Commit e5d0098a by Máhonfai Bálint

Add group export view and template

parent 35e2670f
{% load crispy_forms_tags %}
{% load i18n %}
<p class="text-muted">
{% trans "Export a group to the user store with the given filename." %}
<form method="POST" data-group_pk="{{ }}" action="{% url "" %}">
{% csrf_token %}
{% crispy form %}
......@@ -31,6 +31,7 @@ from django.http import HttpResponse, Http404
from django.shortcuts import redirect
from django.utils.translation import ugettext as _
from django.views.generic import UpdateView, TemplateView
from django.views.generic.detail import SingleObjectMixin
from django_tables2 import SingleTableView
from itertools import chain
......@@ -39,7 +40,7 @@ from .util import (CheckedDetailView, AclUpdateView, search_user,
saml_available, DeleteViewBase)
from ..forms import (
AddGroupMemberForm, AclUserOrGroupAddForm, GroupPermissionForm,
GroupCreateForm, GroupImportForm, GroupProfileUpdateForm,
GroupCreateForm, GroupImportForm, GroupProfileUpdateForm, GroupExportForm,
from ..models import FutureMember, GroupProfile
from ..store_api import Store, NoStoreException
......@@ -427,6 +428,79 @@ class GroupImportView(LoginRequiredMixin, TemplateView):
return self.get(request, form, *args, **kwargs)
class GroupExportView(LoginRequiredMixin, SingleObjectMixin, TemplateView):
form_class = GroupExportForm
model = Group
pk_url_kwarg = "group_pk"
def __init__(self):
super(GroupExportView, self).__init__()
self.object = None
def get_template_names(self):
if self.request.is_ajax():
return ['dashboard/_modal.html']
return ['dashboard/nojs-wrapper.html']
def get(self, request, form=None, *args, **kwargs):
self.object = self.get_object()
if not self.object.profile.has_level(request.user, 'operator'):
raise PermissionDenied()
except NoStoreException:
raise PermissionDenied()
if form is None:
form = self.form_class(
context = self.get_context_data(**kwargs)
'group': self.object,
'template': 'dashboard/group-export.html',
'box_title': _('Export Group'),
'form': form,
'ajax_title': True,
return self.render_to_response(context)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
group = self.object
if not group.profile.has_level(request.user, 'operator'):
raise PermissionDenied()
except NoStoreException:
raise PermissionDenied()
form = self.form_class(request.POST,
if form.is_valid():
name = form.cleaned_data["exported_name"]
group_json = group.profile.convert_to_json()
store = Store(request.user)
url = store.request_upload("/")
data = {'data': (name + '.group', group_json)}, files=data)
success_message = _("Group successfully exported.")
if request.is_ajax():
response = {
'message': success_message,
'redirect': group.profile.get_absolute_url()
return HttpResponse(
messages.success(request, success_message)
return redirect(group.profile.get_absolute_url())
return self.get(request, form, *args, **kwargs)
class GroupProfileUpdate(SuccessMessageMixin, GroupCodeMixin,
LoginRequiredMixin, UpdateView):
form_class = GroupProfileUpdateForm
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment