Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
skill_values = []
for s in skills:
try:
val = SkillLevel.objects.get(app=application, skill=s).level
except SkillLevel.DoesNotExist:
val = 'WIL'
if val not in LEVELS:
val = 'NONE'
skill_values.append((s.position, s.name, val))
else:
# new application
search_form = StudentSearchForm()
courses_formset = CoursesFormSet()
for f in courses_formset:
f.fields['course'].choices = course_choices
ta_form = TAApplicationForm(prefix='ta', initial={'sin': sin})
ta_form.add_extra_questions(posting)
campus_preferences = [(lbl, name, 'WIL') for lbl,name in CAMPUS_CHOICES if lbl in used_campuses]
skill_values = [(s.position, s.name, 'NONE') for s in skills]
today = datetime.date.today()
if(posting.closes < today):
messages.warning(request, "The closing date for this posting has passed. Your application will be marked 'late' and may not be considered.")
context = {
'posting':posting,
'manual':manual,
'editing': editing,
'ta_form':ta_form,
'search_form':search_form,
'courses_formset':courses_formset,
'campus_preferences':campus_preferences,
'campus_pref_choices':PREFERENCE_CHOICES,
for c in used_campuses:
val = request.POST.get('campus-'+c, None)
if val not in PREFERENCES:
val = 'WIL'
campus_preferences.append((c, CAMPUSES[c], val))
skill_values = []
for s in skills:
val = request.POST.get('skill-'+str(s.position), None)
if val not in LEVELS:
val = 'NONE'
skill_values.append((s.position, s.name, val))
elif editing:
# editing: build initial form from existing values
ta_form = TAApplicationForm(prefix='ta', instance=application)
# Stupidly, the filefields don't consider themselves "filled" if we have a previous instance that contained
# the right fields anyway. Manually check and clear the required part.
if application.resume:
ta_form.fields['resume'].required = False
if application.transcript:
ta_form.fields['transcript'].required = False
ta_form.add_extra_questions(posting)
cp_init = [{'course': cp.course, 'taken': cp.taken, 'exper':cp.exper} for cp in old_coursepref]
search_form = None
courses_formset = CoursesFormSet(initial=cp_init)
for f in courses_formset:
f.fields['course'].choices = course_choices
# build values for template with entered values
campus_preferences = []
for c in used_campuses:
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():
# No duplicates allowed
courses = []
for (rank,form) in enumerate(courses_formset):
if 'course' in form.cleaned_data and form.cleaned_data['course']:
courses.append( form.cleaned_data['course'] )
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():
# No duplicates allowed
courses = []
for (rank,form) in enumerate(courses_formset):
if 'course' in form.cleaned_data and form.cleaned_data['course']:
courses.append( form.cleaned_data['course'] )
if len(courses) != len(set(courses)):
messages.error(request, "You have selected duplicate courses. Please select 5 different courses. ")
def __init__(self, *args, **kwargs):
super(TAApplicationForm, self).__init__(*args, **kwargs)
self.fields['sin'].help_text = 'Social insurance number (required for receiving payments: if you don\'t have a SIN yet, please enter "000000000".)'
self.fields['sin'].required = True
self.fields['current_program'].required = True
self.fields['resume'].required = True
self.fields['transcript'].required = True