Handle locale fail
This commit is contained in:
parent
1437f465de
commit
abfed20a96
|
|
@ -16,9 +16,41 @@ class NewsTeaserNode(DjangoObjectType):
|
|||
filter_fields = ['date',]
|
||||
interfaces = (relay.Node,)
|
||||
|
||||
def _month_to_german_string(self, date):
|
||||
if date == 1:
|
||||
month = 'Januar'
|
||||
elif date == 2:
|
||||
month = 'Februar'
|
||||
elif date == 3:
|
||||
month = 'März'
|
||||
elif date == 4:
|
||||
month = 'April'
|
||||
elif date == 5:
|
||||
month = 'Mai'
|
||||
elif date == 6:
|
||||
month = 'Juni'
|
||||
elif date == 7:
|
||||
month = 'Juli'
|
||||
elif date == 8:
|
||||
month = 'August'
|
||||
elif date == 9:
|
||||
month = 'September'
|
||||
elif date == 10:
|
||||
month = 'Oktober'
|
||||
elif date == 11:
|
||||
month = 'November'
|
||||
elif date == 12:
|
||||
month = 'Dezember'
|
||||
return month
|
||||
|
||||
def resolve_display_date(self, *args, **kwargs):
|
||||
locale.setlocale(locale.LC_TIME, "de_DE")
|
||||
return self.date.strftime("%d. %B %Y")
|
||||
# play it safe, locale might not be installed in platform
|
||||
try:
|
||||
locale.setlocale(locale.LC_TIME, "de_DE")
|
||||
return self.date.strftime("%-d. %B %Y")
|
||||
except:
|
||||
month = self._month_to_german_string(self.date)
|
||||
return f'{self.date.day}. {month}. {self.date.year}'
|
||||
|
||||
|
||||
class AllNewsTeasersQuery(object):
|
||||
|
|
|
|||
Loading…
Reference in New Issue