Esempio n. 1
0
def create_profile(request):
    manager = get_database_manager(request)
    entity_list = get_all_entity_types(manager)
    entity_list = helper.remove_reporter(entity_list)
    project_summary = dict(name='New Project')
    if request.method == 'GET':
        form = ProjectProfile(entity_list=entity_list,initial={'activity_report':'yes'})
        return render_to_response('project/profile.html', {'form': form, 'project': project_summary, 'edit':False},
                                  context_instance=RequestContext(request))

    form = ProjectProfile(data=request.POST, entity_list=entity_list)
    if form.is_valid():
        entity_type=form.cleaned_data['entity_type']
        project = Project(name=form.cleaned_data["name"], goals=form.cleaned_data["goals"],
                          project_type=form.cleaned_data['project_type'], entity_type=entity_type,
                          devices=form.cleaned_data['devices'], activity_report=form.cleaned_data['activity_report'], sender_group=form.cleaned_data['sender_group'])
        form_model = helper.create_questionnaire(post=form.cleaned_data, dbm=manager)
        try:
            pid = project.save(manager)
            qid = form_model.save()
            project.qid = qid
            pid = project.save(manager)
        except DataObjectAlreadyExists as e:
            messages.error(request, e.message)
            return render_to_response('project/profile.html', {'form': form, 'project': project_summary, 'edit':False},
                                      context_instance=RequestContext(request))
        return HttpResponseRedirect(reverse(subjects_wizard, args=[pid]))
    else:
        return render_to_response('project/profile.html', {'form': form, 'project': project_summary, 'edit':False},
                                  context_instance=RequestContext(request))
Esempio n. 2
0
def edit_profile(request, project_id=None):
    manager = get_database_manager(request)
    entity_list = get_all_entity_types(manager)
    entity_list = helper.remove_reporter(entity_list)
    project = models.get_project(project_id, dbm=manager)
    if request.method == 'GET':
        form = ProjectProfile(data=project, entity_list=entity_list)
        return render_to_response('project/profile.html', {'form': form, 'project': project, 'edit':True},
                                  context_instance=RequestContext(request))

    form = ProjectProfile(data=request.POST, entity_list=entity_list)
    if form.is_valid():
        older_entity_type = project.entity_type
        if older_entity_type != form.cleaned_data["entity_type"]:
           new_questionnaire =  helper.create_questionnaire(form.cleaned_data, manager)
           new_qid = new_questionnaire.save()
           project.qid = new_qid
        project.update(form.cleaned_data)
        project.update_questionnaire(manager)

        try:
            pid = project.save(manager)
        except DataObjectAlreadyExists as e:
            messages.error(request, e.message)
            return render_to_response('project/profile.html', {'form': form, 'project': project, 'edit':True},
                                      context_instance=RequestContext(request))
        return HttpResponseRedirect(reverse(subjects_wizard, args=[pid]))
    else:
        return render_to_response('project/profile.html', {'form': form, 'project': project, 'edit':True},
                                  context_instance=RequestContext(request))
 def test_creates_project_profile_form(self):
     base_form = {'name': 'Test Project', 'goals': 'Test Goals', 'project_type': 'survey', 'entity_type': 'Reporter', 'activity_report':'yes',
                  'devices': ['sms'], 'sender_group':'open'
     }
     form = ProjectProfile(data=base_form, entity_list=[['Reporter']])
     self.assertTrue(form.is_valid(), form.errors)
     self.assertEquals(form.cleaned_data['name'], 'Test Project')
     self.assertEquals(form.cleaned_data['goals'], 'Test Goals')
     self.assertEquals(form.cleaned_data['project_type'], 'survey')
     self.assertEquals(form.cleaned_data['entity_type'], 'reporter')
     self.assertEquals(form.cleaned_data['devices'], ['sms'])
 def test_field_goals_not_required(self):
     base_form = {
         'name': 'Test Project',
         'project_type': 'survey',
         'entity_type': 'Reporter',
         'devices': ['sms'],
         'activity_report': 'no',
         'sender_group': 'open'
     }
     form = ProjectProfile(data=base_form, entity_list=[['Reporter']])
     assert form.is_valid()
Esempio n. 5
0
def create_profile(request):
    manager = get_database_manager(request)
    entity_list = get_all_entity_types(manager)
    entity_list = helper.remove_reporter(entity_list)
    project_summary = dict(name='New Project')
    if request.method == 'GET':
        form = ProjectProfile(entity_list=entity_list,
                              initial={'activity_report': 'yes'})
        return render_to_response('project/profile.html', {
            'form': form,
            'project': project_summary,
            'edit': False
        },
                                  context_instance=RequestContext(request))

    form = ProjectProfile(data=request.POST, entity_list=entity_list)
    if form.is_valid():
        entity_type = form.cleaned_data['entity_type']
        project = Project(name=form.cleaned_data["name"],
                          goals=form.cleaned_data["goals"],
                          project_type=form.cleaned_data['project_type'],
                          entity_type=entity_type,
                          devices=form.cleaned_data['devices'],
                          activity_report=form.cleaned_data['activity_report'],
                          sender_group=form.cleaned_data['sender_group'])
        form_model = helper.create_questionnaire(post=form.cleaned_data,
                                                 dbm=manager)
        try:
            pid = project.save(manager)
            qid = form_model.save()
            project.qid = qid
            pid = project.save(manager)
        except DataObjectAlreadyExists as e:
            messages.error(request, e.message)
            return render_to_response('project/profile.html', {
                'form': form,
                'project': project_summary,
                'edit': False
            },
                                      context_instance=RequestContext(request))
        return HttpResponseRedirect(reverse(subjects_wizard, args=[pid]))
    else:
        return render_to_response('project/profile.html', {
            'form': form,
            'project': project_summary,
            'edit': False
        },
                                  context_instance=RequestContext(request))
 def test_creates_project_profile_form(self):
     base_form = {
         'name': 'Test Project',
         'goals': 'Test Goals',
         'project_type': 'survey',
         'entity_type': 'Reporter',
         'activity_report': 'yes',
         'devices': ['sms'],
         'sender_group': 'open'
     }
     form = ProjectProfile(data=base_form, entity_list=[['Reporter']])
     self.assertTrue(form.is_valid(), form.errors)
     self.assertEquals(form.cleaned_data['name'], 'Test Project')
     self.assertEquals(form.cleaned_data['goals'], 'Test Goals')
     self.assertEquals(form.cleaned_data['project_type'], 'survey')
     self.assertEquals(form.cleaned_data['entity_type'], 'reporter')
     self.assertEquals(form.cleaned_data['devices'], ['sms'])
Esempio n. 7
0
def edit_profile(request, project_id=None):
    manager = get_database_manager(request)
    entity_list = get_all_entity_types(manager)
    entity_list = helper.remove_reporter(entity_list)
    project = models.get_project(project_id, dbm=manager)
    if request.method == 'GET':
        form = ProjectProfile(data=project, entity_list=entity_list)
        return render_to_response('project/profile.html', {
            'form': form,
            'project': project,
            'edit': True
        },
                                  context_instance=RequestContext(request))

    form = ProjectProfile(data=request.POST, entity_list=entity_list)
    if form.is_valid():
        older_entity_type = project.entity_type
        if older_entity_type != form.cleaned_data["entity_type"]:
            new_questionnaire = helper.create_questionnaire(
                form.cleaned_data, manager)
            new_qid = new_questionnaire.save()
            project.qid = new_qid
        project.update(form.cleaned_data)
        project.update_questionnaire(manager)

        try:
            pid = project.save(manager)
        except DataObjectAlreadyExists as e:
            messages.error(request, e.message)
            return render_to_response('project/profile.html', {
                'form': form,
                'project': project,
                'edit': True
            },
                                      context_instance=RequestContext(request))
        return HttpResponseRedirect(reverse(subjects_wizard, args=[pid]))
    else:
        return render_to_response('project/profile.html', {
            'form': form,
            'project': project,
            'edit': True
        },
                                  context_instance=RequestContext(request))
 def test_field_goals_not_required(self):
     base_form = {'name': 'Test Project', 'project_type': 'survey', 'entity_type': 'Reporter',
                  'devices': ['sms'], 'activity_report':'no', 'sender_group':'open'
     }
     form = ProjectProfile(data=base_form, entity_list=[['Reporter']])
     assert form.is_valid()