31 lines
919 B
Python
31 lines
919 B
Python
from django.views.generic import UpdateView
|
|
from django.contrib.auth.forms import UserChangeForm
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from custom_auth.models import User
|
|
|
|
|
|
@method_decorator(login_required, name="dispatch")
|
|
class ProfileView(UpdateView):
|
|
model = User
|
|
form_class = UserChangeForm
|
|
template_name = "frontend/profile.html"
|
|
success_url = "/"
|
|
|
|
def get_object(self):
|
|
return self.request.user
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context["apps"] = self.request.user.apps.all()
|
|
return context
|
|
|
|
def get_form_kwargs(self):
|
|
kwargs = super().get_form_kwargs()
|
|
kwargs["instance"] = self.request.user
|
|
return kwargs
|
|
|
|
def form_valid(self, form):
|
|
form.save()
|
|
return super().form_valid(form)
|