From b720c2e4318a2a70d71e8ad19613b075c4be321d Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 24 Mar 2022 11:49:34 +1100 Subject: [PATCH 1/4] Check for empty string when rendering dates --- InvenTree/part/templatetags/inventree_extras.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 3deab1ecd1..dd20d49e39 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -57,6 +57,13 @@ def render_date(context, date_object): return None if type(date_object) == str: + + date_object = date_object.strip() + + # Check for empty string + if len(date_object) == 0: + return None + # If a string is passed, first convert it to a datetime date_object = date.fromisoformat(date_object) From 31b71fe29fd9f0179eb733ec9f8bac3a5c60d080 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 24 Mar 2022 11:56:39 +1100 Subject: [PATCH 2/4] Catch error when incorrect date format string is passed --- InvenTree/part/templatetags/inventree_extras.py | 10 +++++++++- InvenTree/plugin/events.py | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index dd20d49e39..dc93e00efa 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -8,6 +8,7 @@ over and above the built-in Django tags. from datetime import date, datetime import os import sys +import logging from django.utils.html import format_html @@ -31,6 +32,9 @@ from plugin.models import PluginSetting register = template.Library() +logger = logging.getLogger('inventree') + + @register.simple_tag() def define(value, *args, **kwargs): """ @@ -65,7 +69,11 @@ def render_date(context, date_object): return None # If a string is passed, first convert it to a datetime - date_object = date.fromisoformat(date_object) + try: + date_object = date.fromisoformat(date_object) + except ValueError: + logger.warning(f"Tried to convert invalid date string: {date_object}") + return None # We may have already pre-cached the date format by calling this already! user_date_format = context.get('user_date_format', None) diff --git a/InvenTree/plugin/events.py b/InvenTree/plugin/events.py index 049c8626c5..b75f5f92bb 100644 --- a/InvenTree/plugin/events.py +++ b/InvenTree/plugin/events.py @@ -59,15 +59,24 @@ def register_event(event, *args, **kwargs): logger.debug(f"Registering triggered event: '{event}'") + print("register_event") + # Determine if there are any plugins which are interested in responding if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_EVENTS'): + print("checking plugins") + with transaction.atomic(): for slug, plugin in registry.plugins.items(): + print("slug:", slug) + print("plugin:", plugin) + if plugin.mixin_enabled('events'): + print("events are enabled for this plugin!") + config = plugin.plugin_config() if config and config.active: From 66487817dd06c72eb73fc4c5848cef6550ed1136 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 24 Mar 2022 12:03:16 +1100 Subject: [PATCH 3/4] Remove debug messages --- InvenTree/plugin/events.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/InvenTree/plugin/events.py b/InvenTree/plugin/events.py index b75f5f92bb..f0e2458810 100644 --- a/InvenTree/plugin/events.py +++ b/InvenTree/plugin/events.py @@ -70,13 +70,8 @@ def register_event(event, *args, **kwargs): for slug, plugin in registry.plugins.items(): - print("slug:", slug) - print("plugin:", plugin) - if plugin.mixin_enabled('events'): - print("events are enabled for this plugin!") - config = plugin.plugin_config() if config and config.active: From bd0bf4368c4adc9bacc8a637247f13217cd732ee Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 24 Mar 2022 12:08:56 +1100 Subject: [PATCH 4/4] Remove more debug messages --- InvenTree/plugin/events.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/InvenTree/plugin/events.py b/InvenTree/plugin/events.py index f0e2458810..049c8626c5 100644 --- a/InvenTree/plugin/events.py +++ b/InvenTree/plugin/events.py @@ -59,13 +59,9 @@ def register_event(event, *args, **kwargs): logger.debug(f"Registering triggered event: '{event}'") - print("register_event") - # Determine if there are any plugins which are interested in responding if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_EVENTS'): - print("checking plugins") - with transaction.atomic(): for slug, plugin in registry.plugins.items():