Skip to content

Commit

Permalink
Resolve reoccurrence of issue #78 for admin list display converts (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminvsf authored Jun 14, 2024
1 parent 101c71a commit da63414
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion jalali_date/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from jalali_date import date2jalali, datetime2jalali
from jalali_date.fields import JalaliDateField, SplitJalaliDateTimeField
from jalali_date.utils import normalize_strftime
from jalali_date.widgets import AdminJalaliDateWidget, AdminSplitJalaliDateTime

overrides = {
Expand Down Expand Up @@ -62,6 +63,7 @@ def func(obj):
if not g_date:
return ''
else:
strftime = normalize_strftime(strftime)
return convert_func(g_date).strftime(strftime)

func.short_description = field.verbose_name
Expand Down Expand Up @@ -89,4 +91,3 @@ def __init__(self, *args, **kwargs):
formfield_overrides.update(self.formfield_overrides)
self.formfield_overrides = formfield_overrides
super(TabularInlineJalaliMixin, self).__init__(*args, **kwargs)

11 changes: 1 addition & 10 deletions jalali_date/templatetags/jalali_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings

from jalali_date import date2jalali, datetime2jalali
from jalali_date.utils import normalize_strftime

django_version = get_version()
if StrictVersion(django_version) >= StrictVersion('1.9'):
Expand All @@ -27,16 +28,6 @@ def contents(self):
return self.value


def normalize_strftime(strftime):
"""
Normalize strftime values to make sure their usable for datetime libraries.
"""
if not isinstance(strftime, str):
# Convert non-str values to str to support stuff like "lazy_translations".
strftime = str(strftime)
return strftime


@register.filter
def to_jalali(g_date, strftime=None):
if g_date is None:
Expand Down
8 changes: 8 additions & 0 deletions jalali_date/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def normalize_strftime(strftime):
"""
Normalize strftime values to make sure their usable for datetime libraries.
"""
if not isinstance(strftime, str):
# Convert non-str values to str to support stuff like "lazy_translations".
strftime = str(strftime)
return strftime

0 comments on commit da63414

Please sign in to comment.