minor updates
This commit is contained in:
parent
de7d2e27d9
commit
94b2e9b01c
@ -689,7 +689,7 @@ class Comment(ExportModelOperationsMixin('comment'), models.Model, PermissionMod
|
|||||||
|
|
||||||
objects = ScopedManager(space='recipe__space')
|
objects = ScopedManager(space='recipe__space')
|
||||||
|
|
||||||
@ staticmethod
|
@staticmethod
|
||||||
def get_space_key():
|
def get_space_key():
|
||||||
return 'recipe', 'space'
|
return 'recipe', 'space'
|
||||||
|
|
||||||
@ -737,7 +737,7 @@ class RecipeBookEntry(ExportModelOperationsMixin('book_entry'), models.Model, Pe
|
|||||||
|
|
||||||
objects = ScopedManager(space='book__space')
|
objects = ScopedManager(space='book__space')
|
||||||
|
|
||||||
@ staticmethod
|
@staticmethod
|
||||||
def get_space_key():
|
def get_space_key():
|
||||||
return 'book', 'space'
|
return 'book', 'space'
|
||||||
|
|
||||||
@ -804,7 +804,7 @@ class ShoppingListRecipe(ExportModelOperationsMixin('shopping_list_recipe'), mod
|
|||||||
|
|
||||||
objects = ScopedManager(space='recipe__space')
|
objects = ScopedManager(space='recipe__space')
|
||||||
|
|
||||||
@ staticmethod
|
@staticmethod
|
||||||
def get_space_key():
|
def get_space_key():
|
||||||
return 'recipe', 'space'
|
return 'recipe', 'space'
|
||||||
|
|
||||||
@ -837,7 +837,7 @@ class ShoppingListEntry(ExportModelOperationsMixin('shopping_list_entry'), model
|
|||||||
space = models.ForeignKey(Space, on_delete=models.CASCADE)
|
space = models.ForeignKey(Space, on_delete=models.CASCADE)
|
||||||
objects = ScopedManager(space='space')
|
objects = ScopedManager(space='space')
|
||||||
|
|
||||||
@ staticmethod
|
@staticmethod
|
||||||
def get_space_key():
|
def get_space_key():
|
||||||
return 'shoppinglist', 'space'
|
return 'shoppinglist', 'space'
|
||||||
|
|
||||||
@ -1010,7 +1010,7 @@ class SearchFields(models.Model, PermissionModelMixin):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return _(self.name)
|
return _(self.name)
|
||||||
|
|
||||||
@ staticmethod
|
@staticmethod
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return _(self.name)
|
return _(self.name)
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ class CustomDecimalField(serializers.Field):
|
|||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
if not isinstance(value, Decimal):
|
if not isinstance(value, Decimal):
|
||||||
value = Decimal(value)
|
value = Decimal(value)
|
||||||
return round(value, 3).normalize()
|
return round(value, 2).normalize()
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
if type(data) == int or type(data) == float:
|
if type(data) == int or type(data) == float:
|
||||||
@ -166,7 +166,7 @@ class UserPreferenceSerializer(serializers.ModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = UserPreference
|
model = UserPreference
|
||||||
fields = (
|
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',
|
'search_style', 'show_recent', 'plan_share', 'ingredient_decimals',
|
||||||
'comments', 'shopping_auto_sync', 'mealplan_autoadd_shopping', 'food_ignore_default', 'default_delay',
|
'comments', 'shopping_auto_sync', 'mealplan_autoadd_shopping', 'food_ignore_default', 'default_delay',
|
||||||
'mealplan_autoinclude_related', 'mealplan_autoexclude_onhand', 'shopping_share', 'shopping_recent_days'
|
'mealplan_autoinclude_related', 'mealplan_autoexclude_onhand', 'shopping_share', 'shopping_recent_days'
|
||||||
@ -335,9 +335,6 @@ class SupermarketCategorySerializer(UniqueFieldsMixin, WritableNestedModelSerial
|
|||||||
class SupermarketCategoryRelationSerializer(WritableNestedModelSerializer):
|
class SupermarketCategoryRelationSerializer(WritableNestedModelSerializer):
|
||||||
category = SupermarketCategorySerializer()
|
category = SupermarketCategorySerializer()
|
||||||
|
|
||||||
def get_fields(self, *args, **kwargs):
|
|
||||||
return super().get_fields(*args, **kwargs)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SupermarketCategoryRelation
|
model = SupermarketCategoryRelation
|
||||||
fields = ('id', 'category', 'supermarket', 'order')
|
fields = ('id', 'category', 'supermarket', 'order')
|
||||||
@ -543,9 +540,6 @@ class RecipeSerializer(RecipeBaseSerializer):
|
|||||||
validated_data['space'] = self.context['request'].space
|
validated_data['space'] = self.context['request'].space
|
||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
|
||||||
return super().update(instance, validated_data)
|
|
||||||
|
|
||||||
|
|
||||||
class RecipeImageSerializer(WritableNestedModelSerializer):
|
class RecipeImageSerializer(WritableNestedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -675,22 +669,11 @@ class ShoppingListEntrySerializer(WritableNestedModelSerializer):
|
|||||||
|
|
||||||
def get_fields(self, *args, **kwargs):
|
def get_fields(self, *args, **kwargs):
|
||||||
fields = super().get_fields(*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
|
# 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))):
|
if self.context['request'] and bool(int(self.context['request'].query_params.get('autosync', False))):
|
||||||
for f in list(set(fields) - set(['id', 'checked'])):
|
for f in list(set(fields) - set(['id', 'checked'])):
|
||||||
del fields[f]
|
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
|
return fields
|
||||||
|
|
||||||
def run_validation(self, data):
|
def run_validation(self, data):
|
||||||
|
@ -342,7 +342,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
|
|
||||||
{% endblock script %}
|
{% endblock script %}
|
||||||
|
|
||||||
<script type="application/javascript">
|
<script type="application/javascript">
|
||||||
|
@ -363,7 +363,8 @@ class SupermarketCategoryViewSet(viewsets.ModelViewSet, StandardFilterMixin):
|
|||||||
permission_classes = [CustomIsUser]
|
permission_classes = [CustomIsUser]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return self.queryset.filter(space=self.request.space)
|
self.queryset = self.queryset.filter(space=self.request.space)
|
||||||
|
return super().get_queryset()
|
||||||
|
|
||||||
|
|
||||||
class SupermarketCategoryRelationViewSet(viewsets.ModelViewSet, StandardFilterMixin):
|
class SupermarketCategoryRelationViewSet(viewsets.ModelViewSet, StandardFilterMixin):
|
||||||
|
Loading…
Reference in New Issue
Block a user