mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-05 06:08:46 -05:00
started migrating file editor page to generic model list
This commit is contained in:
@@ -146,21 +146,20 @@ class UserPreferenceSerializer(serializers.ModelSerializer):
|
||||
class UserFileSerializer(serializers.ModelSerializer):
|
||||
|
||||
def check_file_limit(self, validated_data):
|
||||
if self.context['request'].space.max_file_storage_mb == -1:
|
||||
raise ValidationError(_('File uploads are not enabled for this Space.'))
|
||||
if 'file' in validated_data:
|
||||
if self.context['request'].space.max_file_storage_mb == -1:
|
||||
raise ValidationError(_('File uploads are not enabled for this Space.'))
|
||||
|
||||
try:
|
||||
current_file_size_mb = \
|
||||
UserFile.objects.filter(space=self.context['request'].space).aggregate(Sum('file_size_kb'))[
|
||||
'file_size_kb__sum'] / 1000
|
||||
except TypeError:
|
||||
current_file_size_mb = 0
|
||||
try:
|
||||
current_file_size_mb = \
|
||||
UserFile.objects.filter(space=self.context['request'].space).aggregate(Sum('file_size_kb'))[
|
||||
'file_size_kb__sum'] / 1000
|
||||
except TypeError:
|
||||
current_file_size_mb = 0
|
||||
|
||||
if (
|
||||
(validated_data['file'].size / 1000 / 1000 + current_file_size_mb - 5)
|
||||
> self.context['request'].space.max_file_storage_mb != 0
|
||||
):
|
||||
raise ValidationError(_('You have reached your file upload limit.'))
|
||||
if ((validated_data['file'].size / 1000 / 1000 + current_file_size_mb - 5)
|
||||
> self.context['request'].space.max_file_storage_mb != 0):
|
||||
raise ValidationError(_('You have reached your file upload limit.'))
|
||||
|
||||
def create(self, validated_data):
|
||||
self.check_file_limit(validated_data)
|
||||
|
||||
@@ -10,7 +10,7 @@ from cookbook.helper import dal
|
||||
|
||||
from .models import (Comment, Food, InviteLink, Keyword, MealPlan, Recipe,
|
||||
RecipeBook, RecipeBookEntry, RecipeImport, ShoppingList,
|
||||
Storage, Supermarket, SupermarketCategory, Sync, SyncLog, Unit, get_model_name, Automation)
|
||||
Storage, Supermarket, SupermarketCategory, Sync, SyncLog, Unit, get_model_name, Automation, UserFile)
|
||||
from .views import api, data, delete, edit, import_export, lists, new, views, telegram
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
@@ -179,7 +179,7 @@ for m in generic_models:
|
||||
)
|
||||
)
|
||||
|
||||
vue_models = [Food, Keyword, Unit, Supermarket, SupermarketCategory, Automation]
|
||||
vue_models = [Food, Keyword, Unit, Supermarket, SupermarketCategory, Automation, UserFile]
|
||||
for m in vue_models:
|
||||
py_name = get_model_name(m)
|
||||
url_name = py_name.replace('_', '-')
|
||||
|
||||
@@ -200,6 +200,20 @@ def automation(request):
|
||||
)
|
||||
|
||||
|
||||
@group_required('user')
|
||||
def user_file(request):
|
||||
return render(
|
||||
request,
|
||||
'generic/model_template.html',
|
||||
{
|
||||
"title": _("Files"),
|
||||
"config": {
|
||||
'model': "USERFILE", # *REQUIRED* name of the model in models.js
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@group_required('user')
|
||||
def shopping_list_new(request):
|
||||
# recipe-param is the name of the parameters used when filtering recipes by this attribute
|
||||
@@ -213,4 +227,4 @@ def shopping_list_new(request):
|
||||
'model': "SHOPPING_LIST", # *REQUIRED* name of the model in models.js
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user