From 5d37117ca42d496ac8aa671795c1de8b1e8b2219 Mon Sep 17 00:00:00 2001 From: Zambom Date: Thu, 4 May 2017 23:12:58 -0300 Subject: [PATCH] Subject restore initials --- subjects/templates/subjects/backup.html | 8 +------- subjects/templates/subjects/restore.html | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ subjects/templates/subjects/subject_card.html | 1 + subjects/urls.py | 2 ++ subjects/views.py | 38 +++++++++++++++++++++++++++++++++++++- 5 files changed, 179 insertions(+), 8 deletions(-) create mode 100644 subjects/templates/subjects/restore.html diff --git a/subjects/templates/subjects/backup.html b/subjects/templates/subjects/backup.html index 850c38a..5d810f3 100644 --- a/subjects/templates/subjects/backup.html +++ b/subjects/templates/subjects/backup.html @@ -56,6 +56,7 @@
  • {% trans 'Edit' %}
  • {% trans 'Groups' %}
  • {% trans 'Backup' %}
  • +
  • {% trans 'Restore' %}
  •  {% trans 'Remove' %}
  • {% endif %} @@ -161,12 +162,5 @@ } }); }); - - // $("#bkp_form").submit(function () { - // setTimeout(function() { - // // Should be triggered after download started - // document.location.href="{% url 'subjects:view' subject.slug %}"; - // }, 3000); - // }); {% endblock content %} diff --git a/subjects/templates/subjects/restore.html b/subjects/templates/subjects/restore.html new file mode 100644 index 0000000..eb88d5c --- /dev/null +++ b/subjects/templates/subjects/restore.html @@ -0,0 +1,138 @@ +{% extends 'categories/home.html' %} + +{% load static i18n pagination permissions_tags subject_counter chat_tags %} +{% load django_bootstrap_breadcrumbs %} + +{% block javascript%} + {{ block.super }} + +{% endblock%} + +{% block breadcrumbs %} + {{ block.super }} + {% breadcrumb subject.category 'subjects:cat_view' subject.category.slug %} + {% breadcrumb subject 'subjects:view' subject.slug %} + + {% trans "Restore" as bread %} + {% breadcrumb bread 'subjects:restore' subject.slug %} +{% endblock %} + +{% block content %} + {% if messages %} + {% for message in messages %} + + {% endfor %} + {% endif %} + + {% subject_permissions request.user subject as has_subject_permissions %} + + {% if subject.visible %} +
    +
    + {% elif has_subject_permissions %} +
    +
    + {% endif %} +
    +
    +

    + {{ subject.name }} / {% trans "Restore" %} +

    + +
    + {% if request.user in subject.professor.all or request.user in subject.category.coordinators.all or request.user.is_staff %} + + + {% endif %} +
    +
    +
    +
    +
    +
    {% trans "Please select below the file you want to use for restore:" %}
    + +
    +
    + {% csrf_token %} + +
    + + +
    + + + + +
    + +
    + {% trans 'Click or drop the file here' %}
    +
    +
    + +
    + +
    +
    +
    +
    +
    + + +{% endblock %} \ No newline at end of file diff --git a/subjects/templates/subjects/subject_card.html b/subjects/templates/subjects/subject_card.html index 9c8b4a8..dc7a8f0 100644 --- a/subjects/templates/subjects/subject_card.html +++ b/subjects/templates/subjects/subject_card.html @@ -31,6 +31,7 @@
  • {% trans 'Edit' %}
  • {% trans 'Groups' %}
  • {% trans 'Backup' %}
  • +
  • {% trans 'Restore' %}
  •  {% trans 'Remove' %}
  • {% endif %} diff --git a/subjects/urls.py b/subjects/urls.py index 86a969c..219eca8 100644 --- a/subjects/urls.py +++ b/subjects/urls.py @@ -10,7 +10,9 @@ urlpatterns = [ url(r'^update/(?P[\w_-]+)/$', views.SubjectUpdateView.as_view(), name='update'), url(r'^delete/(?P[\w_-]+)/$', views.SubjectDeleteView.as_view(), name='delete'), url(r'^backup/(?P[\w_-]+)/$', views.Backup.as_view(), name='backup'), + url(r'^restore/(?P[\w_-]+)/$', views.Restore.as_view(), name='restore'), url(r'^do_backup/(?P[\w_-]+)/$', views.realize_backup, name='do_backup'), + url(r'^do_restore/(?P[\w_-]+)/$', views.realize_restore, name='do_restore'), url(r'^view/(?P[\w_-]+)/$', views.SubjectDetailView.as_view(), name='view'), url(r'^view/(?P[\w_-]+)/(?P[\w_-]+)/$', views.SubjectDetailView.as_view(), name='topic_view'), url(r'^subscribe/(?P[\w_-]+)/$', views.SubjectSubscribeView.as_view(), name='subscribe'), diff --git a/subjects/views.py b/subjects/views.py index 21d87c7..23fcbf2 100644 --- a/subjects/views.py +++ b/subjects/views.py @@ -837,4 +837,40 @@ def realize_backup(request, subject): resp['Content-Disposition'] = 'attachment; filename=%s' % zip_filename resp['Content-Length'] = s.tell() - return resp \ No newline at end of file + return resp + +class Restore(LoginRequiredMixin, TemplateView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'subjects/restore.html' + model = Subject + + def dispatch(self, request, *args, **kwargs): + subject = get_object_or_404(Subject, slug = kwargs.get('slug', '')) + + if not has_subject_permissions(request.user, subject): + return redirect(reverse_lazy('subjects:home')) + + return super(Restore, self).dispatch(request, *args, **kwargs) + + def get_context_data(self, **kwargs): + context = super(Restore, self).get_context_data(**kwargs) + + subject = get_object_or_404(Subject, slug = self.kwargs.get('slug', '')) + + context['title'] = _('%s - Restore')%(str(subject)) + context['subject'] = subject + + return context + +@login_required +def realize_restore(request, subject): + zip_file = request.FILES.get('zip_file', None) + + if zip_file: + if zipfile.is_zipfile(zip_file): + file = zipfile.ZipFile(zip_file) + print(file.namelist()) + + return JsonResponse({'message': 'ok'}) \ No newline at end of file -- libgit2 0.21.2