Move month to string to file
This commit is contained in:
parent
abfed20a96
commit
ca6adf75e1
|
|
@ -0,0 +1,26 @@
|
||||||
|
def month_to_german_string(month):
|
||||||
|
if month == 1:
|
||||||
|
month = 'Januar'
|
||||||
|
elif month == 2:
|
||||||
|
month = 'Februar'
|
||||||
|
elif month == 3:
|
||||||
|
month = 'März'
|
||||||
|
elif month == 4:
|
||||||
|
month = 'April'
|
||||||
|
elif month == 5:
|
||||||
|
month = 'Mai'
|
||||||
|
elif month == 6:
|
||||||
|
month = 'Juni'
|
||||||
|
elif month == 7:
|
||||||
|
month = 'Juli'
|
||||||
|
elif month == 8:
|
||||||
|
month = 'August'
|
||||||
|
elif month == 9:
|
||||||
|
month = 'September'
|
||||||
|
elif month == 10:
|
||||||
|
month = 'Oktober'
|
||||||
|
elif month == 11:
|
||||||
|
month = 'November'
|
||||||
|
elif month == 12:
|
||||||
|
month = 'Dezember'
|
||||||
|
return month
|
||||||
|
|
@ -5,6 +5,7 @@ from graphene import relay
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
from graphene_django.filter import DjangoFilterConnectionField
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
|
||||||
|
from newsteaser.date_helper import month_to_german_string
|
||||||
from newsteaser.models import NewsTeaser
|
from newsteaser.models import NewsTeaser
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -16,40 +17,13 @@ class NewsTeaserNode(DjangoObjectType):
|
||||||
filter_fields = ['date',]
|
filter_fields = ['date',]
|
||||||
interfaces = (relay.Node,)
|
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):
|
def resolve_display_date(self, *args, **kwargs):
|
||||||
# play it safe, locale might not be installed in platform
|
# play it safe, locale might not be installed in platform
|
||||||
try:
|
try:
|
||||||
locale.setlocale(locale.LC_TIME, "de_DE")
|
locale.setlocale(locale.LC_TIME, "de_DE")
|
||||||
return self.date.strftime("%-d. %B %Y")
|
return self.date.strftime("%-d. %B %Y")
|
||||||
except:
|
except:
|
||||||
month = self._month_to_german_string(self.date)
|
month = month_to_german_string(self.date.month)
|
||||||
return f'{self.date.day}. {month}. {self.date.year}'
|
return f'{self.date.day}. {month}. {self.date.year}'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue