def create_application(request): ''' This view function will be used to create a new ethics application. Login is required as the principle investigator for the new application will be set as the logged in user that is creating it. All valid users of the system should be able to create ethics applications. ''' if request.method == 'POST': form = EthicsApplicationForm(request.POST) if (form.is_valid()): new_application = form.instance new_application.principle_investigator = request.user new_application.save() return HttpResponseRedirect( reverse('application_view', kwargs={'application_id': new_application.id})) else: form = EthicsApplicationForm() return render_to_response('ethicsapplication/create.html', {'form': form}, context_instance=RequestContext(request))
def create_application(request): ''' This view function will be used to create a new ethics application. Login is required as the principle investigator for the new application will be set as the logged in user that is creating it. All valid users of the system should be able to create ethics applications. ''' if request.method == 'POST': form = EthicsApplicationForm(request.POST) if (form.is_valid()): new_application = form.instance new_application.principle_investigator = request.user new_application.save() return HttpResponseRedirect(reverse('application_view', kwargs={'application_id':new_application.id})) else: form = EthicsApplicationForm() return render_to_response('ethicsapplication/create.html', {'form':form}, context_instance=RequestContext(request))
def test_EthicsApplication_form_title_must_be_present(self): ''' The form must require a non blank string for the title field. ''' incorrect_data = {'data': {'title': '',}} form = EthicsApplicationForm(incorrect_data) #form.is_valid() #JA - don't think we need this call self.assertFalse(form.is_valid()) self.assertEqual(form.errors['title'], [u'This field is required.'])
def test_EthicsApplication_form_title_must_be_present(self): ''' The form must require a non blank string for the title field. ''' incorrect_data = { 'data': { 'title': '', } } form = EthicsApplicationForm(incorrect_data) #form.is_valid() #JA - don't think we need this call self.assertFalse(form.is_valid()) self.assertEqual(form.errors['title'], [u'This field is required.'])
def test_EthicsApplication_form_title(self): ''' Check that the form provdes a field that cannot be blank for the application title ''' form = EthicsApplicationForm() self.assertTrue('title' in form.fields)
def test_EthicsApplication_form_ignored_fields(self): ''' Check that the form does not display a field for either Principle investigator, nor application nor the active flag. ''' form = EthicsApplicationForm() self.assertFalse('principle_investigator' in form.fields) self.assertFalse('application_form' in form.fields) self.assertFalse('active' in form.fields) self.assertFalse('checklist' in form.fields)