From 94b2e9b01c439c0a483104a944fd224ef03f95e9 Mon Sep 17 00:00:00 2001 From: smilerz Date: Mon, 1 Nov 2021 12:43:10 -0500 Subject: [PATCH] minor updates --- cookbook/models.py | 10 +++++----- cookbook/serializer.py | 21 ++------------------- cookbook/templates/base.html | 1 - cookbook/views/api.py | 3 ++- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/cookbook/models.py b/cookbook/models.py index df28efb36..93983d267 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -689,7 +689,7 @@ class Comment(ExportModelOperationsMixin('comment'), models.Model, PermissionMod objects = ScopedManager(space='recipe__space') - @ staticmethod + @staticmethod def get_space_key(): return 'recipe', 'space' @@ -737,7 +737,7 @@ class RecipeBookEntry(ExportModelOperationsMixin('book_entry'), models.Model, Pe objects = ScopedManager(space='book__space') - @ staticmethod + @staticmethod def get_space_key(): return 'book', 'space' @@ -804,7 +804,7 @@ class ShoppingListRecipe(ExportModelOperationsMixin('shopping_list_recipe'), mod objects = ScopedManager(space='recipe__space') - @ staticmethod + @staticmethod def get_space_key(): return 'recipe', 'space' @@ -837,7 +837,7 @@ class ShoppingListEntry(ExportModelOperationsMixin('shopping_list_entry'), model space = models.ForeignKey(Space, on_delete=models.CASCADE) objects = ScopedManager(space='space') - @ staticmethod + @staticmethod def get_space_key(): return 'shoppinglist', 'space' @@ -1010,7 +1010,7 @@ class SearchFields(models.Model, PermissionModelMixin): def __str__(self): return _(self.name) - @ staticmethod + @staticmethod def get_name(self): return _(self.name) diff --git a/cookbook/serializer.py b/cookbook/serializer.py index 27cf02cd7..0da074916 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -78,7 +78,7 @@ class CustomDecimalField(serializers.Field): def to_representation(self, value): if not isinstance(value, Decimal): value = Decimal(value) - return round(value, 3).normalize() + return round(value, 2).normalize() def to_internal_value(self, data): if type(data) == int or type(data) == float: @@ -166,7 +166,7 @@ class UserPreferenceSerializer(serializers.ModelSerializer): class Meta: model = UserPreference fields = ( - 'user', 'theme', 'nav_color', 'default_unit', 'default_page', + 'user', 'theme', 'nav_color', 'default_unit', 'default_page', 'use_kj', 'search_style', 'show_recent', 'plan_share', 'ingredient_decimals', 'comments', 'shopping_auto_sync', 'mealplan_autoadd_shopping', 'food_ignore_default', 'default_delay', 'mealplan_autoinclude_related', 'mealplan_autoexclude_onhand', 'shopping_share', 'shopping_recent_days' @@ -335,9 +335,6 @@ class SupermarketCategorySerializer(UniqueFieldsMixin, WritableNestedModelSerial class SupermarketCategoryRelationSerializer(WritableNestedModelSerializer): category = SupermarketCategorySerializer() - def get_fields(self, *args, **kwargs): - return super().get_fields(*args, **kwargs) - class Meta: model = SupermarketCategoryRelation fields = ('id', 'category', 'supermarket', 'order') @@ -543,9 +540,6 @@ class RecipeSerializer(RecipeBaseSerializer): validated_data['space'] = self.context['request'].space return super().create(validated_data) - def update(self, instance, validated_data): - return super().update(instance, validated_data) - class RecipeImageSerializer(WritableNestedModelSerializer): class Meta: @@ -675,22 +669,11 @@ class ShoppingListEntrySerializer(WritableNestedModelSerializer): def get_fields(self, *args, **kwargs): fields = super().get_fields(*args, **kwargs) - # try: - # # this serializer is the parent serializer for the API - # api_serializer = self.context['view'].serializer_class - # except Exception: - # # this serializer is probably nested or a foreign key - # api_serializer = None # autosync values are only needed for frequent 'checked' value updating if self.context['request'] and bool(int(self.context['request'].query_params.get('autosync', False))): for f in list(set(fields) - set(['id', 'checked'])): del fields[f] - # extended values are computationally expensive and not needed in normal circumstances - # elif bool(int(self.context['request'].query_params.get('extended', False))) and self.__class__ == api_serializer: - # pass - # else: - # del fields['recipe_mealplan'] return fields def run_validation(self, data): diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index 6dd0943c1..263584e1e 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -342,7 +342,6 @@ {% block script %} - {% endblock script %}