mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
"""Views belonging to the core of the project.
|
|
|
|
These views don't represent any of the models in the apps.
|
|
"""
|
|
|
|
from django.conf import settings
|
|
from django.contrib.auth import get_user_model
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.urls import reverse
|
|
from django.views.generic import TemplateView
|
|
from django.views.generic.edit import UpdateView
|
|
from django.contrib.auth.mixins import UserPassesTestMixin
|
|
import typing
|
|
|
|
from . import forms
|
|
|
|
User = get_user_model() # pylint: disable=invalid-name
|
|
|
|
|
|
class IndexView(TemplateView):
|
|
# Template set in Django settings file - may be customised by a customisation app
|
|
template_name = settings.TEMPLATE_NAME_INDEX
|
|
|
|
class UserIsStaffMixin(UserPassesTestMixin):
|
|
def test_func(self) -> typing.Optional[bool]:
|
|
return self.request.user.is_staff
|
|
|
|
|
|
class ConsentTextView(LoginRequiredMixin, UpdateView):
|
|
"""View with consent text and form for users to indicate consent."""
|
|
model = User
|
|
form_class = forms.ConsentForm
|
|
template_name = 'consent.html'
|
|
|
|
def get_success_url(self) -> str:
|
|
try:
|
|
return reverse('people:person.detail', kwargs={'pk': self.request.user.person.pk})
|
|
|
|
except AttributeError:
|
|
return reverse('index')
|
|
|
|
def get_object(self, *args, **kwargs) -> User:
|
|
return self.request.user
|