Commit 2c1ce944 by Carpoon

Group import/export add rerror handling

parent d7c3c84c
......@@ -453,7 +453,11 @@ class GroupImportView(LoginRequiredMixin, TemplateView):
if form.is_valid():
group_path = form.cleaned_data["group_path"]
url = Store(request.user).request_download(group_path)
json_str = requests.get(url).content
try:
response = requests.get(url, verify=False)
#response = requests.get(url)
if response.status_code == 200:
json_str = response.content
profile = GroupProfile.create_from_json(request.user, json_str)
if profile is None:
raise SuspiciousOperation()
......@@ -472,6 +476,12 @@ class GroupImportView(LoginRequiredMixin, TemplateView):
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:
return self.get(request, form, *args, **kwargs)
......@@ -529,22 +539,41 @@ class GroupExportView(LoginRequiredMixin, SingleObjectMixin, TemplateView):
url = store.request_upload("/")
data = {'data': (name + '.group', group_json)}
requests.post(url, files=data)
try:
response = requests.post(url, files=data, verify=False)
#response = requests.post(url, files=data)
if response.status_code == 200:
success_message = _("Group successfully exported.")
if request.is_ajax():
response = {
ajax_response = {
'message': success_message,
'redirect': group.profile.get_absolute_url()
}
return HttpResponse(
json.dumps(response),
json.dumps(ajax_response),
content_type="application/json"
)
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:
return self.get(request, form, *args, **kwargs)
......
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