vkk.workhours.mixins
This submodule contains some Mixin classes.
1""" 2This submodule contains some Mixin classes. 3""" 4 5from django.urls import reverse 6from vkk.workhours.models import Period 7from vkk.workhours.forms import PeriodSelectForm 8 9 10class PeriodSelectorMixin(): 11 """ 12 Adds a Form for selecting Periods to another Form-subclass. 13 """ 14 15 period_select_namespace = None 16 17 def get_context_data(self, **kwargs): 18 """ 19 Adds the form for selecting `Period` instances to the context 20 and returns it. 21 """ 22 query_set = Period.objects.all() 23 context = super().get_context_data(**kwargs) 24 context['period_selector'] = PeriodSelectForm( 25 queryset=query_set.order_by('-start'), 26 initial={'period': self.kwargs['period_pk']} 27 ) 28 return context 29 30 def get_select_url(self): 31 """ 32 Returns the URL for redirecting based on `period_select_namespace`. 33 """ 34 return reverse( 35 self.period_select_namespace, 36 kwargs={'invoice_number': self.kwargs['invoice_number']} 37 )
class
PeriodSelectorMixin:
11class PeriodSelectorMixin(): 12 """ 13 Adds a Form for selecting Periods to another Form-subclass. 14 """ 15 16 period_select_namespace = None 17 18 def get_context_data(self, **kwargs): 19 """ 20 Adds the form for selecting `Period` instances to the context 21 and returns it. 22 """ 23 query_set = Period.objects.all() 24 context = super().get_context_data(**kwargs) 25 context['period_selector'] = PeriodSelectForm( 26 queryset=query_set.order_by('-start'), 27 initial={'period': self.kwargs['period_pk']} 28 ) 29 return context 30 31 def get_select_url(self): 32 """ 33 Returns the URL for redirecting based on `period_select_namespace`. 34 """ 35 return reverse( 36 self.period_select_namespace, 37 kwargs={'invoice_number': self.kwargs['invoice_number']} 38 )
Adds a Form for selecting Periods to another Form-subclass.
def
get_context_data(self, **kwargs):
18 def get_context_data(self, **kwargs): 19 """ 20 Adds the form for selecting `Period` instances to the context 21 and returns it. 22 """ 23 query_set = Period.objects.all() 24 context = super().get_context_data(**kwargs) 25 context['period_selector'] = PeriodSelectForm( 26 queryset=query_set.order_by('-start'), 27 initial={'period': self.kwargs['period_pk']} 28 ) 29 return context
Adds the form for selecting Period
instances to the context
and returns it.
def
get_select_url(self):
31 def get_select_url(self): 32 """ 33 Returns the URL for redirecting based on `period_select_namespace`. 34 """ 35 return reverse( 36 self.period_select_namespace, 37 kwargs={'invoice_number': self.kwargs['invoice_number']} 38 )
Returns the URL for redirecting based on period_select_namespace
.