From 8abb582e4960c30009bdb0a990775b0b5605f50a Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Thu, 26 Dec 2019 19:23:28 +0300 Subject: [PATCH] fix patch news BO --- apps/news/serializers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/news/serializers.py b/apps/news/serializers.py index 9bff32af..2cf03e29 100644 --- a/apps/news/serializers.py +++ b/apps/news/serializers.py @@ -210,6 +210,7 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer): """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, @@ -220,6 +221,12 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer): 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 def create(self, validated_data):