diff --git a/www/conservancy/apps/assignment/forms.py b/www/conservancy/apps/assignment/forms.py new file mode 100644 index 0000000000000000000000000000000000000000..5016ff917b2501590e1f6073eae4a1c7c8545650 --- /dev/null +++ b/www/conservancy/apps/assignment/forms.py @@ -0,0 +1,59 @@ +from django import forms +from django.core.validators import ValidationError +from django.utils import timezone + +from .models import Assignment +from .terms import TERMS + + +def validate_in_past(value): + if value >= timezone.now().date(): + raise ValidationError('Enter a date in the past') + + +class AssignmentForm(forms.ModelForm): + period_begins = forms.DateField( + label='Start of period to assign', + required=True, + widget=forms.DateInput(attrs={'type': 'date'}), + validators=[validate_in_past], + ) + period_end_type = forms.ChoiceField( + label='End of period to assign', + choices=[ + ('all future contributions', 'all future contributions'), + ('a specific past date', 'a specific past date (specify below)'), + ], + widget=forms.RadioSelect(), + ) + period_ends = forms.DateField( + label='Specific past date (if applicable)', + required=False, + widget=forms.DateInput(attrs={'type': 'date'}), + validators=[validate_in_past], + ) + agreement_terms = forms.CharField( + widget=forms.Textarea(attrs={'readonly': 'readonly'}), + initial=TERMS, + help_text='Please be aware that some employment agreements explicitly transfer copyright ownership to the employer. We recommend you review your recent employment agreements for such clauses.', + ) + + class Meta: + model = Assignment + fields = [ + 'full_name', + 'email', + 'country_of_residence', + 'repositories', + 'all_emails', + 'period_begins', + 'period_end_type', + 'period_ends', + 'agreement_terms', + 'attestation_of_copyright', + ] + + def clean_period_ends(self): + cleaned_data = super().clean() + if 'period_begins' in cleaned_data and 'period_ends' in cleaned_data and cleaned_data['period_begins'] > cleaned_data['period_ends']: + raise ValidationError('End of period is before start')