vkk.workhours.accounting.new_users.forms
1from django.forms import ModelForm 2from datetime import date, timedelta 3from vkk.generic.forms import CustomDateInput 4from vkk.users.models import NewUser, send_renew_mail 5 6class NewUserRenewForm(ModelForm): 7 class Meta: 8 model = NewUser 9 fields = ['expiration_date'] 10 widgets = {'expiration_date' : CustomDateInput} 11 12 def __init__(self, *args, **kwargs): 13 if ( kwargs.get('initial') is None 14 or kwargs['initial'].get('expiration_date') is None ): 15 kwargs['initial'] = { 16 'expiration_date' : date.today() + timedelta(days=21) 17 } 18 super().__init__(*args, **kwargs) 19 20 def save(self, commit=True): 21 send_renew_mail(self.instance) 22 return super().save(commit)
class
NewUserRenewForm(django.forms.models.ModelForm):
7class NewUserRenewForm(ModelForm): 8 class Meta: 9 model = NewUser 10 fields = ['expiration_date'] 11 widgets = {'expiration_date' : CustomDateInput} 12 13 def __init__(self, *args, **kwargs): 14 if ( kwargs.get('initial') is None 15 or kwargs['initial'].get('expiration_date') is None ): 16 kwargs['initial'] = { 17 'expiration_date' : date.today() + timedelta(days=21) 18 } 19 super().__init__(*args, **kwargs) 20 21 def save(self, commit=True): 22 send_renew_mail(self.instance) 23 return super().save(commit)
The main implementation of all the Form logic. Note that this class is different than Form. See the comments by the Form class for more info. Any improvements to the form API should be made to this class, not to the Form class.
def
save(self, commit=True):
Save this form's self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.
Inherited Members
- django.forms.models.BaseModelForm
- clean
- validate_unique
- django.forms.forms.BaseForm
- order_fields
- errors
- is_valid
- add_prefix
- add_initial_prefix
- get_context
- non_field_errors
- add_error
- has_error
- full_clean
- has_changed
- changed_data
- is_multipart
- visible_fields
- get_initial_for_field
- django.forms.utils.RenderableFormMixin
- as_p
- as_table
- as_ul
- as_div
- django.forms.utils.RenderableMixin
- render
class
NewUserRenewForm.Meta: