summaryrefslogtreecommitdiff
path: root/app/accounts/views.py
blob: 75bb9332fb98090af16703caa3509ef1d41d4e8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from django.views.generic import UpdateView, DetailView
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required

from .models import UserProfile
from .forms import ProfileForm


@method_decorator(login_required, name='dispatch')
class UpdateViewWithUser(UpdateView):

    def get_form_kwargs(self, **kwargs):
        kwargs = super().get_form_kwargs(**kwargs)
        kwargs.update({'user': self.request.user})
        return kwargs


class ProfileView(UpdateViewWithUser):
    model = UserProfile
    form_class = ProfileForm
    template_name = "accounts/change-settings.html"

    def get_object(self):
        return self.request.user.profile


class SettingsListView(DetailView):
    model = UserProfile
    template_name = "accounts/profile.html"

    def get_object(self):
        return self.request.user.profile