Commit 2c1ce944 by Carpoon

Group import/export add rerror handling

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