vkk.workhours.contributor.mixins
This submodule contains a collection of mixin classes.
1""" 2This submodule contains a collection of mixin classes. 3""" 4 5from django.contrib.auth.mixins import AccessMixin 6from django.utils import timezone 7from django.db.models import Q 8from vkk.workhours.models import ProjectAssignment, Period 9from vkk.workhours.forms import PeriodSelectForm 10 11 12class ContributorRequiredMixin(AccessMixin): 13 """ 14 Verify that the current user is a contributor to the given project. 15 """ 16 17 def dispatch(self, request, *args, **kwargs): 18 """ 19 Dispatches an incoming request according to its method. 20 """ 21 assignment_query = ProjectAssignment.objects.filter( 22 pk=kwargs.get('assignment_pk') 23 ) 24 if not request.user.is_authenticated or not assignment_query.exists(): 25 return self.handle_no_permission() 26 return super().dispatch(request, *args, **kwargs) 27 28 29class ContributorPeriodSelectorMixin(): 30 """ 31 Adds a Form for selecting Periods. 32 """ 33 34 def get_context_data(self, **kwargs): 35 """ 36 Returns a dictionary of context data used in the template layer. 37 """ 38 now = timezone.now() 39 query_set = Period.objects.filter( 40 Q(dead_line__gte=now) | 41 Q(workhours__project_assignment__pk=self.kwargs['assignment_pk']) | 42 Q(periodclosure__project_assignment__pk=self.kwargs['assignment_pk']) 43 ).distinct() 44 context = super().get_context_data(**kwargs) 45 context['period_selector'] = PeriodSelectForm( 46 queryset=query_set.order_by('-start'), 47 initial={'period': self.kwargs['period_pk']} 48 ) 49 return context
class
ContributorRequiredMixin(django.contrib.auth.mixins.AccessMixin):
13class ContributorRequiredMixin(AccessMixin): 14 """ 15 Verify that the current user is a contributor to the given project. 16 """ 17 18 def dispatch(self, request, *args, **kwargs): 19 """ 20 Dispatches an incoming request according to its method. 21 """ 22 assignment_query = ProjectAssignment.objects.filter( 23 pk=kwargs.get('assignment_pk') 24 ) 25 if not request.user.is_authenticated or not assignment_query.exists(): 26 return self.handle_no_permission() 27 return super().dispatch(request, *args, **kwargs)
Verify that the current user is a contributor to the given project.
def
dispatch(self, request, *args, **kwargs):
18 def dispatch(self, request, *args, **kwargs): 19 """ 20 Dispatches an incoming request according to its method. 21 """ 22 assignment_query = ProjectAssignment.objects.filter( 23 pk=kwargs.get('assignment_pk') 24 ) 25 if not request.user.is_authenticated or not assignment_query.exists(): 26 return self.handle_no_permission() 27 return super().dispatch(request, *args, **kwargs)
Dispatches an incoming request according to its method.
Inherited Members
- django.contrib.auth.mixins.AccessMixin
- login_url
- permission_denied_message
- raise_exception
- redirect_field_name
- get_login_url
- get_permission_denied_message
- get_redirect_field_name
- handle_no_permission
class
ContributorPeriodSelectorMixin:
30class ContributorPeriodSelectorMixin(): 31 """ 32 Adds a Form for selecting Periods. 33 """ 34 35 def get_context_data(self, **kwargs): 36 """ 37 Returns a dictionary of context data used in the template layer. 38 """ 39 now = timezone.now() 40 query_set = Period.objects.filter( 41 Q(dead_line__gte=now) | 42 Q(workhours__project_assignment__pk=self.kwargs['assignment_pk']) | 43 Q(periodclosure__project_assignment__pk=self.kwargs['assignment_pk']) 44 ).distinct() 45 context = super().get_context_data(**kwargs) 46 context['period_selector'] = PeriodSelectForm( 47 queryset=query_set.order_by('-start'), 48 initial={'period': self.kwargs['period_pk']} 49 ) 50 return context
Adds a Form for selecting Periods.
def
get_context_data(self, **kwargs):
35 def get_context_data(self, **kwargs): 36 """ 37 Returns a dictionary of context data used in the template layer. 38 """ 39 now = timezone.now() 40 query_set = Period.objects.filter( 41 Q(dead_line__gte=now) | 42 Q(workhours__project_assignment__pk=self.kwargs['assignment_pk']) | 43 Q(periodclosure__project_assignment__pk=self.kwargs['assignment_pk']) 44 ).distinct() 45 context = super().get_context_data(**kwargs) 46 context['period_selector'] = PeriodSelectForm( 47 queryset=query_set.order_by('-start'), 48 initial={'period': self.kwargs['period_pk']} 49 ) 50 return context
Returns a dictionary of context data used in the template layer.