diff --git a/cookbook/urls.py b/cookbook/urls.py index 76018f11..2ce554e3 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -1,12 +1,16 @@ from pydoc import locate -from django.urls import path, include +from django.urls import include, path from rest_framework import routers from rest_framework.schemas import get_schema_view -from .views import * -from cookbook.views import api, import_export from cookbook.helper import dal +from recipes.version import VERSION_NUMBER + +from .models import (Comment, Food, InviteLink, Keyword, MealPlan, Recipe, + RecipeBook, RecipeBookEntry, RecipeImport, ShoppingList, + Storage, Sync, SyncLog, get_model_name) +from .views import api, data, delete, edit, import_export, lists, new, views router = routers.DefaultRouter() router.register(r'user-name', api.UserNameViewSet, basename='username') @@ -47,37 +51,84 @@ urlpatterns = [ path('export/', import_export.export_recipe, name='view_export'), path('view/recipe/', views.recipe_view, name='view_recipe'), - path('view/recipe//', views.recipe_view, name='view_recipe'), + path( + 'view/recipe//', + views.recipe_view, + name='view_recipe' + ), - path('new/recipe-import//', new.create_new_external_recipe, name='new_recipe_import'), + path( + 'new/recipe-import//', + new.create_new_external_recipe, + name='new_recipe_import' + ), path('new/share-link//', new.share_link, name='new_share_link'), path('edit/recipe//', edit.switch_recipe, name='edit_recipe'), - path('edit/recipe/internal//', edit.internal_recipe_update, name='edit_internal_recipe'), # for internal use only - path('edit/recipe/external//', edit.ExternalRecipeUpdate.as_view(), name='edit_external_recipe'), # for internal use only - path('edit/recipe/convert//', edit.convert_recipe, name='edit_convert_recipe'), # for internal use only + + # for internal use only + path( + 'edit/recipe/internal//', + edit.internal_recipe_update, + name='edit_internal_recipe' + ), + path( + 'edit/recipe/external//', + edit.ExternalRecipeUpdate.as_view(), + name='edit_external_recipe' + ), + path( + 'edit/recipe/convert//', + edit.convert_recipe, + name='edit_convert_recipe' + ), path('edit/storage//', edit.edit_storage, name='edit_storage'), path('edit/ingredient/', edit.edit_ingredients, name='edit_food'), - path('delete/recipe-source//', delete.delete_recipe_source, name='delete_recipe_source'), + path( + 'delete/recipe-source//', + delete.delete_recipe_source, + name='delete_recipe_source' + ), - path('data/sync', data.sync, name='data_sync'), # TODO move to generic "new" view + # TODO move to generic "new" view + path('data/sync', data.sync, name='data_sync'), path('data/batch/edit', data.batch_edit, name='data_batch_edit'), path('data/batch/import', data.batch_import, name='data_batch_import'), path('data/sync/wait', data.sync_wait, name='data_sync_wait'), path('data/statistics', data.statistics, name='data_stats'), path('data/import/url', data.import_url, name='data_import_url'), - path('api/get_external_file_link//', api.get_external_file_link, name='api_get_external_file_link'), - path('api/get_recipe_file//', api.get_recipe_file, name='api_get_recipe_file'), + path( + 'api/get_external_file_link//', + api.get_external_file_link, + name='api_get_external_file_link' + ), + path( + 'api/get_recipe_file//', + api.get_recipe_file, + name='api_get_recipe_file' + ), path('api/sync_all/', api.sync_all, name='api_sync'), - path('api/log_cooking//', api.log_cooking, name='api_log_cooking'), - path('api/plan-ical///', api.get_plan_ical, name='api_get_plan_ical'), - path('api/recipe-from-url/', api.recipe_from_url, name='api_recipe_from_url'), + path( + 'api/log_cooking//', + api.log_cooking, + name='api_log_cooking' + ), + path( + 'api/plan-ical///', + api.get_plan_ical, + name='api_get_plan_ical' + ), + path( + 'api/recipe-from-url/', api.recipe_from_url, name='api_recipe_from_url' + ), path('api/backup/', api.get_backup, name='api_backup'), - path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'), + path( + 'dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword' + ), path('dal/food/', dal.IngredientsAutocomplete.as_view(), name='dal_food'), path('dal/unit/', dal.UnitAutocomplete.as_view(), name='dal_unit'), @@ -90,24 +141,50 @@ urlpatterns = [ ), name='openapi-schema'), path('api/', include((router.urls, 'api'))), - path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), + path( + 'api-auth/', + include('rest_framework.urls', namespace='rest_framework') + ), ] -generic_models = (Recipe, RecipeImport, Storage, RecipeBook, MealPlan, SyncLog, Sync, Comment, RecipeBookEntry, Keyword, Food, ShoppingList, InviteLink) +generic_models = ( + Recipe, RecipeImport, Storage, RecipeBook, MealPlan, SyncLog, Sync, + Comment, RecipeBookEntry, Keyword, Food, ShoppingList, InviteLink +) for m in generic_models: py_name = get_model_name(m) url_name = py_name.replace('_', '-') if c := locate(f'cookbook.views.new.{m.__name__}Create'): - urlpatterns.append(path(f'new/{url_name}/', c.as_view(), name=f'new_{py_name}')) + urlpatterns.append( + path( + f'new/{url_name}/', c.as_view(), name=f'new_{py_name}' + ) + ) if c := locate(f'cookbook.views.edit.{m.__name__}Update'): - urlpatterns.append(path(f'edit/{url_name}//', c.as_view(), name=f'edit_{py_name}')) + urlpatterns.append( + path( + f'edit/{url_name}//', + c.as_view(), + name=f'edit_{py_name}' + ) + ) if c := getattr(lists, py_name, None): - urlpatterns.append(path(f'list/{url_name}/', c, name=f'list_{py_name}')) + urlpatterns.append( + path( + f'list/{url_name}/', c, name=f'list_{py_name}' + ) + ) if c := locate(f'cookbook.views.delete.{m.__name__}Delete'): - urlpatterns.append(path(f'delete/{url_name}//', c.as_view(), name=f'delete_{py_name}')) + urlpatterns.append( + path( + f'delete/{url_name}//', + c.as_view(), + name=f'delete_{py_name}' + ) + ) diff --git a/cookbook/views/__init__.py b/cookbook/views/__init__.py index 44c4ca5b..ab37dad9 100644 --- a/cookbook/views/__init__.py +++ b/cookbook/views/__init__.py @@ -1,8 +1,19 @@ -# flake8: noqa -from cookbook.views.api import * -from cookbook.views.data 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 * +import cookbook.views.api +import cookbook.views.data +import cookbook.views.delete +import cookbook.views.edit +import cookbook.views.import_export +import cookbook.views.lists +import cookbook.views.new +import cookbook.views.views + +__all__ = [ + 'api', + 'data', + 'delete', + 'edit', + 'import_export', + 'lists', + 'new', + 'views', +]