2018-12-10 15:58:35 +00:00
|
|
|
"""passbook core user views"""
|
|
|
|
from django.contrib import messages
|
2020-05-10 22:49:48 +00:00
|
|
|
from django.contrib.auth import logout
|
2019-03-11 10:25:59 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2019-02-27 14:09:05 +00:00
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
2020-05-10 22:49:48 +00:00
|
|
|
from django.shortcuts import reverse
|
2019-02-27 14:09:05 +00:00
|
|
|
from django.urls import reverse_lazy
|
2018-12-10 15:58:35 +00:00
|
|
|
from django.utils.translation import gettext as _
|
2020-05-10 22:49:48 +00:00
|
|
|
from django.views.generic import DeleteView, UpdateView
|
2018-12-10 15:58:35 +00:00
|
|
|
|
2020-05-10 22:49:48 +00:00
|
|
|
from passbook.core.forms.users import UserDetailForm
|
2018-12-10 15:58:35 +00:00
|
|
|
|
|
|
|
|
2019-03-11 10:25:59 +00:00
|
|
|
class UserSettingsView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
|
2018-12-10 15:58:35 +00:00
|
|
|
"""Update User settings"""
|
2019-02-26 09:57:05 +00:00
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
template_name = "user/settings.html"
|
2018-12-10 15:58:35 +00:00
|
|
|
form_class = UserDetailForm
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
success_message = _("Successfully updated user.")
|
|
|
|
success_url = reverse_lazy("passbook_core:user-settings")
|
2019-02-27 14:09:05 +00:00
|
|
|
|
2018-12-10 15:58:35 +00:00
|
|
|
def get_object(self):
|
|
|
|
return self.request.user
|
|
|
|
|
2019-03-11 10:25:59 +00:00
|
|
|
|
|
|
|
class UserDeleteView(LoginRequiredMixin, DeleteView):
|
2018-12-10 15:58:35 +00:00
|
|
|
"""Delete user account"""
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
template_name = "generic/delete.html"
|
2018-12-10 15:58:35 +00:00
|
|
|
|
|
|
|
def get_object(self):
|
|
|
|
return self.request.user
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2019-12-31 11:51:16 +00:00
|
|
|
messages.success(self.request, _("Successfully deleted user."))
|
2018-12-10 15:58:35 +00:00
|
|
|
logout(self.request)
|
2020-05-10 22:49:48 +00:00
|
|
|
return reverse("passbook_flows:default-auth")
|