class EntryForm(BaseEntryForm): funding_agency = forms.CharField(label='Funding Agency', max_length=255) grant_name = forms.CharField(label='Grant Name', max_length=255) amount = forms.DecimalField(widget=DollarInput, decimal_places=2, initial=0) overhead = forms.DecimalField(widget=DollarInput, required=False, decimal_places=2, initial=0) primary_use_of_funds = forms.CharField(label='Primary Use of Funds', required=False, max_length=255) title_of_project = forms.CharField(label='Title of Project', required=False, max_length=255) co_investigator = forms.CharField(label='Co-investigator', required=False, max_length=255) funding_program = forms.CharField(label='Funding Program', required=False, max_length=255) projected_start_date = SemesterField(required=False, semester_start=False) projected_end_date = SemesterField(required=False, semester_start=False)
class BaseEntryForm(forms.Form): start_date = SemesterField(required=True, semester_start=True, help_text="Day this becomes effective: enter date or enter semester code on the right") end_date = SemesterField(required=False, semester_start=False, help_text="Day this ends: enter date or enter semester code on the right") comments = forms.CharField(required=False, widget=forms.Textarea(attrs={'cols': 60, 'rows': 3})) unit = forms.ModelChoiceField(queryset=Unit.objects.none(), required=True) def __init__(self, editor, units, *args, **kwargs): handler = kwargs.pop('handler', None) self.person = kwargs.pop('person', None) self.editor = editor self.units = units super(BaseEntryForm, self).__init__(*args, **kwargs) self.fields['unit'].queryset = Unit.objects.filter(id__in=(u.id for u in units)) self.fields['unit'].choices = [(str(u.id), str(u)) for u in units] # Load initial data from the handler instance if possible if handler: self.initial['start_date'] = handler.event.start_date self.initial['end_date'] = handler.event.end_date self.initial['unit'] = handler.event.unit self.initial['comments'] = handler.event.comments # Load any handler specific field values for name in handler.CONFIG_FIELDS: self.initial[name] = handler.get_config(name, None) # force the comments field to the bottom comments = self.fields.pop('comments') self.fields['comments'] = comments self.post_init() def post_init(self): "Hook to do setup of the form" pass def clean_end_date(self): start_date = self.cleaned_data.get('start_date', None) end_date = self.cleaned_data['end_date'] if not start_date: return end_date if not end_date: return if start_date > end_date: raise forms.ValidationError('End date cannot be before the start date.') return end_date
class BaseEntryForm(forms.Form): start_date = SemesterField(required=True, semester_start=True) end_date = SemesterField(required=False, semester_start=False) comments = forms.CharField(required=False, widget=forms.Textarea(attrs={'cols': 60, 'rows': 3})) unit = forms.ModelChoiceField(queryset=Unit.objects.none(), required=True) def __init__(self, editor, units, *args, **kwargs): handler = kwargs.pop('handler', None) self.person = kwargs.pop('person', None) self.editor = editor self.units = units super(BaseEntryForm, self).__init__(*args, **kwargs) self.fields['unit'].queryset = Unit.objects.filter(id__in=(u.id for u in units)) self.fields['unit'].choices = [(unicode(u.id), unicode(u)) for u in units] # Load initial data from the handler instance if possible if handler: self.initial['start_date'] = handler.event.start_date self.initial['end_date'] = handler.event.end_date self.initial['unit'] = handler.event.unit self.initial['comments'] = handler.event.comments # Load any handler specific field values for name in handler.CONFIG_FIELDS: self.initial[name] = handler.get_config(name, None) # force the comments field to the bottom self.fields.keyOrder = [k for k in self.fields.keyOrder if k != 'comments'] self.fields.keyOrder.append('comments') self.post_init() def post_init(self): "Hook to do setup of the form" pass
class PositionForm(forms.ModelForm): title = forms.CharField(required=True) projected_start_date = SemesterField(semester_start=True, required=True) teaching_load = AnnualTeachingCreditField(label="Teaching Load", required=False) base_salary = AddSalaryField(required=False) add_salary = AddSalaryField(required=False) add_pay = AddPayField(required=False) position_number = forms.CharField(max_length=6, required=True) rank = forms.ChoiceField(choices=RANK_CHOICES, required=False) step = forms.DecimalField(max_digits=3, decimal_places=1, required=False) class Meta: fields = ['title', 'projected_start_date', 'unit', 'position_number', 'percentage', 'rank', 'step', 'base_salary', 'add_salary', 'add_pay'] model = Position widgets = { 'position_number': forms.TextInput(attrs={'size': '6'}) }