def post_exit_survey(request,student_id): #if the student hasn't had an exit survey performed alert the user try: exit = ExitSurvey.objects.get(student_id=student_id) except ObjectDoesNotExist: return render( request,'mande/errors/noexitsurvey.html', {'student_id':student_id}) #get students current info for pre-filling the survey try: survey = IntakeSurvey.objects.get(pk=student_id) most_recent = survey.getRecentFields() except ObjectDoesNotExist: survey = None most_recent = None if request.method == 'POST': form = PostExitSurveyForm(request.POST) if form.is_valid(): instance = form.save() message = 'Did a post exit survey for '+unicode(instance.student_id.name) log = NotificationLog( user=request.user, text=message, font_awesome_icon='fa-heart') log.save() #then return return HttpResponseRedirect(reverse('post_exit_survey')) else: form = PostExitSurveyForm(most_recent) context = {'form': form,'student_id':student_id } return render(request, 'mande/postexitsurvey.html', context)
def test_PostExitSurveyForm_valid(self): data = { "post_exit_survey_date": "2017-01-01", "student_id": 1, "exit_date": "2017-01-01", "early_exit": "Y", "guardian1_relationship": "FATHER", "guardian1_profession": 1, "guardian1_employment": 1, "minors": 1, "enrolled": "Y", "grade_current": 1, "grade_previous": 1 } form = PostExitSurveyForm(data) self.assertTrue(form.is_valid())
def test_PostExitSurveyForm_invalid(self): data = { "post_exit_survey_date": "2017-01-01", "exit_date": "2017-01-01", "early_exit": "Y", "guardian1_relationship": "FATHER", "guardian1_profession": 1, "guardian1_employment": 1, "minors": 1, "enrolled": "Y", "grade_current": 1, "grade_previous": 1 } form = PostExitSurveyForm(data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'student_id': [u'This field is required.']})
def post_exit_survey(request, student_id): #if the student hasn't had an exit survey performed alert the user try: exit = ExitSurvey.objects.get(student_id=student_id) except ObjectDoesNotExist: return render(request, 'mande/errors/noexitsurvey.html', {'student_id': student_id}) #get students current info for pre-filling the survey try: survey = IntakeSurvey.objects.get(pk=student_id) most_recent = survey.getRecentFields() except ObjectDoesNotExist: survey = None most_recent = None if request.method == 'POST': form = PostExitSurveyForm(request.POST) if form.is_valid(): instance = form.save() message = 'Did a post exit survey for ' + unicode( instance.student_id.name) log = NotificationLog(user=request.user, text=message, font_awesome_icon='fa-heart') log.save() #then return return HttpResponseRedirect(reverse('post_exit_survey')) else: form = PostExitSurveyForm(most_recent) context = {'form': form, 'student_id': student_id} return render(request, 'mande/postexitsurvey.html', context)