diff --git a/cookbook/views/__init__.py b/cookbook/views/__init__.py index fe952811..03fd9fae 100644 --- a/cookbook/views/__init__.py +++ b/cookbook/views/__init__.py @@ -1,7 +1,7 @@ -from cookbook.views.views import * from cookbook.views.api import * from cookbook.views.data import * -from cookbook.views.edit import * -from cookbook.views.new import * -from cookbook.views.lists import * from cookbook.views.delete import * +from cookbook.views.edit import * +from cookbook.views.lists import * +from cookbook.views.new import * +from cookbook.views.views import * diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 45148929..ddc6b0a1 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -4,7 +4,6 @@ import re import uuid import requests -from PIL import Image from annoying.decorators import ajax_request from annoying.functions import get_object_or_None from django.contrib import messages @@ -12,28 +11,45 @@ from django.contrib.auth.models import User from django.core import management from django.core.files import File from django.db.models import Q -from django.http import HttpResponse, FileResponse, JsonResponse +from django.http import FileResponse, HttpResponse, JsonResponse from django.shortcuts import redirect -from django.utils import timezone, dateformat +from django.utils import timezone from django.utils.formats import date_format from django.utils.translation import gettext as _ -from django.views.generic.base import View from icalendar import Calendar, Event -from rest_framework import viewsets, permissions, decorators +from PIL import Image +from rest_framework import decorators, permissions, viewsets from rest_framework.exceptions import APIException -from rest_framework.mixins import RetrieveModelMixin, UpdateModelMixin, ListModelMixin -from rest_framework.parsers import JSONParser, FileUploadParser, MultiPartParser +from rest_framework.mixins import (ListModelMixin, RetrieveModelMixin, + UpdateModelMixin) +from rest_framework.parsers import MultiPartParser from rest_framework.response import Response from rest_framework.viewsets import ViewSetMixin -from cookbook.helper.permission_helper import group_required, CustomIsOwner, CustomIsAdmin, CustomIsUser, CustomIsGuest, CustomIsShare, CustomIsShared +from cookbook.helper.permission_helper import (CustomIsAdmin, CustomIsGuest, + CustomIsOwner, CustomIsShare, + CustomIsShared, CustomIsUser, + group_required) from cookbook.helper.recipe_url_import import get_from_html -from cookbook.models import Recipe, Sync, Storage, CookLog, MealPlan, MealType, ViewLog, UserPreference, RecipeBook, Ingredient, Food, Step, Keyword, Unit, SyncLog, ShoppingListRecipe, ShoppingList, ShoppingListEntry +from cookbook.models import (CookLog, Food, Ingredient, Keyword, MealPlan, + MealType, Recipe, RecipeBook, ShoppingList, + ShoppingListEntry, ShoppingListRecipe, Step, + Storage, Sync, SyncLog, Unit, UserPreference, + ViewLog) from cookbook.provider.dropbox import Dropbox from cookbook.provider.nextcloud import Nextcloud -from cookbook.serializer import MealPlanSerializer, MealTypeSerializer, RecipeSerializer, ViewLogSerializer, UserNameSerializer, UserPreferenceSerializer, RecipeBookSerializer, IngredientSerializer, FoodSerializer, StepSerializer, \ - KeywordSerializer, RecipeImageSerializer, StorageSerializer, SyncSerializer, SyncLogSerializer, UnitSerializer, ShoppingListSerializer, ShoppingListRecipeSerializer, ShoppingListEntrySerializer, ShoppingListEntryCheckedSerializer, \ - ShoppingListAutoSyncSerializer +from cookbook.serializer import (FoodSerializer, IngredientSerializer, + KeywordSerializer, MealPlanSerializer, + MealTypeSerializer, RecipeBookSerializer, + RecipeImageSerializer, RecipeSerializer, + ShoppingListAutoSyncSerializer, + ShoppingListEntrySerializer, + ShoppingListRecipeSerializer, + ShoppingListSerializer, StepSerializer, + StorageSerializer, SyncLogSerializer, + SyncSerializer, UnitSerializer, + UserNameSerializer, UserPreferenceSerializer, + ViewLogSerializer) class UserNameViewSet(viewsets.ReadOnlyModelViewSet): diff --git a/cookbook/views/data.py b/cookbook/views/data.py index 01b78866..ea4edeaa 100644 --- a/cookbook/views/data.py +++ b/cookbook/views/data.py @@ -3,19 +3,20 @@ from datetime import datetime from io import BytesIO import requests -from PIL import Image, UnidentifiedImageError from django.contrib import messages from django.core.files import File from django.db.transaction import atomic -from django.utils.translation import gettext as _ -from django.http import HttpResponseRedirect, HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import redirect, render from django.urls import reverse +from django.utils.translation import gettext as _ from django.utils.translation import ngettext from django_tables2 import RequestConfig +from PIL import Image, UnidentifiedImageError -from cookbook.forms import SyncForm, BatchEditForm -from cookbook.helper.permission_helper import group_required, has_group_permission +from cookbook.forms import BatchEditForm, SyncForm +from cookbook.helper.permission_helper import (group_required, + has_group_permission) from cookbook.models import * from cookbook.tables import SyncTable diff --git a/cookbook/views/delete.py b/cookbook/views/delete.py index 0a4df1cb..5d4241f9 100644 --- a/cookbook/views/delete.py +++ b/cookbook/views/delete.py @@ -1,15 +1,17 @@ from django.contrib import messages -from django.contrib.auth.mixins import LoginRequiredMixin from django.db.models import ProtectedError from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404 -from django.urls import reverse_lazy, reverse +from django.urls import reverse, reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import DeleteView -from cookbook.helper.permission_helper import group_required, GroupRequiredMixin, OwnerRequiredMixin -from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, RecipeBook, \ - RecipeBookEntry, MealPlan, Food, InviteLink +from cookbook.helper.permission_helper import (GroupRequiredMixin, + OwnerRequiredMixin, + group_required) +from cookbook.models import (Comment, InviteLink, Keyword, MealPlan, Recipe, + RecipeBook, RecipeBookEntry, RecipeImport, + Storage, Sync) from cookbook.provider.dropbox import Dropbox from cookbook.provider.nextcloud import Nextcloud diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index ac856b2c..b8c06a08 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -7,12 +7,16 @@ from django.urls import reverse from django.utils.translation import gettext as _ from django.views.generic import UpdateView -from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncForm, CommentForm, \ - MealPlanForm, UnitMergeForm, RecipeBookForm, FoodForm, FoodMergeForm -from cookbook.helper.permission_helper import OwnerRequiredMixin -from cookbook.helper.permission_helper import group_required, GroupRequiredMixin -from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, Ingredient, RecipeBook, \ - MealPlan, Food, MealType +from cookbook.forms import (CommentForm, ExternalRecipeForm, FoodForm, + FoodMergeForm, KeywordForm, MealPlanForm, + RecipeBookForm, StorageForm, SyncForm, + UnitMergeForm) +from cookbook.helper.permission_helper import (GroupRequiredMixin, + OwnerRequiredMixin, + group_required) +from cookbook.models import (Comment, Food, Ingredient, Keyword, MealPlan, + MealType, Recipe, RecipeBook, RecipeImport, + Storage, Sync) from cookbook.provider.dropbox import Dropbox from cookbook.provider.nextcloud import Nextcloud diff --git a/cookbook/views/import_export.py b/cookbook/views/import_export.py index d8ef7186..1312f3e9 100644 --- a/cookbook/views/import_export.py +++ b/cookbook/views/import_export.py @@ -5,7 +5,7 @@ from json import JSONDecodeError from django.contrib import messages from django.core.files.base import ContentFile -from django.http import HttpResponseRedirect, HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render from django.urls import reverse_lazy from django.utils.translation import gettext as _ diff --git a/cookbook/views/lists.py b/cookbook/views/lists.py index 034ddd9d..c455792b 100644 --- a/cookbook/views/lists.py +++ b/cookbook/views/lists.py @@ -1,6 +1,5 @@ from datetime import datetime -from django.contrib.auth.decorators import login_required from django.db.models import Q from django.db.models.functions import Lower from django.shortcuts import render @@ -9,8 +8,11 @@ from django_tables2 import RequestConfig from cookbook.filters import IngredientFilter, ShoppingListFilter from cookbook.helper.permission_helper import group_required -from cookbook.models import Keyword, SyncLog, RecipeImport, Storage, Food, ShoppingList, InviteLink -from cookbook.tables import KeywordTable, ImportLogTable, RecipeImportTable, StorageTable, IngredientTable, ShoppingListTable, InviteLinkTable +from cookbook.models import (Food, InviteLink, Keyword, RecipeImport, + ShoppingList, Storage, SyncLog) +from cookbook.tables import (ImportLogTable, IngredientTable, InviteLinkTable, + KeywordTable, RecipeImportTable, + ShoppingListTable, StorageTable) @group_required('user') diff --git a/cookbook/views/new.py b/cookbook/views/new.py index 464fbe7c..56bdf332 100644 --- a/cookbook/views/new.py +++ b/cookbook/views/new.py @@ -3,15 +3,18 @@ from datetime import datetime from django.contrib import messages from django.http import HttpResponseRedirect -from django.shortcuts import render, redirect, get_object_or_404 -from django.urls import reverse_lazy, reverse +from django.shortcuts import get_object_or_404, redirect, render +from django.urls import reverse, reverse_lazy from django.utils.translation import gettext as _ from django.views.generic import CreateView -from cookbook.forms import ImportRecipeForm, RecipeImport, KeywordForm, Storage, StorageForm, InternalRecipeForm, \ - RecipeBookForm, MealPlanForm, InviteLinkForm -from cookbook.helper.permission_helper import GroupRequiredMixin, group_required -from cookbook.models import Keyword, Recipe, RecipeBook, MealPlan, ShareLink, MealType, Step, InviteLink +from cookbook.forms import (ImportRecipeForm, InviteLinkForm, KeywordForm, + MealPlanForm, RecipeBookForm, RecipeImport, + Storage, StorageForm) +from cookbook.helper.permission_helper import (GroupRequiredMixin, + group_required) +from cookbook.models import (InviteLink, Keyword, MealPlan, MealType, Recipe, + RecipeBook, ShareLink, Step) class RecipeCreate(GroupRequiredMixin, CreateView): diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 7b2ae082..138421f6 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -1,30 +1,28 @@ -import copy import os -from datetime import datetime, timedelta +from datetime import datetime from uuid import UUID + +from django.conf import settings from django.contrib import messages -from django.contrib.auth import update_session_auth_hash, authenticate +from django.contrib.auth import update_session_auth_hash from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.password_validation import validate_password from django.core.exceptions import ValidationError from django.db import IntegrityError -from django.db.models import Q, Avg +from django.db.models import Avg, Q from django.http import HttpResponseRedirect -from django.shortcuts import render, get_object_or_404 +from django.shortcuts import get_object_or_404, render from django.urls import reverse, reverse_lazy from django.utils import timezone -from django.views.decorators.clickjacking import xframe_options_exempt -from django_tables2 import RequestConfig from django.utils.translation import gettext as _ - -from django.conf import settings +from django_tables2 import RequestConfig from rest_framework.authtoken.models import Token from cookbook.filters import RecipeFilter from cookbook.forms import * from cookbook.helper.permission_helper import group_required, share_link_valid -from cookbook.tables import RecipeTable, RecipeTableSmall, CookLogTable, ViewLogTable - +from cookbook.tables import (CookLogTable, RecipeTable, RecipeTableSmall, + ViewLogTable) from recipes.version import * @@ -129,7 +127,8 @@ def recipe_view(request, pk, share=None): return render(request, 'recipe_view.html', {'recipe': recipe, 'comments': comments, 'comment_form': comment_form, - 'bookmark_form': bookmark_form, 'share': share, 'user_servings': user_servings}) + 'bookmark_form': bookmark_form, 'share': share, 'user_servings': user_servings + }) @group_required('user') @@ -248,7 +247,8 @@ def user_settings(request): return render(request, 'settings.html', {'preference_form': preference_form, 'user_name_form': user_name_form, 'password_form': password_form, - 'api_token': api_token}) + 'api_token': api_token + }) @group_required('guest') @@ -267,7 +267,8 @@ def system(request): return render(request, 'system.html', {'gunicorn_media': settings.GUNICORN_MEDIA, 'debug': settings.DEBUG, 'postgres': postgres, - 'version': VERSION_NUMBER, 'ref': BUILD_REF, 'secret_key': secret_key}) + 'version': VERSION_NUMBER, 'ref': BUILD_REF, 'secret_key': secret_key + }) def setup(request):