finally fix issue w/ news patch
This commit is contained in:
parent
d9ff3227dc
commit
8b014a7923
|
|
@ -155,6 +155,9 @@ class NewsDetailSerializer(NewsBaseSerializer):
|
|||
'gallery',
|
||||
)
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
|
||||
class NewsDetailWebSerializer(NewsDetailSerializer):
|
||||
"""News detail serializer for web users.."""
|
||||
|
|
@ -260,7 +263,7 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
|||
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):
|
||||
if locale not in attrs[key]:
|
||||
attrs[key][locale] = getattr(instance, key).get(locale)
|
||||
|
||||
return attrs
|
||||
|
|
@ -381,27 +384,10 @@ class NewsBackOfficeDetailSerializer(NewsBackOfficeBaseSerializer,
|
|||
|
||||
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 super().validate(attrs)
|
||||
|
||||
return attrs
|
||||
def update(self, instance, validated_data):
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
|
||||
class NewsBackOfficeGallerySerializer(serializers.ModelSerializer):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user