Exemple #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))
Exemple #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))
Exemple #3
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))
Exemple #4
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))