Exemplo n.º 1
0
class AssetChangeForm(forms.ModelForm):
    person = PersonField()

    def __init__(self, request, *args, **kwargs):
        super(AssetChangeForm, self).__init__(*args, **kwargs)
        #  The following two lines look stupid, but they are not.  request.units contains a set of units.
        #  in order to be used this way, we need an actual queryset.
        #
        #  In this case, we also include subunits.  If you manage assets for a parent unit, chances are you may be
        #  adding/removing them for events in your children units.
        unit_ids = [unit.id for unit in Unit.sub_units(request.units)]
        units = Unit.objects.filter(id__in=unit_ids)
        #  Get current events + any events in the last 12 weeks, that should give enough time to fix inventory based
        #  on events.
        self.fields['event'].queryset = OutreachEvent.objects.visible(units).\
            exclude(end_date__lt=datetime.datetime.today() - datetime.timedelta(weeks=12))

    class Meta:
        model = AssetChangeRecord
        widgets = {'date': CalendarWidget}
        fields = ['person', 'qty', 'event', 'date']

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(AssetChangeForm, self).is_valid(*args, **kwargs)
Exemplo n.º 2
0
class BookingRecordForm(forms.ModelForm):
    person = PersonField()

    class Meta:
        exclude = ['location']
        model = BookingRecord
        field_classes = {
            'start_time': forms.SplitDateTimeField,
            'end_time': forms.SplitDateTimeField,
        }
        widgets = {
            'start_time': forms.SplitDateTimeWidget,
            'end_time': forms.SplitDateTimeWidget,
            'notes': forms.Textarea,
        }

    def clean(self):
        cleaned_data = super(BookingRecordForm, self).clean()
        print(cleaned_data)
        start_time = cleaned_data.get("start_time")
        end_time = cleaned_data.get("end_time")
        if end_time is not None and start_time is not None and end_time < start_time:
            raise forms.ValidationError({
                'end_time':
                "End date/time cannot be before start date.",
                'start_time':
                "End date/time cannot be before start date."
            })

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(BookingRecordForm, self).is_valid(*args, **kwargs)
Exemplo n.º 3
0
class AssetForm(forms.ModelForm):
    user = PersonField(required=False)

    def __init__(self, request, *args, **kwargs):
        super(AssetForm, self).__init__(*args, **kwargs)
        unit_ids = [unit.id for unit in request.units]
        units = Unit.objects.filter(id__in=unit_ids)
        self.fields['unit'].queryset = units
        self.fields['unit'].empty_label = None
        SORTED_CATEGORIES = sorted(CATEGORY_CHOICES, key=lambda x: x[1])
        self.fields['category'].choices = SORTED_CATEGORIES

    class Meta:
        exclude = []
        model = Asset
        widgets = {
            'notes': forms.Textarea,
            'price': DollarInput,
            'last_order_date': CalendarWidget,
            'vendor': forms.Textarea,
            'service_records': forms.Textarea,
            'calibration_date': CalendarWidget,
            'eol_date': CalendarWidget,
            'date_shipped': CalendarWidget,
        }

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(AssetForm, self).is_valid(*args, **kwargs)
Exemplo n.º 4
0
class VisaForm(forms.ModelForm):
    def __init__(self, request, *args, **kwargs):
        super(VisaForm, self).__init__(*args, **kwargs)
        #  The following two lines look stupid, but they are not.  request.units contains a set of units.
        #  in order to be used this way, we need an actual queryset.
        #
        #  In this case, we also include subunits.  If you manage visas for a parent unit, chances are you may be
        #  adding/removing them for people in your children units.
        unit_ids = [unit.id for unit in Unit.sub_units(request.units)]
        units = Unit.objects.filter(id__in=unit_ids)
        self.fields['unit'].queryset = units
        self.fields['unit'].empty_label = None

    person = PersonField()

    class Meta:
        exclude = []
        model = Visa
        widgets = {'start_date': CalendarWidget, 'end_date': CalendarWidget}

    def clean(self):
        cleaned_data = super(VisaForm, self).clean()
        start_date = cleaned_data.get("start_date")
        end_date = cleaned_data.get("end_date")
        if end_date is not None and start_date is not None and end_date < start_date:
            raise forms.ValidationError(
                {'end_date': "End date cannot be before start date."})

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(VisaForm, self).is_valid(*args, **kwargs)
Exemplo n.º 5
0
class AdminAssignFormForm(_AdminAssignForm):
    form = _FormModelChoiceField(required=True,
                                 queryset=Form.objects.none(),
                                 empty_label=None)
    assignee = PersonField(label='Assign to', required=True, needs_email=True)

    def __init__(self, query_set, *args, **kwargs):
        super(AdminAssignFormForm, self).__init__(*args, **kwargs)
        self.fields['form'].queryset = query_set
Exemplo n.º 6
0
class AccessRuleForm(ModelForm):
    person = PersonField(label="Emplid", help_text="or type to search")

    class Meta:
        model = AccessRule
        exclude = ('report', 'hidden', 'config', 'created_at')

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(AccessRuleForm, self).is_valid(*args, **kwargs)
Exemplo n.º 7
0
class EmployeeSearchForm(forms.Form):
    search = PersonField(label="Person")
    email = forms.BooleanField(
        required=False,
        initial=True,
        help_text="Should this member be emailed when submissions come in?")

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(EmployeeSearchForm, self).is_valid(*args, **kwargs)
Exemplo n.º 8
0
class RAForm(forms.ModelForm):
    person = PersonField(label='Hire')
    sin = forms.IntegerField(label='SIN', required=False)
    use_hourly = forms.BooleanField(
        label='Use Hourly Rate',
        initial=False,
        required=False,
        help_text=
        'Should the hourly rate be displayed on the contract (or total hours for lump sum contracts)?'
    )

    class Meta:
        model = RAAppointment
        exclude = ('config', 'offer_letter_text', 'deleted')

    def __init__(self, *args, **kwargs):
        super(RAForm, self).__init__(*args, **kwargs)
        choices = self.fields['hiring_category'].choices
        choices = [(k, v) for k, v in choices
                   if k not in HIRING_CATEGORY_DISABLED]
        self.fields['hiring_category'].choices = choices

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(RAForm, self).is_valid(*args, **kwargs)

    def clean_sin(self):
        sin = self.cleaned_data['sin']
        try:
            emplid = int(self['person'].value())
        except ValueError:
            raise forms.ValidationError(
                "The correct format for a SIN is XXXXXXXXX, all numbers, no spaces or dashes."
            )
        people = Person.objects.filter(emplid=emplid)
        if people:
            person = people[0]
            person.set_sin(sin)
            person.save()
        return sin

    def clean_hours(self):
        data = self.cleaned_data['hours']
        if self.cleaned_data['pay_frequency'] == 'L':
            return data

        if int(data) > 168:
            raise forms.ValidationError("There are only 168 hours in a week.")
        if int(data) < 0:
            raise forms.ValidationError("One cannot work negative hours.")
        return data

    def clean(self):
        cleaned_data = self.cleaned_data
        return cleaned_data
Exemplo n.º 9
0
class SessionalContractForm(forms.ModelForm):
    person = PersonField()
    offering = OfferingField()

    def __init__(self, request, *args, **kwargs):
        super(SessionalContractForm, self).__init__(*args, **kwargs)
        unit_ids = [unit.id for unit in request.units]
        units = Unit.objects.filter(id__in=unit_ids)
        accounts = SessionalAccount.objects.visible(units)
        self.fields['account'].queryset = accounts
        self.fields['account'].empty_label = None
        self.fields['unit'].queryset = units
        self.fields['unit'].empty_label = None

    class Meta:
        exclude = ['sessional']
        model = SessionalContract
        widgets = {
            'pay_start': CalendarWidget,
            'pay_end': CalendarWidget,
            'appointment_start': CalendarWidget,
            'appointment_end': CalendarWidget,
            'contract_hours': forms.NumberInput(attrs={'class': 'smallnumberinput'}),
            'total_salary': DollarInput,
            'appt_guarantee': forms.RadioSelect,
            'appt_type': forms.RadioSelect
        }
        help_texts = {
            'notes': 'These will appear in the "Remarks" field of the payroll form.'
        }
        fields = ['person', 'account', 'unit', 'sin', 'visa_verified', 'appointment_start', 'appointment_end',
                  'pay_start', 'pay_end', 'offering', 'course_hours_breakdown','appt_guarantee', 'appt_type',
                  'contact_hours', 'total_salary', 'notes']

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(SessionalContractForm, self).is_valid(*args, **kwargs)

    def clean(self):
        cleaned_data = super(SessionalContractForm, self).clean()
        appointment_start = cleaned_data.get("appointment_start")
        appointment_end = cleaned_data.get("appointment_end")
        if appointment_end < appointment_start:
            raise forms.ValidationError({'appointment_end': "Appointment end date cannot be before appointment start "
                                                            "date.",
                                         'appointment_start': "Appointment end date cannot be before appointmentstart "
                                                              "date."})
        pay_start = cleaned_data.get("pay_start")
        pay_end = cleaned_data.get("pay_end")
        if pay_end < pay_start:
            raise forms.ValidationError({'pay_end': "Pay end date cannot be before pay start date.",
                                         'pay_start': "Pay end date cannot be before pay start date."})
        sin = cleaned_data.get("sin")
        if sin and len(sin) != 9:
            raise forms.ValidationError({'sin': "SIN has to be exactly 9 digits."})
Exemplo n.º 10
0
class VisaForm(forms.ModelForm):
    person = PersonField()

    class Meta:
        exclude = []
        model = Visa
        widgets = {'start_date': CalendarWidget, 'end_date': CalendarWidget}

    def clean(self):
        cleaned_data = super(VisaForm, self).clean()
        start_date = cleaned_data.get("start_date")
        end_date = cleaned_data.get("end_date")
        if end_date is not None and end_date < start_date:
            raise forms.ValidationError(
                "End date cannot be before start date.")

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(VisaForm, self).is_valid(*args, **kwargs)
Exemplo n.º 11
0
class NewRoleForm(forms.ModelForm):
    person = PersonField(label="Emplid", help_text="or type to search")

    class Meta:
        model = Role
        exclude = ("config", "role")

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(NewRoleForm, self).is_valid(*args, **kwargs)

    def clean(self):
        data = self.cleaned_data
        person = data['person']
        unit = data['unit']
        if Role.objects.filter(person=person, unit=unit, role='FAC').exists():
            raise forms.ValidationError(
                'This person already has a faculty role in that unit.')
        return super(NewRoleForm, self).clean()
Exemplo n.º 12
0
class NewRoleForm(forms.ModelForm):
    person = PersonField(label="Emplid", help_text="or type to search")

    class Meta:
        model = Role
        exclude = ("config", "role")

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(NewRoleForm, self).is_valid(*args, **kwargs)

    def clean(self):
        data = self.cleaned_data
        person = data['person']
        unit = data['unit']
        self.old_role = None
        existing = Role.objects.filter(person=person, unit=unit, role='FAC')
        if existing.exists():
            self.old_role = existing[0]
        return super(NewRoleForm, self).clean()
Exemplo n.º 13
0
class AssetChangeForm(forms.ModelForm):
    person = PersonField()

    def __init__(self, request, *args, **kwargs):
        super(AssetChangeForm, self).__init__(*args, **kwargs)
        #  The following two lines look stupid, but they are not.  request.units contains a set of units.
        #  in order to be used this way, we need an actual queryset.
        #
        #  In this case, we also include subunits.  If you manage assets for a parent unit, chances are you may be
        #  adding/removing them for events in your children units.
        unit_ids = [unit.id for unit in Unit.sub_units(request.units)]
        units = Unit.objects.filter(id__in=unit_ids)

    class Meta:
        model = AssetChangeRecord
        widgets = {'date': CalendarWidget}
        fields = ['person', 'qty', 'date']

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(AssetChangeForm, self).is_valid(*args, **kwargs)
Exemplo n.º 14
0
class AdminAssignSheetForm(_AdminAssignForm):
    sheet = _FormModelChoiceField(required=True,
                                  queryset=Sheet.objects.none(),
                                  empty_label=None)
    assignee = PersonField(label='Assign to', required=True, needs_email=True)
    comment = forms.CharField(
        required=False,
        widget=forms.Textarea(attrs={
            'rows': '3',
            'cols': '70'
        }),
        help_text=
        "Optional comment on the form: this becomes part of the form history. If you have additional info about this submission, you can record it here."
    )
    note = forms.CharField(required=False,
                           widget=forms.Textarea(attrs={
                               'rows': '3',
                               'cols': '70'
                           }),
                           help_text="Optional private note to the assignee")

    def __init__(self, query_set, *args, **kwargs):
        super(_AdminAssignForm, self).__init__(*args, **kwargs)
        self.fields['sheet'].queryset = query_set
Exemplo n.º 15
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(SessionalContractForm, self).is_valid(*args, **kwargs)
Exemplo n.º 16
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(NewRoleForm, self).is_valid(*args, **kwargs)
Exemplo n.º 17
0
class PositionPersonForm(forms.Form):
    person = PersonField(label="Emplid", help_text="or type to search")

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(PositionPersonForm, self).is_valid(*args, **kwargs)
Exemplo n.º 18
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(PositionPersonForm, self).is_valid(*args, **kwargs)
Exemplo n.º 19
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(AssetChangeForm, self).is_valid(*args, **kwargs)
Exemplo n.º 20
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(AssetChangeForm, self).is_valid(*args, **kwargs)
Exemplo n.º 21
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(BookingRecordForm, self).is_valid(*args, **kwargs)
Exemplo n.º 22
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(SessionalContractForm, self).is_valid(*args, **kwargs)
Exemplo n.º 23
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(NewRoleForm, self).is_valid(*args, **kwargs)
Exemplo n.º 24
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(BookingRecordForm, self).is_valid(*args, **kwargs)
Exemplo n.º 25
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(RARequestForm, self).is_valid(*args, **kwargs)
Exemplo n.º 26
0
class RARequestForm(forms.ModelForm):
    person = PersonField(label='Appointee')
    supervisor = PersonField(label='Supervisor')

    ra_duties_ex = forms.MultipleChoiceField(
        required=False,
        choices=DUTIES_CHOICES_EX,
        widget=forms.CheckboxSelectMultiple,
        label="Experimental/Research Activities")
    ra_duties_dc = forms.MultipleChoiceField(
        required=False,
        choices=DUTIES_CHOICES_DC,
        widget=forms.CheckboxSelectMultiple,
        label="Data Collection/Analysis")
    ra_duties_pd = forms.MultipleChoiceField(
        required=False,
        choices=DUTIES_CHOICES_PD,
        widget=forms.CheckboxSelectMultiple,
        label="Project Development")
    ra_duties_im = forms.MultipleChoiceField(
        required=False,
        choices=DUTIES_CHOICES_IM,
        widget=forms.CheckboxSelectMultiple,
        label="Information Management")
    ra_duties_eq = forms.MultipleChoiceField(
        required=False,
        choices=DUTIES_CHOICES_EQ,
        widget=forms.CheckboxSelectMultiple,
        label="Equipment/Inventory Management and Development")
    ra_duties_su = forms.MultipleChoiceField(
        required=False,
        choices=DUTIES_CHOICES_SU,
        widget=forms.CheckboxSelectMultiple,
        label="Supervision")
    ra_duties_wr = forms.MultipleChoiceField(
        required=False,
        choices=DUTIES_CHOICES_WR,
        widget=forms.CheckboxSelectMultiple,
        label="Writing/Reporting")
    ra_duties_pm = forms.MultipleChoiceField(
        required=False,
        choices=DUTIES_CHOICES_PM,
        widget=forms.CheckboxSelectMultiple,
        label="Project Management")

    people_comments = forms.CharField(
        required=False,
        widget=forms.Textarea(attrs={'rows': 3}),
        label="Any comments about the Appointee or Hiring Supervisor?")

    student = forms.ChoiceField(required=True,
                                choices=STUDENT_TYPE,
                                widget=forms.RadioSelect,
                                label="Is the appointee a student?")
    coop = forms.ChoiceField(required=False,
                             widget=forms.RadioSelect,
                             choices=BOOL_CHOICES,
                             label="Is the appointee a co-op student?")
    mitacs = forms.ChoiceField(
        required=False,
        widget=forms.RadioSelect,
        choices=BOOL_CHOICES,
        label=
        "Is the appointee's co-op funded by a Mitacs scholarship in their own name?"
    )
    thesis = forms.ChoiceField(
        required=False,
        widget=forms.RadioSelect,
        choices=BOOL_CHOICES,
        label="Is the appointment for the student's thesis/project?")

    fs1_unit = forms.IntegerField(
        required=True,
        label="Department #1",
        help_text=
        "CS = 2110; ENSC = 2130; MSE = 2140; SEE = 2150; Dean's Office = 2010, 2020 or 2030"
    )
    fs1_fund = forms.IntegerField(required=True,
                                  label="Fund #1",
                                  help_text="Example: 11, 13, 21, 31")
    fs1_project = forms.CharField(
        required=True,
        label="Project #1",
        help_text=
        "Example: N654321, S654321, X654321, R654321. If fund 11 enter X000000"
    )
    fs1_percentage = forms.IntegerField(
        required=False,
        label="Percentage of Funding Source #1 to Total Funding",
        help_text="Percentages of all funding sources must add up to 100.")

    fs2_option = forms.BooleanField(
        required=False,
        label=
        "Please select the following if there is an additional funding source")
    fs2_unit = forms.IntegerField(
        required=False,
        label="Department #2",
        help_text=
        "CS = 2110; ENSC = 2130; MSE = 2140; SEE = 2150; Dean's Office = 2010, 2020 or 2030"
    )
    fs2_fund = forms.IntegerField(required=False,
                                  label="Fund #2",
                                  help_text="Example: 11, 13, 21, 31")
    fs2_project = forms.CharField(
        required=False,
        label="Project #2",
        help_text=
        "Example: N654321, S654321, X654321, R654321. If fund 11 enter X000000"
    )
    fs2_percentage = forms.IntegerField(
        required=False,
        label="Percentage of Funding Source #2 to Total Funding",
        help_text="Percentages of all funding sources must add up to 100.")

    fs3_option = forms.BooleanField(
        required=False,
        label=
        "Please select the following if there is an additional funding source")
    fs3_unit = forms.IntegerField(
        required=False,
        label="Department #3",
        help_text=
        "CS = 2110; ENSC = 2130; MSE = 2140; SEE = 2150; Dean's Office = 2010, 2020 or 2030"
    )
    fs3_fund = forms.IntegerField(required=False,
                                  label="Fund #3",
                                  help_text="Example: 11, 13, 21, 31")
    fs3_project = forms.CharField(
        required=False,
        label="Percentage #3",
        help_text=
        "Example: N654321, S654321, X654321, R654321. If fund 11 enter X000000"
    )
    fs3_percentage = forms.IntegerField(
        required=False,
        label="Percentage of Funding Source #3 to Total Funding",
        help_text="Percentages of all funding sources must add up to 100.")

    gras_payment_method = forms.ChoiceField(
        required=False,
        choices=GRAS_PAYMENT_METHOD_CHOICES,
        widget=forms.RadioSelect,
        label="Scholarship (No added benefit & vacation cost)",
        help_text=
        'Canadian bank status impacts how students will be paid. This generally applies to International'
        +
        'students currently working outside of Canada, who do not have banking status in Canada. If the status is'
        + 'unknown please confirm with the student.')
    ra_payment_method = forms.ChoiceField(
        required=False,
        choices=RA_PAYMENT_METHOD_CHOICES,
        widget=forms.RadioSelect,
        label="Please select from the following")

    rabw_total_gross = forms.DecimalField(required=False,
                                          label="Total Gross Salary Paid")
    rabw_weeks_vacation = forms.DecimalField(
        required=False, label="Weeks Vacation (Minimum 2)")
    rabw_biweekly_hours = forms.DecimalField(required=False,
                                             label="Bi-Weekly Hours")
    rabw_biweekly_salary = forms.DecimalField(required=False,
                                              widget=forms.HiddenInput)
    rabw_gross_hourly = forms.DecimalField(required=False,
                                           widget=forms.HiddenInput)

    rah_gross_hourly = forms.DecimalField(required=False, label="Gross Hourly")
    rah_vacation_pay = forms.DecimalField(required=False,
                                          label="Vacation Pay % (Minimum 4%)")
    rah_biweekly_hours = forms.DecimalField(required=False,
                                            label="Bi-Weekly Hours")

    grasls_total_gross = forms.DecimalField(required=False,
                                            label="Total Gross Salary Paid")

    grasbw_total_gross = forms.DecimalField(required=False,
                                            label="Total Gross Salary Paid")
    grasbw_biweekly_hours = forms.DecimalField(required=False,
                                               label="Bi-Weekly Hours")
    grasbw_biweekly_salary = forms.DecimalField(required=False,
                                                widget=forms.HiddenInput)
    grasbw_gross_hourly = forms.DecimalField(required=False,
                                             widget=forms.HiddenInput)

    ra_benefits = forms.ChoiceField(
        required=False,
        choices=RA_BENEFITS_CHOICES,
        widget=forms.RadioSelect,
        label="Are you willing to provide extended health benefits?")

    funding_comments = forms.CharField(
        required=False,
        widget=forms.Textarea(attrs={'rows': 3}),
        label="Any comments about funding?")
    ra_other_duties = forms.CharField(required=False,
                                      widget=forms.Textarea(attrs={'rows': 3}),
                                      label="Other RA Duties")

    class Meta:
        model = RARequest
        exclude = (
            'config',
            'deleted',
            'status',
        )
        labels = {
            'first_name': "Appointee First Name",
            'last_name': "Appointee Last Name",
            'email_address': "Appointee Email Address",
            'nonstudent': "Select if appointee does not have an ID",
            'department': "Appointee Department",
            'start_date': "Date Appointment Begins",
            'end_date': "Date Appointment Ends",
            'file_attachment_1': "Supplementary Document #1",
            'file_attachment_2': "Supplementary Document #2",
        }

        widgets = {
            'hiring_category': forms.HiddenInput(),
            'total_pay': forms.HiddenInput()
        }

        help_texts = {
            'file_attachment_1':
            "Both of these fields are optional.",
            'file_attachment_2':
            "If co-op appointment, please upload co-op forms.",
        }

    def __init__(self, *args, **kwargs):
        super(RARequestForm, self).__init__(*args, **kwargs)
        not_required = [
            'person', 'nonstudent', 'first_name', 'last_name', 'email_address',
            'file_attachment_1', 'file_attachment_2', 'ra_duties_ex',
            'ra_duties_dc', 'ra_duties_pd', 'ra_duties_im', 'ra_duties_eq',
            'ra_duties_su', 'ra_duties_wr', 'ra_duties_pm', 'ra_other_duties'
        ]
        for field in not_required:
            self.fields[field].required = False

        config_init = [
            'people_comments', 'coop', 'mitacs', 'student', 'thesis',
            'fs1_unit', 'fs1_fund', 'fs1_project', 'fs1_percentage',
            'fs2_option', 'fs2_unit', 'fs2_fund', 'fs2_project',
            'fs2_percentage', 'fs3_option', 'fs3_unit', 'fs3_fund',
            'fs3_project', 'fs3_percentage', 'rabw_total_gross',
            'rabw_weeks_vacation', 'rabw_biweekly_salary', 'rabw_gross_hourly',
            'rabw_biweekly_hours', 'rah_gross_hourly', 'rah_vacation_pay',
            'rah_biweekly_hours', 'grasls_total_gross', 'grasbw_total_gross',
            'grasbw_total_gross', 'grasbw_biweekly_hours',
            'grasbw_biweekly_salary', 'ra_payment_method',
            'gras_payment_method', 'ra_benefits', 'funding_comments',
            'ra_other_duties'
        ]

        for field in config_init:
            self.initial[field] = getattr(self.instance, field)

    def is_valid(self, *args, **kwargs):
        PersonField.person_data_prep(self)
        return super(RARequestForm, self).is_valid(*args, **kwargs)

    # TODO: Make sure total pay and hiring category are calculated properly. Javascript only for now.
    def clean(self):
        cleaned_data = super().clean()

        config_clean = [
            'people_comments', 'coop', 'mitacs', 'student', 'thesis',
            'fs1_unit', 'fs1_fund', 'fs1_project', 'fs1_percentage',
            'fs2_option', 'fs2_unit', 'fs2_fund', 'fs2_project',
            'fs2_percentage', 'fs3_option', 'fs3_unit', 'fs3_fund',
            'fs3_project', 'fs3_percentage', 'rabw_total_gross',
            'rabw_weeks_vacation', 'rabw_biweekly_salary', 'rabw_gross_hourly',
            'rabw_biweekly_hours', 'rah_gross_hourly', 'rah_vacation_pay',
            'rah_biweekly_hours', 'grasls_total_gross', 'grasbw_total_gross',
            'grasbw_total_gross', 'grasbw_biweekly_hours',
            'grasbw_biweekly_salary', 'ra_payment_method',
            'gras_payment_method', 'ra_benefits', 'funding_comments',
            'ra_other_duties'
        ]

        for field in config_clean:
            setattr(self.instance, field, cleaned_data[field])

        total_pay = cleaned_data.get('total_pay')
        #print(total_pay)

        nonstudent = cleaned_data.get('nonstudent')
        first_name = cleaned_data.get('first_name')
        last_name = cleaned_data.get('last_name')
        email_address = cleaned_data.get('email_address')
        person = cleaned_data.get('person')

        # TODO: Why isn't this a required field regularly? Not in the list of non-required fields.
        if nonstudent:
            error_message = 'If the appointee does not have an SFU ID then you must answer this question.'
            if first_name == None:
                self.add_error('first_name', error_message)
            if last_name == None:
                self.add_error('last_name', error_message)
            if email_address == None:
                self.add_error('email_address', error_message)
        else:
            if person == None:
                self.add_error(
                    'person',
                    'You must provide an SFU ID. If the appointee does not have an SFU ID, please select the checkbox below.'
                )

        if nonstudent == None and person == None:
            raise forms.ValidationError(
                "Cannot be a student and not have an SFU ID.")

        student = cleaned_data.get('student')
        coop = cleaned_data.get('coop')
        mitacs = cleaned_data.get('mitacs')
        thesis = cleaned_data.get('thesis')
        if student == 'U' or student == 'M' or student == 'P':
            error_message = 'If the appointee is a student then you must answer this question.'
            if coop == None:
                self.add_error('coop', error_message)
            if mitacs == None:
                self.add_error('mitacs', error_message)
        if mitacs == False:
            if thesis == None:
                self.add_error('thesis', 'You must answer this question.')

        fs2_option = cleaned_data.get('fs2_option')
        fs2_unit = cleaned_data.get('fs2_unit')
        fs2_fund = cleaned_data.get('fs2_fund')
        fs2_project = cleaned_data.get('fs2_project')

        if fs2_option:
            error_message = 'If you have a second funding source then you must answer this question.'
            if fs2_unit == None:
                self.add_error('fs2_unit', error_message)
            if fs2_fund == None:
                self.add_error('fs2_fund', error_message)
            if fs2_project == None:
                self.add_error('fs2_project', error_message)

        fs3_option = cleaned_data.get('fs3_option')
        fs3_unit = cleaned_data.get('fs3_unit')
        fs3_fund = cleaned_data.get('fs3_fund')
        fs3_project = cleaned_data.get('fs3_project')

        if fs3_option:
            error_message = 'If you have a third funding source then you must answer this question.'
            if fs3_unit == None:
                self.add_error('fs3_unit', error_message)
            if fs3_fund == None:
                self.add_error('fs3_fund', error_message)
            if fs3_project == None:
                self.add_error('fs3_project', error_message)

        gras_payment_method = cleaned_data.get('gras_payment_method')
        ra_payment_method = cleaned_data.get('ra_payment_method')
        grasbw_biweekly_hours = cleaned_data.get('grasbw_biweekly_hours')
        grasls_total_gross = cleaned_data.get('grasls_total_gross')

        if gras_payment_method:
            error_message = "Graduate Research Assistants must answer this question."
            if gras_payment_method == "LS" or gras_payment_method == "LE":
                if grasls_total_gross == 0 or grasls_total_gross == None:
                    self.add_error('grasls_total_gross', error_message)
            if gras_payment_method == "BW":
                if grasbw_biweekly_hours == 0 or grasbw_biweekly_hours == None:
                    self.add_error('grasbw_biweekly_hours', error_message)
            if ra_payment_method:
                raise forms.ValidationError("Cannot be both an RA and a GRAS.")

        #total_pay = cleaned_data.get('total_pay')
        #if total_pay == 0 or total_pay == None:
        #    raise forms.ValidationError("Total pay must be calculated.")

        start_date = cleaned_data.get('start_date')
        end_date = cleaned_data.get('end_date')
        if end_date < start_date:
            error_message = "Start date must be before end date."
            self.add_error('end_date', error_message)
            self.add_error('start_date', error_message)
Exemplo n.º 27
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(EmployeeSearchForm, self).is_valid(*args, **kwargs)
Exemplo n.º 28
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(_AdminAssignForm, self).is_valid(*args, **kwargs)
Exemplo n.º 29
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(EmployeeSearchForm, self).is_valid(*args, **kwargs)
Exemplo n.º 30
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(_AdminAssignForm, self).is_valid(*args, **kwargs)
Exemplo n.º 31
0
 def is_valid(self, *args, **kwargs):
     PersonField.person_data_prep(self)
     return super(PositionPersonForm, self).is_valid(*args, **kwargs)