backup basic fixture
This commit is contained in:
parent
363a4b6ff7
commit
9510562576
@ -10,7 +10,21 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{% trans 'System Information' %}</h1>
|
||||
<h1>{% trans 'System' %}</h1>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<h3>{% trans 'Backup & Restore' %}</h3>
|
||||
<a href="{% url 'api_backup' %}" class="btn btn-success">{% trans 'Download Backup' %}</a>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<h3>{% trans 'System Information' %}</h3>
|
||||
|
||||
{% blocktrans %}
|
||||
Django Recipes is an open source free software application. It can be found on
|
||||
|
@ -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/<int:recipe_id>/', api.log_cooking, name='api_log_cooking'),
|
||||
path('api/plan-ical/<slug:html_week>/', api.get_plan_ical, name='api_get_plan_ical'),
|
||||
path('api/recipe-from-url/<path: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'),
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user