Skip to content

Commit

Permalink
Fix error to return none to empty fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ericosta-dev committed Sep 13, 2024
1 parent 3472722 commit bc2a09a
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions connect/api/v2/template_projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ def _get_language(self):

def get_description(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).description
if obj.translations.filter(language=lang).exists():
translation = obj.translations.get(language=lang)
return translation.description
return None

def get_name(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).name
if obj.translations.filter(language=lang).exists():
translation = obj.translations.get(language=lang)
return translation.name
return None


class TemplateTypeSerializer(ModelSerializer):
Expand Down Expand Up @@ -65,28 +71,45 @@ def _get_language(self):

def get_name(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).name
if obj.translations.filter(language=lang).exists():
translation = obj.translations.get(language=lang)
return translation.name
return None

def get_description(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).description
if obj.translations.filter(language=lang).exists():
translation = obj.translations.get(language=lang)
return translation.description
return None

def get_setup(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).setup
if obj.translations.filter(language=lang).exists():
translation = obj.translations.get(language=lang)
return translation.setup
return None

def get_photo(self, obj):
lang = self._get_language()
translation = obj.translations.get(language=lang)
return translation.photo.url if translation.photo else None
if obj.translations.filter(language=lang).exists():
translation = obj.translations.get(language=lang)
return translation.photo.url
return None

def get_photo_description(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).photo_description
if obj.translations.filter(language=lang).exists():
translation = obj.translations.get(language=lang)
return translation.photo_description
return None

def get_category(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).category
if obj.translations.filter(language=lang).exists():
translation = obj.translations.get(language=lang)
return translation.category
return None

def get_features(self, obj):
return TemplateFeatureSerializer(
Expand All @@ -108,11 +131,13 @@ def _get_language(self):

def get_description(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).description
translation = obj.translations.get(language=lang)
return translation.description if translation else None

def get_name(self, obj):
lang = self._get_language()
return obj.translations.get(language=lang).name
translation = obj.translations.get(language=lang)
return translation.name if translation else None


class TemplateSuggestionSerializer(ModelSerializer):
Expand Down

0 comments on commit bc2a09a

Please sign in to comment.