From ca6adf75e18b76afec53461bdd9e16ef8cf9f09f Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Thu, 28 May 2020 09:58:19 +0200 Subject: [PATCH] Move month to string to file --- server/newsteaser/date_helper.py | 26 ++++++++++++++++++++++++++ server/newsteaser/schema_public.py | 30 ++---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 server/newsteaser/date_helper.py diff --git a/server/newsteaser/date_helper.py b/server/newsteaser/date_helper.py new file mode 100644 index 00000000..62f199a8 --- /dev/null +++ b/server/newsteaser/date_helper.py @@ -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 diff --git a/server/newsteaser/schema_public.py b/server/newsteaser/schema_public.py index 690631d9..afbac9ae 100644 --- a/server/newsteaser/schema_public.py +++ b/server/newsteaser/schema_public.py @@ -5,6 +5,7 @@ from graphene import relay from graphene_django import DjangoObjectType from graphene_django.filter import DjangoFilterConnectionField +from newsteaser.date_helper import month_to_german_string from newsteaser.models import NewsTeaser @@ -16,40 +17,13 @@ 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): # 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) + month = month_to_german_string(self.date.month) return f'{self.date.day}. {month}. {self.date.year}'