mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #2767 from SchrodingersGat/date-render-fix
Check for empty string when rendering dates
This commit is contained in:
commit
170c4dfd4c
@ -8,6 +8,7 @@ over and above the built-in Django tags.
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
|
|
||||||
@ -31,6 +32,9 @@ from plugin.models import PluginSetting
|
|||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger('inventree')
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def define(value, *args, **kwargs):
|
def define(value, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -57,8 +61,19 @@ def render_date(context, date_object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if type(date_object) == str:
|
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
|
# If a string is passed, first convert it to a datetime
|
||||||
|
try:
|
||||||
date_object = date.fromisoformat(date_object)
|
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!
|
# We may have already pre-cached the date format by calling this already!
|
||||||
user_date_format = context.get('user_date_format', None)
|
user_date_format = context.get('user_date_format', None)
|
||||||
|
Loading…
Reference in New Issue
Block a user