From 961b3f07b5c79afa6b412e5b5722bc072605f6ba Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sun, 17 Jan 2021 14:37:34 +0100 Subject: [PATCH] added demo setting --- cookbook/templates/forms/edit_internal_recipe.html | 2 +- cookbook/views/api.py | 13 ++++++++++++- recipes/settings.py | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index 66b23038e..63c8fb810 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -585,7 +585,7 @@ }).catch((err) => { console.log(err) - this.makeToast(gettext('Error'), gettext('There was an error updating the recipe!') + err.body.image, 'danger') + this.makeToast(gettext('Error'), gettext('There was an error updating the recipe!') + err.bodyText, 'danger') }) let reader = new FileReader(); diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 80dd1eb9a..b2b64e52c 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -9,6 +9,7 @@ from annoying.functions import get_object_or_None from django.contrib import messages from django.contrib.auth.models import User from django.core import management +from django.core.exceptions import FieldError from django.core.files import File from django.db.models import Q from django.http import FileResponse, HttpResponse, JsonResponse @@ -19,7 +20,7 @@ from django.utils.translation import gettext as _ from icalendar import Calendar, Event from PIL import Image from rest_framework import decorators, permissions, viewsets -from rest_framework.exceptions import APIException +from rest_framework.exceptions import APIException, PermissionDenied from rest_framework.mixins import (ListModelMixin, RetrieveModelMixin, UpdateModelMixin, CreateModelMixin) from rest_framework.parsers import MultiPartParser @@ -50,6 +51,7 @@ from cookbook.serializer import (FoodSerializer, IngredientSerializer, SyncSerializer, UnitSerializer, UserNameSerializer, UserPreferenceSerializer, ViewLogSerializer, CookLogSerializer, RecipeBookEntrySerializer, RecipeOverviewSerializer) +from recipes.settings import DEMO class UserNameViewSet(viewsets.ReadOnlyModelViewSet): @@ -284,6 +286,9 @@ class RecipeViewSet(viewsets.ModelViewSet, StandardFilterMixin): obj, data=request.data, partial=True ) + if DEMO: + raise PermissionDenied(detail='Not available in demo', code=None) + if serializer.is_valid(): serializer.save() img = Image.open(obj.image) @@ -397,6 +402,12 @@ def get_recipe_file(request, recipe_id): @group_required('user') def sync_all(request): + if DEMO or True: + messages.add_message( + request, messages.ERROR, _('This feature is not available in the demo version!') + ) + return redirect('index') + monitors = Sync.objects.filter(active=True) error = False diff --git a/recipes/settings.py b/recipes/settings.py index da6b92b01..a2e177528 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -23,6 +23,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = os.getenv('SECRET_KEY') if os.getenv('SECRET_KEY') else 'INSECURE_STANDARD_KEY_SET_IN_ENV' DEBUG = bool(int(os.getenv('DEBUG', True))) +DEMO = bool(int(os.getenv('DEMO', False))) INTERNAL_IPS = os.getenv('INTERNAL_IPS').split(',') if os.getenv('INTERNAL_IPS') else ['127.0.0.1']