Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if person.sin() != person.defaults['sin']:
sin = person.sin()
if request.method == "POST":
search_form = StudentSearchForm(request.POST)
#Try to manually retrieve person
if manual:
try:
person = get_object_or_404(Person, emplid=int(request.POST['search']))
except ValueError:
search_form = StudentSearchForm(request.POST['search'])
messages.error(request, "Invalid emplid %s for person." % (request.POST['search']))
return HttpResponseRedirect(reverse('ta:new_application_manual', args=(post_slug,)))
#Check to see if an application already exists for the person
existing_app = TAApplication.objects.filter(person=person, posting=posting)
if existing_app.count() > 0:
messages.success(request, "%s has already applied for the %s %s posting." % (person, posting.unit, posting.semester))
return HttpResponseRedirect(reverse('ta:view_application', kwargs={'post_slug': existing_app[0].posting.slug, 'userid': existing_app[0].person.userid}))
if editing:
ta_form = TAApplicationForm(request.POST, request.FILES, prefix='ta', instance=application)
else:
ta_form = TAApplicationForm(request.POST, request.FILES, prefix='ta')
ta_form.add_extra_questions(posting)
courses_formset = CoursesFormSet(request.POST)
for f in courses_formset:
f.fields['course'].choices = course_choices
if ta_form.is_valid() and courses_formset.is_valid():
def print_all_applications(request,post_slug):
posting = get_object_or_404(TAPosting, slug=post_slug, unit__in=request.units)
applications = TAApplication.objects.filter(posting=posting).order_by('person')
for application in applications:
application.courses = CoursePreference.objects.filter(app=application).exclude(rank=0).order_by('rank')
application.skills = SkillLevel.objects.filter(app=application).select_related('skill')
application.campuses = CampusPreference.objects.filter(app=application)
application.contracts = TAContract.objects.filter(application=application)
application.previous_experience = TACourse.objects.filter(contract__application__person=application.person) \
.exclude(contract__application=application).select_related('course__semester')
application.grad_programs = GradStudent.objects \
.filter(program__unit__in=request.units, person=application.person)
context = {
'applications': applications,
'posting': posting,
}
return render(request, 'ta/print_all_applications.html', context)
if not manual:
"""
Don't change the person in the case of a TA Admin editing, as we don't want to save this application as the
Admin's, but as the original user's.
"""
if not is_ta_admin:
try:
person = ensure_person_from_userid(request.user.username)
except SIMSProblem:
return HttpError(request, status=503, title="Service Unavailable", error="Currently unable to handle the request.", errormsg="Problem with SIMS connection while trying to find your account info")
if not person:
return NotFoundResponse(request, "Unable to find your computing account in the system: this is likely because your account was recently activated, and it should be fixed tomorrow. If not, email %s." % (help_email(request),))
existing_app = TAApplication.objects.filter(person=person, posting=posting)
if not userid and existing_app.count() > 0:
messages.success(request, "You have already applied for the %s %s posting." % (posting.unit, posting.semester))
return HttpResponseRedirect(reverse('ta:view_application', kwargs={'post_slug': existing_app[0].posting.slug, 'userid': existing_app[0].person.userid}))
if person.sin() != person.defaults['sin']:
sin = person.sin()
if request.method == "POST":
search_form = StudentSearchForm(request.POST)
#Try to manually retrieve person
if manual:
try:
person = get_object_or_404(Person, emplid=int(request.POST['search']))
except ValueError:
search_form = StudentSearchForm(request.POST['search'])
messages.error(request, "Invalid emplid %s for person." % (request.POST['search']))
# generate CSV
filename = str(posting.slug) + '.csv'
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'inline; filename="%s"' % (filename)
csvWriter = csv.writer(response)
#First csv row: all the course names
off = ['Rank', 'Name', 'Categ', 'Program (Reported)', 'Program (System)', 'Status', 'Unit', 'Start Sem', 'BU',
'Campus', 'Assigned Course(s)', 'Assigned BUs'] + [str(o.course) + ' ' + str(o.section) for o in offerings]
csvWriter.writerow(off)
# next row: campuses
off = ['']*12 + [str(CAMPUSES_SHORTENED[o.campus]) for o in offerings]
csvWriter.writerow(off)
apps = TAApplication.objects.filter(posting=posting).order_by('person')
for app in apps:
rank = 'P%d' % app.rank
system_program = ''
startsem = ''
status = ''
unit = ''
# grad program info
gradstudents = GradStudent.get_canonical(app.person, app.posting.semester)
if len(gradstudents) == 1:
gs = gradstudents[0]
system_program = gs.program.label
status = gs.get_current_status_display()
unit = gs.program.unit.label
if gs.start_semester:
startsem = gs.start_semester.name
else:
def new_contract(request, post_slug):
"""
Create a new contract for this person and redirect to edit it.
"""
posting = get_object_or_404(TAPosting, slug=post_slug, unit__in=request.units)
existing = set(c.application_id for c in TAContract.objects.filter(posting=posting).select_related('application'))
queryset = TAApplication.objects.filter(posting=posting).exclude(id__in=existing).order_by('person')
application_choices = [(a.id, a.person.name()) for a in queryset if a not in existing]
if request.method == 'POST':
form = NewTAContractForm(request.POST)
form.fields['application'].choices = application_choices
form.fields['application'].queryset = queryset
if form.is_valid():
app = form.cleaned_data['application']
contract = TAContract(created_by=request.user.username)
contract.first_assign(app, posting)
return HttpResponseRedirect(reverse('ta:edit_contract', kwargs={'post_slug': posting.slug, 'userid': app.person.userid}))
return HttpResponseRedirect(reverse('ta:all_contracts', args=(post_slug,)))
def download_all_applications(request, post_slug):
posting = get_object_or_404(TAPosting, slug=post_slug, unit__in=request.units)
applications = TAApplication.objects.filter(posting=posting)
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'inline; filename="ta_applications-%s-%s.csv"' % \
(posting.semester.name, datetime.datetime.now().strftime('%Y%m%d'))
writer = csv.writer(response)
if applications:
writer.writerow(['Person', 'ID', 'Category', 'Program', 'Assigned BUs', 'Max BUs', 'Ranked', 'Assigned', 'Campus Preferences'])
for a in applications:
writer.writerow([a.person.sortname(), a.person.emplid, a.get_category_display(), a.get_current_program_display(), a.base_units_assigned(),
a.base_units, a.course_pref_display(), a.course_assigned_display(), a.campus_pref_display()])
return response