aboutsummaryrefslogtreecommitdiff
path: root/apps/accounts/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/accounts/views.py')
-rw-r--r--apps/accounts/views.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/apps/accounts/views.py b/apps/accounts/views.py
new file mode 100644
index 0000000..e51c60e
--- /dev/null
+++ b/apps/accounts/views.py
@@ -0,0 +1,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/profile.html"
+
+ def get_object(self):
+ return self.request.user.userprofile
+
+
+class SettingsListView(DetailView):
+ model = UserProfile
+ template_name = "accounts/profile.html"
+
+ def get_object(self):
+ return self.request.user.userprofile