def manage_supervisors(request, grad_slug): grad = get_object_or_404(GradStudent, slug=grad_slug, program__unit__in=request.units) supervisors = Supervisor.objects.filter(student=grad).select_related('supervisor') supervisor_people = [s.supervisor for s in supervisors if s.supervisor] if request.method == 'POST': form = SupervisorForm(request.POST) form.set_supervisor_choices(possible_supervisors([grad.program.unit], extras=supervisor_people, null=True)) if form.is_valid(): s = form.save(commit=False) s.modified_by = request.user.username s.student = grad s.save() messages.success(request, "Added committee member for %s." % (grad)) l = LogEntry(userid=request.user.username, description="Added committee member %s for %s." % (s, grad.person.userid), related_object=s) l.save() return HttpResponseRedirect(reverse('grad:manage_supervisors', kwargs={'grad_slug':grad_slug})) else: form = SupervisorForm() form.set_supervisor_choices(possible_supervisors([grad.program.unit], extras=supervisor_people, null=True)) context = { 'form': form, 'supervisors': supervisors, 'grad': grad, 'can_edit': True, } return render(request, 'grad/manage_supervisors.html', context)
def browse(request): units = request.units hiring_choices = [('all', 'All')] + possible_supervisors(units) project_choices = [('all', 'All')] + [ (p.id, unicode(p)) for p in Project.objects.filter(unit__in=units, hidden=False) ] account_choices = [('all', 'All')] + [ (a.id, unicode(a)) for a in Account.objects.filter(unit__in=units, hidden=False) ] if 'data' in request.GET: # AJAX query for data ras = RAAppointment.objects.filter(unit__in=units, deleted=False) \ .select_related('person', 'hiring_faculty', 'project', 'account') if 'hiring_faculty' in request.GET and request.GET[ 'hiring_faculty'] != 'all': ras = ras.filter(hiring_faculty__id=request.GET['hiring_faculty']) if 'project' in request.GET and request.GET['project'] != 'all': ras = ras.filter(project__id=request.GET['project'], project__unit__in=units) if 'account' in request.GET and request.GET['account'] != 'all': ras = ras.filter(account__id=request.GET['account'], account__unit__in=units) truncated = False if ras.count() > 200: ras = ras[:200] truncated = True data = [] for ra in ras: radata = { 'slug': ra.slug, 'name': ra.person.sortname(), 'hiring': ra.hiring_faculty.sortname(), 'project': unicode(ra.project), 'project_hidden': ra.project.hidden, 'account': unicode(ra.account), 'account_hidden': ra.account.hidden, 'start': datefilter(ra.start_date, settings.GRAD_DATE_FORMAT), 'end': datefilter(ra.end_date, settings.GRAD_DATE_FORMAT), 'amount': '$' + unicode(ra.lump_sum_pay), } data.append(radata) response = HttpResponse(content_type="application/json") json.dump({'truncated': truncated, 'data': data}, response, indent=1) return response else: # request for page form = RABrowseForm() form.fields['hiring_faculty'].choices = hiring_choices form.fields['account'].choices = account_choices form.fields['project'].choices = project_choices context = {'form': form} return render(request, 'ra/browse.html', context)
def manage_supervisors(request, grad_slug): grad = get_object_or_404(GradStudent, slug=grad_slug, program__unit__in=request.units) supervisors = Supervisor.objects.filter( student=grad).select_related('supervisor') supervisor_people = [s.supervisor for s in supervisors if s.supervisor] if request.method == 'POST': form = SupervisorForm(request.POST) form.set_supervisor_choices( possible_supervisors([grad.program.unit], extras=supervisor_people, null=True)) if form.is_valid(): s = form.save(commit=False) s.modified_by = request.user.username s.student = grad s.save() messages.success(request, "Added committee member for %s." % (grad)) l = LogEntry(userid=request.user.username, description="Added committee member %s for %s." % (s, grad.person.userid), related_object=s) l.save() return HttpResponseRedirect( reverse('grad:manage_supervisors', kwargs={'grad_slug': grad_slug})) else: form = SupervisorForm() form.set_supervisor_choices( possible_supervisors([grad.program.unit], extras=supervisor_people, null=True)) context = { 'form': form, 'supervisors': supervisors, 'grad': grad, 'can_edit': True, } return render(request, 'grad/manage_supervisors.html', context)
def _appointment_defaults(units, emplid=None): hiring_faculty_choices = possible_supervisors(units) unit_choices = [(u.id, u.name) for u in units] project_choices = [(p.id, unicode(p)) for p in Project.objects.filter(unit__in=units, hidden=False)] account_choices = [(a.id, unicode(a)) for a in Account.objects.filter(unit__in=units, hidden=False)] scholarship_choices = [("", u'\u2014')] if emplid: for s in Scholarship.objects.filter(student__person__emplid=emplid): scholarship_choices.append((s.pk, s.scholarship_type.unit.label + ": " + s.scholarship_type.name + " (" + s.start_semester.name + " to " + s.end_semester.name + ")")) return (scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices)
def _appointment_defaults(units, emplid=None): hiring_faculty_choices = possible_supervisors(units) unit_choices = [(u.id, u.name) for u in units] project_choices = [(p.id, unicode(p)) for p in Project.objects.filter(unit__in=units, hidden=False)] account_choices = [(a.id, unicode(a)) for a in Account.objects.filter(unit__in=units, hidden=False)] scholarship_choices = [("", u'\u2014')] if emplid: for s in Scholarship.objects.filter(student__person__emplid=emplid): scholarship_choices.append((s.pk, s.scholarship_type.unit.label + ": " + s.scholarship_type.name + " (" + s.start_semester.name + " to " + s.end_semester.name + ")")) return (scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices)
def browse(request): units = Unit.sub_units(request.units) hiring_choices = [('all', 'All')] + possible_supervisors(units) project_choices = [('all', 'All')] + [(p.id, unicode(p)) for p in Project.objects.filter(unit__in=units, hidden=False)] account_choices = [('all', 'All')] + [(a.id, unicode(a)) for a in Account.objects.filter(unit__in=units, hidden=False)] if 'data' in request.GET: # AJAX query for data ras = RAAppointment.objects.filter(unit__in=units, deleted=False) \ .select_related('person', 'hiring_faculty', 'project', 'account') if 'hiring_faculty' in request.GET and request.GET['hiring_faculty'] != 'all': ras = ras.filter(hiring_faculty__id=request.GET['hiring_faculty']) if 'project' in request.GET and request.GET['project'] != 'all': ras = ras.filter(project__id=request.GET['project'], project__unit__in=units) if 'account' in request.GET and request.GET['account'] != 'all': ras = ras.filter(account__id=request.GET['account'], account__unit__in=units) truncated = False if ras.count() > 200: ras = ras[:200] truncated = True data = [] for ra in ras: radata = { 'slug': ra.slug, 'name': ra.person.sortname(), 'hiring': ra.hiring_faculty.sortname(), 'project': unicode(ra.project), 'project_hidden': ra.project.hidden, 'account': unicode(ra.account), 'account_hidden': ra.account.hidden, 'start': datefilter(ra.start_date, settings.GRAD_DATE_FORMAT), 'end': datefilter(ra.end_date, settings.GRAD_DATE_FORMAT), 'amount': '$'+unicode(ra.lump_sum_pay), } data.append(radata) response = HttpResponse(content_type="application/json") json.dump({'truncated': truncated, 'data': data}, response, indent=1) return response else: # request for page form = RABrowseForm() form.fields['hiring_faculty'].choices = hiring_choices form.fields['account'].choices = account_choices form.fields['project'].choices = project_choices context = { 'form': form } return render(request, 'ra/browse.html', context)
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 })
def reappoint(request, ra_slug): appointment = get_object_or_404(RAAppointment, slug=ra_slug, deleted=False) 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 })
def manage_defence(request, grad_slug): """ Page for managing all defence-related stuff. Slightly complicated since this info cuts across several models. """ grad = get_object_or_404(GradStudent, slug=grad_slug, program__unit__in=request.units) supervisors = Supervisor.objects.filter( student=grad).select_related('supervisor') supervisor_people = [s.supervisor for s in supervisors if s.supervisor] supervisor_choices = possible_supervisors(units=request.units, extras=supervisor_people, null=True) if request.method == 'POST': form = GradDefenceForm(request.POST) form.set_supervisor_choices(supervisor_choices) if form.is_valid(): with transaction.atomic(): grad.config['thesis_type'] = form.cleaned_data['thesis_type'] grad.config['work_title'] = form.cleaned_data['work_title'] grad.config['exam_date'] = form.cleaned_data['exam_date'] grad.config['thesis_outcome'] = form.cleaned_data[ 'thesis_outcome'] grad.config['thesis_location'] = form.cleaned_data[ 'thesis_location'] grad.save() if form.cleaned_data['internal']: p = form.cleaned_data['internal'] # remove any old ones remove_sup = Supervisor.objects.filter( student=grad, removed=False, supervisor_type='SFU').exclude(supervisor=p) for sup in remove_sup: sup.removed = True sup.save() existing_sup = Supervisor.objects.filter( student=grad, removed=False, supervisor_type='SFU', supervisor=p) if not existing_sup: # doesn't exist: create sup = Supervisor(student=grad, supervisor_type='SFU', supervisor=p) sup.save() # else: already there, so nothing to change if form.cleaned_data['chair']: p = form.cleaned_data['chair'] # remove any old ones remove_sup = Supervisor.objects.filter( student=grad, removed=False, supervisor_type='CHA').exclude(supervisor=p) for sup in remove_sup: sup.removed = True sup.save() existing_sup = Supervisor.objects.filter( student=grad, removed=False, supervisor_type='CHA', supervisor=p) if not existing_sup: # doesn't exist: create sup = Supervisor(student=grad, supervisor_type='CHA', supervisor=p) sup.save() # else: already there, so nothing to change if form.cleaned_data['external']: name = form.cleaned_data['external'] # remove any old ones remove_sup = Supervisor.objects.filter( student=grad, removed=False, supervisor_type='EXT').exclude(external=name) for sup in remove_sup: sup.removed = True sup.save() # creqate/update existing_sup = Supervisor.objects.filter( student=grad, removed=False, supervisor_type='EXT', external=name) if existing_sup: sup = existing_sup[0] else: sup = Supervisor(student=grad, supervisor_type='EXT', external=name) sup.config['email'] = form.cleaned_data['external_email'] sup.config['contact'] = form.cleaned_data[ 'external_contact'] sup.config['attend'] = form.cleaned_data['external_attend'] sup.save() messages.success(request, "Updated defence info for %s." % (grad.person)) l = LogEntry(userid=request.user.username, description="Updated grad defence info for %s." % (grad), related_object=grad) l.save() return HttpResponseRedirect( reverse('grad.views.view', kwargs={'grad_slug': grad.slug})) else: initial = {} if 'thesis_type' in grad.config: initial['thesis_type'] = grad.config['thesis_type'] if 'work_title' in grad.config: initial['work_title'] = grad.config['work_title'] if 'exam_date' in grad.config: initial['exam_date'] = grad.config['exam_date'] if 'thesis_outcome' in grad.config: initial['thesis_outcome'] = grad.config['thesis_outcome'] if 'thesis_location' in grad.config: initial['thesis_location'] = grad.config['thesis_location'] internals = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='SFU') if internals: initial['internal'] = internals[0].supervisor_id chairs = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='CHA') if chairs: initial['chair'] = chairs[0].supervisor_id externals = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='EXT') if externals: ext = externals[0] initial['external'] = ext.external initial['external_email'] = ext.config.get('email', '') initial['external_contact'] = ext.config.get('contact', '') initial['external_attend'] = ext.config.get('attend', '') form = GradDefenceForm(initial=initial) form.set_supervisor_choices(supervisor_choices) context = { 'form': form, 'grad': grad, } return render(request, 'grad/manage_defence.html', context)
def manage_defence(request, grad_slug): """ Page for managing all defence-related stuff. Slightly complicated since this info cuts across several models. """ grad = get_object_or_404(GradStudent, slug=grad_slug, program__unit__in=request.units) supervisors = Supervisor.objects.filter(student=grad).select_related('supervisor') supervisor_people = [s.supervisor for s in supervisors if s.supervisor] supervisor_choices = possible_supervisors(units=request.units, extras=supervisor_people, null=True) if request.method == 'POST': form = GradDefenceForm(request.POST) form.set_supervisor_choices(supervisor_choices) if form.is_valid(): with transaction.atomic(): grad.config['thesis_type'] = form.cleaned_data['thesis_type'] grad.config['work_title'] = form.cleaned_data['work_title'] grad.config['exam_date'] = form.cleaned_data['exam_date'] grad.config['thesis_outcome'] = form.cleaned_data['thesis_outcome'] grad.config['thesis_location'] = form.cleaned_data['thesis_location'] grad.save() if form.cleaned_data['internal']: p = form.cleaned_data['internal'] # remove any old ones remove_sup = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='SFU').exclude(supervisor=p) for sup in remove_sup: sup.removed = True sup.save() existing_sup = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='SFU', supervisor=p) if not existing_sup: # doesn't exist: create sup = Supervisor(student=grad, supervisor_type='SFU', supervisor=p) sup.save() # else: already there, so nothing to change if form.cleaned_data['chair']: p = form.cleaned_data['chair'] # remove any old ones remove_sup = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='CHA').exclude(supervisor=p) for sup in remove_sup: sup.removed = True sup.save() existing_sup = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='CHA', supervisor=p) if not existing_sup: # doesn't exist: create sup = Supervisor(student=grad, supervisor_type='CHA', supervisor=p) sup.save() # else: already there, so nothing to change if form.cleaned_data['external']: name = form.cleaned_data['external'] # remove any old ones remove_sup = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='EXT').exclude(external=name) for sup in remove_sup: sup.removed = True sup.save() # creqate/update existing_sup = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='EXT', external=name) if existing_sup: sup = existing_sup[0] else: sup = Supervisor(student=grad, supervisor_type='EXT', external=name) sup.config['email'] = form.cleaned_data['external_email'] sup.config['contact'] = form.cleaned_data['external_contact'] sup.config['attend'] = form.cleaned_data['external_attend'] sup.save() messages.success(request, "Updated defence info for %s." % (grad.person)) l = LogEntry(userid=request.user.username, description="Updated grad defence info for %s." % (grad), related_object=grad) l.save() return HttpResponseRedirect(reverse('grad.views.view', kwargs={'grad_slug':grad.slug})) else: initial = {} if 'thesis_type' in grad.config: initial['thesis_type'] = grad.config['thesis_type'] if 'work_title' in grad.config: initial['work_title'] = grad.config['work_title'] if 'exam_date' in grad.config: initial['exam_date'] = grad.config['exam_date'] if 'thesis_outcome' in grad.config: initial['thesis_outcome'] = grad.config['thesis_outcome'] if 'thesis_location' in grad.config: initial['thesis_location'] = grad.config['thesis_location'] internals = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='SFU') if internals: initial['internal'] = internals[0].supervisor_id chairs = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='CHA') if chairs: initial['chair'] = chairs[0].supervisor_id externals = Supervisor.objects.filter(student=grad, removed=False, supervisor_type='EXT') if externals: ext = externals[0] initial['external'] = ext.external initial['external_email'] = ext.config.get('email', '') initial['external_contact'] = ext.config.get('contact', '') initial['external_attend'] = ext.config.get('attend', '') form = GradDefenceForm(initial=initial) form.set_supervisor_choices(supervisor_choices) context = { 'form': form, 'grad': grad, } return render(request, 'grad/manage_defence.html', context)