mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-06 14:48:02 -05:00
@@ -2,22 +2,21 @@ import random
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db.models import Avg, QuerySet, Sum
|
from django.db.models import Avg, QuerySet, Sum
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from drf_writable_nested import (UniqueFieldsMixin,
|
from drf_writable_nested import UniqueFieldsMixin, WritableNestedModelSerializer
|
||||||
WritableNestedModelSerializer)
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.exceptions import ValidationError, NotFound
|
from rest_framework.exceptions import NotFound, ValidationError
|
||||||
|
|
||||||
from cookbook.models import (Comment, CookLog, Food, Ingredient, Keyword,
|
from cookbook.models import (Automation, BookmarkletImport, Comment, CookLog, Food, ImportLog,
|
||||||
MealPlan, MealType, NutritionInformation, Recipe,
|
Ingredient, Keyword, MealPlan, MealType, NutritionInformation, Recipe,
|
||||||
RecipeBook, RecipeBookEntry, RecipeImport,
|
RecipeBook, RecipeBookEntry, RecipeImport, ShareLink, ShoppingList,
|
||||||
ShareLink, ShoppingList, ShoppingListEntry,
|
ShoppingListEntry, ShoppingListRecipe, Step, Storage, Supermarket,
|
||||||
ShoppingListRecipe, Step, Storage, Sync, SyncLog,
|
SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog, Unit,
|
||||||
Unit, UserPreference, ViewLog, SupermarketCategory, Supermarket,
|
UserFile, UserPreference, ViewLog)
|
||||||
SupermarketCategoryRelation, ImportLog, BookmarkletImport, UserFile, Automation)
|
|
||||||
from cookbook.templatetags.custom_tags import markdown
|
from cookbook.templatetags.custom_tags import markdown
|
||||||
|
|
||||||
|
|
||||||
@@ -34,12 +33,14 @@ class ExtendedRecipeMixin(serializers.ModelSerializer):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
api_serializer = None
|
api_serializer = None
|
||||||
# extended values are computationally expensive and not needed in normal circumstances
|
# extended values are computationally expensive and not needed in normal circumstances
|
||||||
if self.context.get('request', False) and bool(int(self.context['request'].query_params.get('extended', False))) and self.__class__ == api_serializer:
|
try:
|
||||||
return fields
|
if bool(int(self.context['request'].query_params.get('extended', False))) and self.__class__ == api_serializer:
|
||||||
else:
|
return fields
|
||||||
del fields['image']
|
except AttributeError:
|
||||||
del fields['numrecipe']
|
pass
|
||||||
return fields
|
del fields['image']
|
||||||
|
del fields['numrecipe']
|
||||||
|
return fields
|
||||||
|
|
||||||
def get_image(self, obj):
|
def get_image(self, obj):
|
||||||
# TODO add caching
|
# TODO add caching
|
||||||
@@ -158,7 +159,7 @@ class UserFileSerializer(serializers.ModelSerializer):
|
|||||||
current_file_size_mb = 0
|
current_file_size_mb = 0
|
||||||
|
|
||||||
if ((validated_data['file'].size / 1000 / 1000 + current_file_size_mb - 5)
|
if ((validated_data['file'].size / 1000 / 1000 + current_file_size_mb - 5)
|
||||||
> self.context['request'].space.max_file_storage_mb != 0):
|
> self.context['request'].space.max_file_storage_mb != 0):
|
||||||
raise ValidationError(_('You have reached your file upload limit.'))
|
raise ValidationError(_('You have reached your file upload limit.'))
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
|||||||
Reference in New Issue
Block a user