diff --git a/cookbook/templates/system.html b/cookbook/templates/system.html
index c17cc7794..50e86e4e2 100644
--- a/cookbook/templates/system.html
+++ b/cookbook/templates/system.html
@@ -10,7 +10,21 @@
{% block content %}
-
{% trans 'System Information' %}
+ {% trans 'System' %}
+
+
+
+
+
+ {% trans 'Backup & Restore' %}
+ {% trans 'Download Backup' %}
+
+
+
+
+
+
+ {% trans 'System Information' %}
{% blocktrans %}
Django Recipes is an open source free software application. It can be found on
diff --git a/cookbook/urls.py b/cookbook/urls.py
index 1edfb110d..73944baf0 100644
--- a/cookbook/urls.py
+++ b/cookbook/urls.py
@@ -18,7 +18,6 @@ router.register(r'keyword', api.KeywordViewSet)
router.register(r'unit', api.UnitViewSet)
router.register(r'food', api.FoodViewSet)
-
router.register(r'step', api.StepViewSet)
router.register(r'recipe', api.RecipeViewSet)
router.register(r'ingredient', api.IngredientViewSet)
@@ -26,7 +25,6 @@ router.register(r'meal-plan', api.MealPlanViewSet)
router.register(r'meal-type', api.MealTypeViewSet)
router.register(r'view-log', api.ViewLogViewSet)
-
urlpatterns = [
path('', views.index, name='index'),
path('setup/', views.setup, name='view_setup'),
@@ -72,6 +70,7 @@ urlpatterns = [
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/food/', dal.IngredientsAutocomplete.as_view(), name='dal_food'),
diff --git a/cookbook/views/api.py b/cookbook/views/api.py
index b08281952..5695726d2 100644
--- a/cookbook/views/api.py
+++ b/cookbook/views/api.py
@@ -9,10 +9,13 @@ from annoying.decorators import ajax_request
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.files import File
from django.db.models import Q
from django.http import HttpResponse, FileResponse, JsonResponse
from django.shortcuts import redirect
+from django.utils import timezone, dateformat
+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
@@ -199,7 +202,8 @@ class RecipeViewSet(viewsets.ModelViewSet, StandardFilterMixin):
queryset = Recipe.objects.all()
serializer_class = RecipeSerializer
permission_classes = [CustomIsShare | CustomIsGuest] # TODO split read and write permission for meal plan guest
- # TODO write extensive tests for permissions
+
+ # TODO write extensive tests for permissions
@decorators.action(
detail=True,
@@ -352,3 +356,16 @@ def recipe_from_url(request, url):
if response.status_code == 403:
return JsonResponse({'error': True, 'msg': _('The requested page refused to provide any information (Status Code 403).')}, status=400)
return get_from_html(response.text, url)
+
+
+def get_backup(request):
+ if not request.user.is_superuser:
+ return HttpResponse('', status=403)
+
+ buf = io.StringIO()
+ management.call_command('dumpdata', exclude=['contenttypes', 'auth'], stdout=buf)
+
+ response = FileResponse(buf.getvalue())
+ response["Content-Disposition"] = f'attachment; filename=backup{date_format(timezone.now(), format="SHORT_DATETIME_FORMAT", use_l10n=True)}.json'
+
+ return response