fix patch news BO
This commit is contained in:
parent
0da58133fc
commit
8abb582e49
|
|
@ -210,6 +210,7 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
||||||
"""Overridden validate method."""
|
"""Overridden validate method."""
|
||||||
if 'descriptions' in attrs:
|
if 'descriptions' in attrs:
|
||||||
descriptions = attrs.pop('descriptions')
|
descriptions = attrs.pop('descriptions')
|
||||||
|
locales = list(map(lambda x: x['locale'], descriptions))
|
||||||
status_to_bool = {
|
status_to_bool = {
|
||||||
'active': True,
|
'active': True,
|
||||||
'inactive': False,
|
'inactive': False,
|
||||||
|
|
@ -220,6 +221,12 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
||||||
obj['locale']: status_to_bool[obj['status']] for obj in descriptions
|
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}
|
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
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user