Commit f40abcce authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[accounts][views] created template pattern to generate response

parent 6a4fab3d
......@@ -139,6 +139,15 @@ def account_settings(request):
'token' : user.auth_token})
def generate_load_response(request, temp_url, template, parameters):
answer = {}
answer["template"] = template
answer["parameters"] = parameters
temp_url.delete()
return render(request, answer["template"], answer["parameters"])
def load_temporary_url(request, hash_url):
temp_url = get_object_or_404(TemporaryUrl, url_hash=hash_url)
supervisiontrack = temp_url.supervision_track
......@@ -178,15 +187,10 @@ def load_temporary_url(request, hash_url):
context,
[supervisee.email])
temp_url.delete()
return render(request,
'accounts/url_validation.html',
{'supervisiontrack': supervisiontrack})
return generate_load_response(request, temp_url, "accounts/url_validation.html", {"supervisiontrack": supervisiontrack})
else:
#Track already valid
temp_url.delete()
return render(request,
'accounts/url_validation_failed.html')
return generate_load_response(request, temp_url, "accounts/url_validation_failed.html", {})
elif temp_url.status == TemporaryUrl.YEARREVALIDATION:
# Supervisee re-validation
if supervisee.profile.supervision_key is not None and now < temp_url.expires:
......@@ -220,18 +224,12 @@ def load_temporary_url(request, hash_url):
else:
#Track already valid
error_message = "You don't need to revalidate at the moment, your supervision is still valid"
temp_url.delete()
return render(request,
'accounts/url_revalidation_failed.html',
{'error_message': error_message})
return generate_load_response(request, temp_url, "accounts/url_revalidation_failed.html", {"error_message": error_message})
else:
#A pending request already exist
error_message = "You are not able to perform this action as you already have a pending supervision request"
temp_url.delete()
return render(request,
'accounts/url_revalidation_failed.html',
{'error_message': error_message})
return generate_load_response(request, temp_url, "accounts/url_revalidation_failed.html", {"error_message": error_message})
else:
#No key is present in supervisee
......@@ -247,18 +245,10 @@ def load_temporary_url(request, hash_url):
#Not allowed to do this (unproper profile.status)
error_message = "You are not allowed to perform this action, you first need to get a valid supervision"
temp_url.delete()
return render(request,
'accounts/url_revalidation_failed.html',
{'error_message': error_message})
return generate_load_response(request, temp_url, "accounts/url_revalidation_failed.html", {"error_message": error_message})
temp_url.delete()
return render(request,
'accounts/url_validation.html',
{'supervisiontrack': supervisiontrack})
return generate_load_response(request, temp_url, "accounts/url_validation.html", {'supervisiontrack': supervisiontrack})
else:
#Track already valid
temp_url.delete()
return render(request,
'accounts/url_validation_failed.html')
return generate_load_response(request, temp_url, "accounts/url_validation_failed.html", {})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment