def test_IntakeInternalForm_valid(self): data = { "student_id": 1, "enrollment_date": "2017-01-01", "starting_grade": 1 } form = IntakeInternalForm(data) self.assertTrue(form.is_valid())
def intake_internal(request, student_id=0): #get current method name method_name = inspect.currentframe().f_code.co_name if user_permissions(method_name, request.user): if request.method == 'POST': form = IntakeInternalForm(request.POST) if form.is_valid(): instance = form.save() message = ('Enrolled ' + unicode(instance.student_id.name) + ' in ' + instance.get_starting_grade_display()) log = NotificationLog(user=request.user, text=message, font_awesome_icon='fa-user-plus') log.save() #then return return HttpResponseRedirect( reverse( 'student_detail', kwargs={'student_id': instance.student_id.student_id})) else: if student_id > 0: form = IntakeInternalForm({'student_id': student_id}) else: form = IntakeInternalForm() context = { 'form': form, } return render(request, 'mande/intakeinternal.html', context) else: raise PermissionDenied
def intake_internal(request, student_id=0): if request.method == "POST": form = IntakeInternalForm(request.POST) if form.is_valid(): instance = form.save() message = "Enrolled " + unicode(instance.student_id.name) + " in " + instance.get_starting_grade_display() log = NotificationLog(user=request.user, text=message, font_awesome_icon="fa-user-plus") log.save() # then return return HttpResponseRedirect( reverse("student_detail", kwargs={"student_id": instance.student_id.student_id}) ) else: if student_id > 0: form = IntakeInternalForm({"student_id": student_id}) else: form = IntakeInternalForm() context = {"form": form} return render(request, "mande/intakeinternal.html", context)
def intake_internal(request, student_id=0): if request.method == 'POST': form = IntakeInternalForm(request.POST) if form.is_valid(): instance = form.save() message = ( 'Enrolled '+unicode(instance.student_id.name)+ ' in '+instance.get_starting_grade_display()) log = NotificationLog( user=request.user, text=message, font_awesome_icon='fa-user-plus') log.save() #then return return HttpResponseRedirect(reverse('student_detail',kwargs= {'student_id':instance.student_id.student_id})) else: if student_id > 0: form = IntakeInternalForm({'student_id':student_id}) else: form = IntakeInternalForm() context = {'form': form,} return render(request, 'mande/intakeinternal.html', context)
def test_IntakeInternalForm_invalid(self): data = {"enrollment_date": "2017-01-01", "starting_grade": 1} form = IntakeInternalForm(data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'student_id': [u'This field is required.']})