Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e5d0098a
authored
Apr 12, 2021
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add group export view and template
parent
35e2670f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
1 deletions
+86
-1
circle/dashboard/templates/dashboard/group-export.html
+11
-0
circle/dashboard/views/group.py
+75
-1
No files found.
circle/dashboard/templates/dashboard/group-export.html
0 → 100644
View file @
e5d0098a
{% load crispy_forms_tags %}
{% load i18n %}
<p
class=
"text-muted"
>
{% trans "Export a group to the user store with the given filename." %}
</p>
<form
method=
"POST"
data-group_pk=
"{{ group.pk }}"
action=
"{% url "
dashboard
.
views
.
group-export
"
group_pk=
group.pk
%}"
>
{% csrf_token %}
{% crispy form %}
</form>
circle/dashboard/views/group.py
View file @
e5d0098a
...
@@ -31,6 +31,7 @@ from django.http import HttpResponse, Http404
...
@@ -31,6 +31,7 @@ from django.http import HttpResponse, Http404
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.views.generic
import
UpdateView
,
TemplateView
from
django.views.generic
import
UpdateView
,
TemplateView
from
django.views.generic.detail
import
SingleObjectMixin
from
django_tables2
import
SingleTableView
from
django_tables2
import
SingleTableView
from
itertools
import
chain
from
itertools
import
chain
...
@@ -39,7 +40,7 @@ from .util import (CheckedDetailView, AclUpdateView, search_user,
...
@@ -39,7 +40,7 @@ from .util import (CheckedDetailView, AclUpdateView, search_user,
saml_available
,
DeleteViewBase
)
saml_available
,
DeleteViewBase
)
from
..forms
import
(
from
..forms
import
(
AddGroupMemberForm
,
AclUserOrGroupAddForm
,
GroupPermissionForm
,
AddGroupMemberForm
,
AclUserOrGroupAddForm
,
GroupPermissionForm
,
GroupCreateForm
,
GroupImportForm
,
GroupProfileUpdateForm
,
GroupCreateForm
,
GroupImportForm
,
GroupProfileUpdateForm
,
GroupExportForm
,
)
)
from
..models
import
FutureMember
,
GroupProfile
from
..models
import
FutureMember
,
GroupProfile
from
..store_api
import
Store
,
NoStoreException
from
..store_api
import
Store
,
NoStoreException
...
@@ -427,6 +428,79 @@ class GroupImportView(LoginRequiredMixin, TemplateView):
...
@@ -427,6 +428,79 @@ class GroupImportView(LoginRequiredMixin, TemplateView):
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
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'
]
else
:
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
()
try
:
Store
(
request
.
user
)
except
NoStoreException
:
raise
PermissionDenied
()
if
form
is
None
:
form
=
self
.
form_class
(
group_name
=
self
.
object
.
name
)
context
=
self
.
get_context_data
(
**
kwargs
)
context
.
update
({
'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
()
try
:
Store
(
request
.
user
)
except
NoStoreException
:
raise
PermissionDenied
()
form
=
self
.
form_class
(
request
.
POST
,
group_name
=
self
.
object
.
name
)
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
)}
requests
.
post
(
url
,
files
=
data
)
success_message
=
_
(
"Group successfully exported."
)
if
request
.
is_ajax
():
response
=
{
'message'
:
success_message
,
'redirect'
:
group
.
profile
.
get_absolute_url
()
}
return
HttpResponse
(
json
.
dumps
(
response
),
content_type
=
"application/json"
)
else
:
messages
.
success
(
request
,
success_message
)
return
redirect
(
group
.
profile
.
get_absolute_url
())
else
:
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
class
GroupProfileUpdate
(
SuccessMessageMixin
,
GroupCodeMixin
,
class
GroupProfileUpdate
(
SuccessMessageMixin
,
GroupCodeMixin
,
LoginRequiredMixin
,
UpdateView
):
LoginRequiredMixin
,
UpdateView
):
form_class
=
GroupProfileUpdateForm
form_class
=
GroupProfileUpdateForm
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment