Allow editing and deleting profile

This commit is contained in:
Gabriel Augendre 2019-03-03 13:42:06 +01:00
parent a3e3d1c0b4
commit 56ec884f7b
7 changed files with 80 additions and 3 deletions

View file

@ -158,5 +158,6 @@ APP = {
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGOUT_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = '/'
django_heroku.settings(locals(), allowed_hosts=False, databases=DJANGO_ENV == 'prod')

View file

@ -0,0 +1,13 @@
{% extends 'map/base.html' %}
{% load crispy_forms_filters %}
{% block h1 %}Change your profile{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<button type="submit" class="btn btn-primary">Save</button>
<a href="{% url 'delete-profile' %}" class="btn btn-warning">Permanently delete your profile</a>
</form>
{% endblock %}

View file

@ -4,10 +4,16 @@
{% block h1 %}Delete your location{% endblock %}
{% block content %}
<p>Are you sure you want to delete your location ? There is no turning back.</p>
<div class="alert alert-warning">
<h4 class="alert-heading">Are you sure?</h4>
<p>
Are you sure you want to delete your location ? This can't be undone,
though you will be able to add it again in the future.
</p>
</div>
<form method="post">
{% csrf_token %}
<button type="submit" class="btn btn-danger">Yes I'm sure</button>
<a href="{% url 'map' %}" class="btn btn-secondary">Cancel</a>
<a href="{% url 'map' %}" class="btn btn-secondary">No, cancel</a>
</form>
{% endblock %}

View file

@ -0,0 +1,19 @@
{% extends 'map/base.html' %}
{% load crispy_forms_filters %}
{% block h1 %}Delete your location{% endblock %}
{% block content %}
<div class="alert alert-danger">
<h4 class="alert-heading">Are you sure?</h4>
<p>
Are you sure you want to delete your profile ? You will permanently lose access to this service.
This can't be undone.
</p>
</div>
<form method="post">
{% csrf_token %}
<button type="submit" class="btn btn-danger">Yes I'm sure</button>
<a href="{% url 'map' %}" class="btn btn-secondary">No, cancel</a>
</form>
{% endblock %}

View file

@ -20,12 +20,13 @@
<a class="dropdown-item" href="{% url 'admin:index' %}">Admin</a>
<div role="separator" class="dropdown-divider"></div>
{% endif %}
<a class="dropdown-item" href="{% url 'change-profile' %}">Edit profile</a>
<a class="dropdown-item" href="{% url 'password_change' %}">Change password</a>
<div role="separator" class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'logout' %}">Logout</a>
</div>
{% else %}
<a class="nav-link" href="{% url 'login' %}?next={% url 'map' %}">Login</a>
<a class="nav-link" href="{% url 'login' %}">Login</a>
{% endif %}
</li>
</ul>

View file

@ -7,4 +7,6 @@ urlpatterns = [
path('change-location', views.EditLocationView.as_view(), name='change-location'),
path('add-location', views.AddLocationView.as_view(), name='add-location'),
path('delete-location', views.DeleteLocationView.as_view(), name='delete-location'),
path('accounts/profile', views.UpdateProfileView.as_view(), name='change-profile'),
path('accounts/profile/delete', views.DeleteProfileView.as_view(), name='delete-profile'),
]

View file

@ -86,3 +86,38 @@ class DeleteLocationView(LoginRequiredMixin, generic.DeleteView):
def get_success_url(self):
messages.success(self.request, 'Your location has been successfully deleted')
return super().get_success_url()
class UpdateProfileView(LoginRequiredMixin, generic.UpdateView):
model = models.Friend
context_object_name = 'friend'
template_name = 'map/change_profile.html'
success_url = reverse_lazy('map')
fields = [
'username',
'first_name',
'last_name',
'email',
]
def get_object(self, queryset=None):
return self.request.user
def get_success_url(self):
messages.success(self.request, 'Your profile has been successfully updated')
return super().get_success_url()
class DeleteProfileView(LoginRequiredMixin, generic.DeleteView):
model = models.Friend
context_object_name = 'friend'
template_name = 'map/delete_profile.html'
success_url = reverse_lazy('map')
def get_object(self, queryset=None):
return self.request.user
def get_success_url(self):
messages.success(self.request, 'Your profile has been successfully and permanently deleted')
return super().get_success_url()