def new_student(request, userid): person = get_object_or_404(Person, find_userid_or_emplid(userid)) semester = Semester.next_starting() semesterconfig = SemesterConfig.get_config(request.units, semester) student = get_object_or_404(Person, find_userid_or_emplid(userid)) initial = { 'person': student.emplid, 'start_date': semesterconfig.start_date(), 'end_date': semesterconfig.end_date(), 'hours': 80 } scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices = _appointment_defaults( request.units, emplid=student.emplid) gss = GradStudent.objects.filter(person=student) if gss: gradstudent = gss[0] initial['sin'] = gradstudent.person.sin() raform = RAForm(initial=initial) raform.fields['person'] = forms.CharField(widget=forms.HiddenInput()) raform.fields['scholarship'].choices = scholarship_choices raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices return render(request, 'ra/new.html', {'raform': raform, 'person': person})
def new(request): scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices =_appointment_defaults(request.units) if request.method == 'POST': data = request.POST.copy() if data['pay_frequency'] == 'L': # force legal values into the non-submitted (and don't-care) fields for lump sum pay data['biweekly_pay'] = 1 data['hourly_pay'] = 1 data['hours'] = 1 data['pay_periods'] = 1 raform = RAForm(data) raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices if raform.is_valid(): userid = raform.cleaned_data['person'].userid_or_emplid() appointment = raform.save(commit=False) appointment.set_use_hourly(raform.cleaned_data['use_hourly']) appointment.save() messages.success(request, 'Created RA Appointment for ' + appointment.person.name()) return HttpResponseRedirect(reverse(student_appointments, kwargs=({'userid': userid}))) else: semester = Semester.next_starting() semesterconfig = SemesterConfig.get_config(request.units, semester) raform = RAForm(initial={'start_date': semesterconfig.start_date(), 'end_date': semesterconfig.end_date(), 'hours': 80 }) raform.fields['scholarship'].choices = scholarship_choices raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices return render(request, 'ra/new.html', { 'raform': raform })
def edit(request, ra_slug): appointment = get_object_or_404(RAAppointment, slug=ra_slug, deleted=False) scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices = _appointment_defaults(request.units, emplid=appointment.person.emplid) if request.method == 'POST': data = request.POST.copy() if data['pay_frequency'] == 'L': # force legal values into the non-submitted (and don't-care) fields for lump sum pay data['biweekly_pay'] = 1 data['hourly_pay'] = 1 data['hours'] = 1 data['pay_periods'] = 1 raform = RAForm(data, instance=appointment) if raform.is_valid(): userid = raform.cleaned_data['person'].userid appointment = raform.save(commit=False) appointment.set_use_hourly(raform.cleaned_data['use_hourly']) appointment.save() messages.success(request, 'Updated RA Appointment for ' + appointment.person.first_name + " " + appointment.person.last_name) return HttpResponseRedirect(reverse(student_appointments, kwargs=({'userid': userid}))) else: #The initial value needs to be the person's emplid in the form. Django defaults to the pk, which is not human readable. raform = RAForm(instance=appointment, initial={'person': appointment.person.emplid, 'use_hourly': appointment.use_hourly()}) #As in the new method, choices are restricted to relevant options. raform.fields['person'] = forms.CharField(widget=forms.HiddenInput()) raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['scholarship'].choices = scholarship_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices return render(request, 'ra/edit.html', { 'raform': raform, 'appointment': appointment, 'person': appointment.person })
def reappoint(request, ra_slug): appointment = get_object_or_404(RAAppointment, slug=ra_slug, deleted=False, unit__in=request.units) semester = Semester.next_starting() semesterconfig = SemesterConfig.get_config(request.units, semester) raform = RAForm(instance=appointment, initial={ 'person': appointment.person.emplid, 'reappointment': True, 'start_date': semesterconfig.start_date(), 'end_date': semesterconfig.end_date(), 'hours': 80, 'use_hourly': appointment.use_hourly() }) scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices, program_choices = \ _appointment_defaults(request.units, emplid=appointment.person.emplid) raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['scholarship'].choices = scholarship_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices raform.fields['program'].choices = program_choices return render(request, 'ra/new.html', { 'raform': raform, 'appointment': appointment })
def edit(request, ra_slug): appointment = get_object_or_404(RAAppointment, slug=ra_slug, deleted=False, unit__in=request.units) scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices = _appointment_defaults(request.units, emplid=appointment.person.emplid) if request.method == 'POST': data = request.POST.copy() if data['pay_frequency'] == 'L': # force legal values into the non-submitted (and don't-care) fields for lump sum pay data['biweekly_pay'] = 1 data['hourly_pay'] = 1 data['hours'] = 1 data['pay_periods'] = 1 raform = RAForm(data, instance=appointment) if raform.is_valid(): userid = raform.cleaned_data['person'].userid appointment = raform.save(commit=False) appointment.set_use_hourly(raform.cleaned_data['use_hourly']) appointment.save() messages.success(request, 'Updated RA Appointment for ' + appointment.person.first_name + " " + appointment.person.last_name) return HttpResponseRedirect(reverse(student_appointments, kwargs=({'userid': userid}))) else: #The initial value needs to be the person's emplid in the form. Django defaults to the pk, which is not human readable. raform = RAForm(instance=appointment, initial={'person': appointment.person.emplid, 'use_hourly': appointment.use_hourly()}) #As in the new method, choices are restricted to relevant options. raform.fields['person'] = forms.CharField(widget=forms.HiddenInput()) raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['scholarship'].choices = scholarship_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices return render(request, 'ra/edit.html', { 'raform': raform, 'appointment': appointment, 'person': appointment.person })
def new_student(request, userid): person = get_object_or_404(Person, find_userid_or_emplid(userid)) semester = Semester.next_starting() semesterconfig = SemesterConfig.get_config(request.units, semester) student = get_object_or_404(Person, find_userid_or_emplid(userid)) initial = {'person': student.emplid, 'start_date': semesterconfig.start_date(), 'end_date': semesterconfig.end_date(), 'hours': 80 } scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices =_appointment_defaults(request.units, emplid=student.emplid) gss = GradStudent.objects.filter(person=student) if gss: gradstudent = gss[0] initial['sin'] = gradstudent.person.sin() raform = RAForm(initial=initial) raform.fields['person'] = forms.CharField(widget=forms.HiddenInput()) raform.fields['scholarship'].choices = scholarship_choices raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices return render(request, 'ra/new.html', { 'raform': raform, 'person': person })
def new(request): scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices = _appointment_defaults(request.units) if request.method == 'POST': data = request.POST.copy() if data['pay_frequency'] == 'L': # force legal values into the non-submitted (and don't-care) fields for lump sum pay data['biweekly_pay'] = 1 data['hourly_pay'] = 1 data['hours'] = 1 data['pay_periods'] = 1 raform = RAForm(data) raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices if raform.is_valid(): userid = raform.cleaned_data['person'].userid_or_emplid() appointment = raform.save(commit=False) appointment.set_use_hourly(raform.cleaned_data['use_hourly']) appointment.save() messages.success(request, 'Created RA Appointment for ' + appointment.person.name()) return HttpResponseRedirect(reverse(student_appointments, kwargs=({'userid': userid}))) else: semester = Semester.next_starting() semesterconfig = SemesterConfig.get_config(request.units, semester) raform = RAForm(initial={'start_date': semesterconfig.start_date(), 'end_date': semesterconfig.end_date(), 'hours': 80 }) raform.fields['scholarship'].choices = scholarship_choices raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices return render(request, 'ra/new.html', { 'raform': raform })
def reappoint(request, ra_slug): appointment = get_object_or_404(RAAppointment, slug=ra_slug, deleted=False, unit__in=request.units) semester = Semester.next_starting() semesterconfig = SemesterConfig.get_config(request.units, semester) raform = RAForm(instance=appointment, initial={'person': appointment.person.emplid, 'reappointment': True, 'start_date': semesterconfig.start_date(), 'end_date': semesterconfig.end_date(), 'hours': 80, 'use_hourly': appointment.use_hourly() }) raform.fields['hiring_faculty'].choices = possible_supervisors(request.units) scholarship_choices = [("", "---------")] for s in Scholarship.objects.filter(student__person__emplid = appointment.person.emplid): scholarship_choices.append((s.pk, s.scholarship_type.unit.label + ": " + s.scholarship_type.name + " (" + s.start_semester.name + " to " + s.end_semester.name + ")")) raform.fields['scholarship'].choices = scholarship_choices raform.fields['unit'].choices = [(u.id, u.name) for u in request.units] raform.fields['project'].choices = [(p.id, unicode(p.project_number)) for p in Project.objects.filter(unit__in=request.units)] raform.fields['account'].choices = [(a.id, u'%s (%s)' % (a.account_number, a.title)) for a in Account.objects.filter(unit__in=request.units)] return render(request, 'ra/new.html', { 'raform': raform, 'appointment': appointment })