actually apply limits everywhere
This commit is contained in:
@ -20,12 +20,20 @@ from cookbook.forms import BatchEditForm, SyncForm
|
|||||||
from cookbook.helper.permission_helper import group_required, has_group_permission
|
from cookbook.helper.permission_helper import group_required, has_group_permission
|
||||||
from cookbook.helper.recipe_url_import import parse_cooktime
|
from cookbook.helper.recipe_url_import import parse_cooktime
|
||||||
from cookbook.models import (Comment, Food, Ingredient, Keyword, Recipe,
|
from cookbook.models import (Comment, Food, Ingredient, Keyword, Recipe,
|
||||||
RecipeImport, Step, Sync, Unit)
|
RecipeImport, Step, Sync, Unit, UserPreference)
|
||||||
from cookbook.tables import SyncTable
|
from cookbook.tables import SyncTable
|
||||||
|
|
||||||
|
|
||||||
@group_required('user')
|
@group_required('user')
|
||||||
def sync(request):
|
def sync(request):
|
||||||
|
if request.space.max_recipes != 0 and Recipe.objects.filter(space=request.space).count() >= request.space.max_recipes: # TODO move to central helper function
|
||||||
|
messages.add_message(request, messages.WARNING, _('You have reached the maximum number of recipes for your space.'))
|
||||||
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
|
if request.space.max_users != 0 and UserPreference.objects.filter(space=request.space).count() > request.space.max_users:
|
||||||
|
messages.add_message(request, messages.WARNING, _('You have more users than allowed in your space.'))
|
||||||
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if not has_group_permission(request.user, ['admin']):
|
if not has_group_permission(request.user, ['admin']):
|
||||||
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
|
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
|
||||||
@ -109,6 +117,14 @@ def batch_edit(request):
|
|||||||
@group_required('user')
|
@group_required('user')
|
||||||
@atomic
|
@atomic
|
||||||
def import_url(request):
|
def import_url(request):
|
||||||
|
if request.space.max_recipes != 0 and Recipe.objects.filter(space=request.space).count() >= request.space.max_recipes: # TODO move to central helper function
|
||||||
|
messages.add_message(request, messages.WARNING, _('You have reached the maximum number of recipes for your space.'))
|
||||||
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
|
if request.space.max_users != 0 and UserPreference.objects.filter(space=request.space).count() > request.space.max_users:
|
||||||
|
messages.add_message(request, messages.WARNING, _('You have more users than allowed in your space.'))
|
||||||
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
data = json.loads(request.body)
|
data = json.loads(request.body)
|
||||||
data['cookTime'] = parse_cooktime(data.get('cookTime', ''))
|
data['cookTime'] = parse_cooktime(data.get('cookTime', ''))
|
||||||
@ -200,6 +216,7 @@ def import_url(request):
|
|||||||
|
|
||||||
return render(request, 'url_import.html', context)
|
return render(request, 'url_import.html', context)
|
||||||
|
|
||||||
|
|
||||||
class Object(object):
|
class Object(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ def convert_recipe(request, pk):
|
|||||||
|
|
||||||
@group_required('user')
|
@group_required('user')
|
||||||
def internal_recipe_update(request, pk):
|
def internal_recipe_update(request, pk):
|
||||||
if request.space.max_recipes != 0 and Recipe.objects.filter(space=request.space).count() > request.space.max_recipes:
|
if request.space.max_recipes != 0 and Recipe.objects.filter(space=request.space).count() > request.space.max_recipes: # TODO move to central helper function
|
||||||
messages.add_message(request, messages.WARNING, _('You have reached the maximum number of recipes for your space.'))
|
messages.add_message(request, messages.WARNING, _('You have reached the maximum number of recipes for your space.'))
|
||||||
return HttpResponseRedirect(reverse('view_recipe', args=[pk]))
|
return HttpResponseRedirect(reverse('view_recipe', args=[pk]))
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ from cookbook.integration.recettetek import RecetteTek
|
|||||||
from cookbook.integration.recipesage import RecipeSage
|
from cookbook.integration.recipesage import RecipeSage
|
||||||
from cookbook.integration.rezkonv import RezKonv
|
from cookbook.integration.rezkonv import RezKonv
|
||||||
from cookbook.integration.safron import Safron
|
from cookbook.integration.safron import Safron
|
||||||
from cookbook.models import Recipe, ImportLog
|
from cookbook.models import Recipe, ImportLog, UserPreference
|
||||||
|
|
||||||
|
|
||||||
def get_integration(request, export_type):
|
def get_integration(request, export_type):
|
||||||
@ -57,6 +57,14 @@ def get_integration(request, export_type):
|
|||||||
|
|
||||||
@group_required('user')
|
@group_required('user')
|
||||||
def import_recipe(request):
|
def import_recipe(request):
|
||||||
|
if request.space.max_recipes != 0 and Recipe.objects.filter(space=request.space).count() >= request.space.max_recipes: # TODO move to central helper function
|
||||||
|
messages.add_message(request, messages.WARNING, _('You have reached the maximum number of recipes for your space.'))
|
||||||
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
|
if request.space.max_users != 0 and UserPreference.objects.filter(space=request.space).count() > request.space.max_users:
|
||||||
|
messages.add_message(request, messages.WARNING, _('You have more users than allowed in your space.'))
|
||||||
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = ImportForm(request.POST, request.FILES)
|
form = ImportForm(request.POST, request.FILES)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
@ -28,7 +28,7 @@ class RecipeCreate(GroupRequiredMixin, CreateView):
|
|||||||
fields = ('name',)
|
fields = ('name',)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
if self.request.space.max_recipes != 0 and Recipe.objects.filter(space=self.request.space).count() >= self.request.space.max_recipes:
|
if self.request.space.max_recipes != 0 and Recipe.objects.filter(space=self.request.space).count() >= self.request.space.max_recipes: # TODO move to central helper function
|
||||||
messages.add_message(self.request, messages.WARNING, _('You have reached the maximum number of recipes for your space.'))
|
messages.add_message(self.request, messages.WARNING, _('You have reached the maximum number of recipes for your space.'))
|
||||||
return HttpResponseRedirect(reverse('index'))
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user