Return to previous page after Edit profile

Use a parameter to pass the current page to the Edit Profile URL so that
saving or cancelling returns you to that same page.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-11-19 15:52:11 +13:00
parent 61dd9527ba
commit b767d709ff
3 changed files with 4 additions and 3 deletions

View File

@ -844,6 +844,7 @@ class EditProfileFormView(SuccessMessageMixin, UpdateView):
else:
error_fields = form.errors.keys()
context['error_fields'] = error_fields
context['return_url'] = self.get_success_url()
return context
def get_object(self, queryset=None):
@ -870,7 +871,7 @@ class EditProfileFormView(SuccessMessageMixin, UpdateView):
return "Profile saved successfully"
def get_success_url(self):
return reverse('frontpage')
return self.request.GET.get('return_to', reverse('frontpage'))
@receiver(pre_save, sender=reversion.models.Version)

View File

@ -54,7 +54,7 @@
<ul class="dropdown-menu">
<li><a href="{% url 'auth_logout' %}">{% trans "Log out" %}</a></li>
<li><a href="{% url 'auth_password_change' %}">{% trans "Change password" %}</a></li>
<li><a href="{% url 'profile' %}">{% trans "Edit profile" %}</a></li>
<li><a href="{% url 'profile' %}?return_to={{ request.path }}">{% trans "Edit profile" %}</a></li>
</ul>
</div>
{% else %}

View File

@ -42,7 +42,7 @@
{% endfor %}
<input type="submit" class="btn btn-default" value="{% trans 'Save' %}" />
<a class="btn btn-default" href="{% url 'frontpage' %}">{% trans 'Cancel' %}</a>
<a class="btn btn-default" href="{{ return_url }}">{% trans 'Cancel' %}</a>
<a class="btn btn-danger" href="{% url 'delete_account' %}">{% trans 'Delete account' %}</a>
{% csrf_token %}
</form>