Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2c1ce944
authored
Dec 14, 2023
by
Carpoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Group import/export add rerror handling
parent
d7c3c84c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
33 deletions
+62
-33
circle/dashboard/views/group.py
+62
-33
No files found.
circle/dashboard/views/group.py
View file @
2c1ce944
...
@@ -453,24 +453,34 @@ class GroupImportView(LoginRequiredMixin, TemplateView):
...
@@ -453,24 +453,34 @@ class GroupImportView(LoginRequiredMixin, TemplateView):
if
form
.
is_valid
():
if
form
.
is_valid
():
group_path
=
form
.
cleaned_data
[
"group_path"
]
group_path
=
form
.
cleaned_data
[
"group_path"
]
url
=
Store
(
request
.
user
)
.
request_download
(
group_path
)
url
=
Store
(
request
.
user
)
.
request_download
(
group_path
)
json_str
=
requests
.
get
(
url
)
.
content
try
:
profile
=
GroupProfile
.
create_from_json
(
request
.
user
,
json_str
)
response
=
requests
.
get
(
url
,
verify
=
False
)
if
profile
is
None
:
#response = requests.get(url)
raise
SuspiciousOperation
()
if
response
.
status_code
==
200
:
json_str
=
response
.
content
success_message
=
_
(
"Group successfully imported."
)
profile
=
GroupProfile
.
create_from_json
(
request
.
user
,
json_str
)
if
request
.
is_ajax
():
if
profile
is
None
:
response
=
{
raise
SuspiciousOperation
()
'message'
:
success_message
,
'redirect'
:
profile
.
get_absolute_url
()
success_message
=
_
(
"Group successfully imported."
)
}
if
request
.
is_ajax
():
return
HttpResponse
(
response
=
{
json
.
dumps
(
response
),
'message'
:
success_message
,
content_type
=
"application/json"
'redirect'
:
profile
.
get_absolute_url
()
)
}
else
:
return
HttpResponse
(
messages
.
success
(
request
,
success_message
)
json
.
dumps
(
response
),
return
redirect
(
profile
.
get_absolute_url
())
content_type
=
"application/json"
)
else
:
messages
.
success
(
request
,
success_message
)
return
redirect
(
profile
.
get_absolute_url
())
else
:
messages
.
error
(
request
,
response
.
reason
)
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
except
requests
.
exceptions
.
RequestException
as
e
:
messages
.
error
(
e
)
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
else
:
else
:
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
...
@@ -529,21 +539,40 @@ class GroupExportView(LoginRequiredMixin, SingleObjectMixin, TemplateView):
...
@@ -529,21 +539,40 @@ class GroupExportView(LoginRequiredMixin, SingleObjectMixin, TemplateView):
url
=
store
.
request_upload
(
"/"
)
url
=
store
.
request_upload
(
"/"
)
data
=
{
'data'
:
(
name
+
'.group'
,
group_json
)}
data
=
{
'data'
:
(
name
+
'.group'
,
group_json
)}
requests
.
post
(
url
,
files
=
data
)
try
:
response
=
requests
.
post
(
url
,
files
=
data
,
verify
=
False
)
success_message
=
_
(
"Group successfully exported."
)
#response = requests.post(url, files=data)
if
request
.
is_ajax
():
if
response
.
status_code
==
200
:
response
=
{
success_message
=
_
(
"Group successfully exported."
)
'message'
:
success_message
,
if
request
.
is_ajax
():
'redirect'
:
group
.
profile
.
get_absolute_url
()
ajax_response
=
{
}
'message'
:
success_message
,
return
HttpResponse
(
'redirect'
:
group
.
profile
.
get_absolute_url
()
json
.
dumps
(
response
),
}
content_type
=
"application/json"
return
HttpResponse
(
)
json
.
dumps
(
ajax_response
),
else
:
content_type
=
"application/json"
messages
.
success
(
request
,
success_message
)
)
return
redirect
(
group
.
profile
.
get_absolute_url
())
else
:
messages
.
success
(
request
,
success_message
)
return
redirect
(
group
.
profile
.
get_absolute_url
())
else
:
if
request
.
is_ajax
():
ajax_response
=
{
'message'
:
response
.
reason
,
'redirect'
:
group
.
profile
.
get_absolute_url
()
}
return
HttpResponse
(
json
.
dumps
(
ajax_response
),
content_type
=
"application/json"
)
else
:
messages
.
error
(
request
,
response
.
reason
)
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
# This catches all requests Exceptions as this is the base class
except
requests
.
exceptions
.
RequestException
as
e
:
messages
.
error
(
e
)
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
else
:
else
:
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
...
...
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