From 4c7088abbcc237827eb3d061c66406dfbfdeaeab Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Tue, 28 Jan 2020 14:58:41 +0300 Subject: [PATCH] fix news again... --- apps/news/serializers.py | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/apps/news/serializers.py b/apps/news/serializers.py index 2ddae3c1..a6b2d72d 100644 --- a/apps/news/serializers.py +++ b/apps/news/serializers.py @@ -379,29 +379,29 @@ class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer, 'duplicates', ) - def validate(self, attrs): - """Overridden validate method.""" - if 'descriptions' in attrs: - descriptions = attrs.pop('descriptions') - locales = list(map(lambda x: x['locale'], descriptions)) - status_to_bool = { - 'active': True, - 'inactive': False, - } - attrs['slugs'] = {obj['locale']: obj['slug'] for obj in descriptions if 'slug' in obj} - attrs['title'] = {obj['locale']: obj['title'] for obj in descriptions if 'title' in obj} - attrs['locale_to_description_is_active'] = { - obj['locale']: status_to_bool[obj['status']] for obj in descriptions - } - attrs['description'] = {obj['locale']: obj['text'] for obj in descriptions if 'text' in obj} - if self.context['request'].method == 'PATCH': - instance = models.News.objects.get(pk=self.context['request'].data['id']) - for key in ['slugs', 'title', 'locale_to_description_is_active', 'description']: - for locale in locales: - if not attrs[key].get(locale): - attrs[key][locale] = getattr(instance, key).get(locale) + def validate(self, attrs): + """Overridden validate method.""" + if 'descriptions' in attrs: + descriptions = attrs.pop('descriptions') + locales = list(map(lambda x: x['locale'], descriptions)) + status_to_bool = { + 'active': True, + 'inactive': False, + } + attrs['slugs'] = {obj['locale']: obj['slug'] for obj in descriptions if 'slug' in obj} + attrs['title'] = {obj['locale']: obj['title'] for obj in descriptions if 'title' in obj} + attrs['locale_to_description_is_active'] = { + obj['locale']: status_to_bool[obj['status']] for obj in descriptions + } + attrs['description'] = {obj['locale']: obj['text'] for obj in descriptions if 'text' in obj} + if self.context['request'].method == 'PATCH': + instance = models.News.objects.get(pk=self.context['request'].data['id']) + for key in ['slugs', 'title', 'locale_to_description_is_active', 'description']: + for locale in locales: + if not attrs[key].get(locale): + attrs[key][locale] = getattr(instance, key).get(locale) - return attrs + return attrs class NewsBackOfficeGallerySerializer(serializers.ModelSerializer):