Exemplo n.º 1
0
def section_branch_add(request):
    """Add branching on section for the logged in user

    **Attributes**:

        * ``form`` - BranchingForm
        * ``template`` - survey/section_branch_change.html

    **Logic Description**:

        * Add branching record via BranchingForm
    """
    request.session['msg'] = ''
    form = ''
    section_survey_id = ''
    section_type = ''
    section_id = ''
    if request.GET.get('section_id'):
        section_id = request.GET.get('section_id')
        section = Section_template.objects.get(pk=int(section_id))
        section_survey_id = section.survey_id
        section_type = section.type
        form = BranchingForm(section.survey_id, section.id, request.POST or None, initial={'section': section_id})

        if request.method == 'POST':
            if form.is_valid():
                form.save()
                request.session["msg"] = _('branching is added successfully.')
                return HttpResponseRedirect(
                    redirect_url_to_survey_list + '%s/#row%s' % (section.survey_id, section_id))
            else:
                form._errors["keys"] = _("duplicate keys with goto.")
                request.session["err_msg"] = True

    data = {
        'form': form,
        'survey_id': section_survey_id,
        'section_type': section_type,
        'section_id': section_id,
        'err_msg': request.session.get('err_msg'),
        'action': 'add',
        'SECTION_TYPE': SECTION_TYPE,
    }
    request.session["msg"] = ''
    request.session['err_msg'] = ''
    return render_to_response('survey/section_branch_change.html', data, context_instance=RequestContext(request))
Exemplo n.º 2
0
def section_branch_add(request):
    """Add branching on section for the logged in user

    **Attributes**:

        * ``form`` - BranchingForm
        * ``template`` - frontend/survey/section_branch_change.html

    **Logic Description**:

        * Add branching record via BranchingForm
    """
    request.session['msg'] = ''
    form = ''
    section_survey_id = ''
    section_type = ''
    section_id = ''
    if request.GET.get('section_id'):
        section_id = request.GET.get('section_id')
        section = Section_template.objects.get(pk=int(section_id))
        section_survey_id = section.survey_id
        section_type = section.type
        form = BranchingForm(section.survey_id,
                             section.id,
                             initial={'section': section_id})
        if request.method == 'POST':
            form = BranchingForm(section.survey_id, section.id, request.POST)
            if form.is_valid():
                form.save()
                request.session["msg"] = _('branching is added successfully.')
                return HttpResponseRedirect('/survey/%s/#row%s' %
                                            (section.survey_id, section_id))
            else:
                form._errors["keys"] = _("duplicate record keys with goto.")
                request.session["err_msg"] = True

    template = 'frontend/survey/section_branch_change.html'
    data = {
        'form': form,
        'survey_id': section_survey_id,
        'section_type': section_type,
        'section_id': section_id,
        'module': current_view(request),
        'err_msg': request.session.get('err_msg'),
        'action': 'add',
        'SECTION_TYPE': SECTION_TYPE,
    }
    request.session["msg"] = ''
    request.session['err_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def section_branch_change(request, id):
    """Add branching on section for the logged in user

    **Attributes**:

        * ``form`` - BranchingForm
        * ``template`` - survey/section_branch_change.html

    **Logic Description**:

        * Update branching record via BranchingForm
        * Delete branching record
    """
    request.session['msg'] = ''
    if request.GET.get('delete'):
        # perform delete
        branching_obj = get_object_or_404(Branching_template, id=int(id),
                                          section__survey__user=request.user)
        survey_id = branching_obj.section.survey_id
        section_id = branching_obj.section_id
        branching_obj.delete()
        request.session["msg"] = _('branching is deleted successfully.')
        return HttpResponseRedirect(redirect_url_to_survey_list + '%s/#row%s' % (survey_id, section_id))

    branching = get_object_or_404(Branching_template, id=int(id),
                                  section__survey__user=request.user)
    form = BranchingForm(branching.section.survey_id,
                         branching.section_id,
                         request.POST or None,
                         instance=branching)
    if request.method == 'POST':
        if form.is_valid():
            form.save()
            request.session["msg"] = _('branching updated.')
            return HttpResponseRedirect(redirect_url_to_survey_list + '%s/#row%s'
                                        % (branching.section.survey_id, branching.section_id))
        else:
            form._errors["keys"] = _("duplicate record keys with goto.")
            request.session["err_msg"] = True

    data = {
        'form': form,
        'survey_id': branching.section.survey_id,
        'section_type': branching.section.type,
        'section_id': branching.section.id,
        'branching_id': branching.id,
        'err_msg': request.session.get('err_msg'),
        'action': 'update',
        'SECTION_TYPE': SECTION_TYPE,
    }
    request.session["msg"] = ''
    request.session['err_msg'] = ''
    return render_to_response('survey/section_branch_change.html', data, context_instance=RequestContext(request))
Exemplo n.º 4
0
def section_branch_change(request, id):
    """Add branching on section for the logged in user

    **Attributes**:

        * ``form`` - BranchingForm
        * ``template`` - frontend/survey/section_branch_change.html

    **Logic Description**:

        * Update branching record via BranchingForm
        * Delete branching record
    """
    request.session["msg"] = ""
    if request.GET.get("delete"):
        # perform delete
        branching_obj = get_object_or_404(Branching_template, id=int(id), section__survey__user=request.user)
        survey_id = branching_obj.section.survey_id
        section_id = branching_obj.section_id
        branching_obj.delete()
        request.session["msg"] = _("branching is deleted successfully.")
        return HttpResponseRedirect(redirect_url_to_survey_list + "%s/#row%s" % (survey_id, section_id))

    branching = get_object_or_404(Branching_template, id=int(id), section__survey__user=request.user)
    form = BranchingForm(branching.section.survey_id, branching.section_id, instance=branching)
    if request.method == "POST":
        form = BranchingForm(branching.section.survey_id, branching.section_id, request.POST, instance=branching)
        if form.is_valid():
            form.save()
            request.session["msg"] = _("branching updated.")
            return HttpResponseRedirect(
                redirect_url_to_survey_list + "%s/#row%s" % (branching.section.survey_id, branching.section_id)
            )
        else:
            form._errors["keys"] = _("duplicate record keys with goto.")
            request.session["err_msg"] = True

    template = "frontend/survey/section_branch_change.html"
    data = {
        "form": form,
        "survey_id": branching.section.survey_id,
        "section_type": branching.section.type,
        "section_id": branching.section.id,
        "branching_id": branching.id,
        "err_msg": request.session.get("err_msg"),
        "action": "update",
        "SECTION_TYPE": SECTION_TYPE,
    }
    request.session["msg"] = ""
    request.session["err_msg"] = ""
    return render_to_response(template, data, context_instance=RequestContext(request))
Exemplo n.º 5
0
def section_branch_add(request):
    """Add branching on section for the logged in user

    **Attributes**:

        * ``form`` - BranchingForm
        * ``template`` - frontend/survey/section_branch_change.html

    **Logic Description**:

        * Add branching record via BranchingForm
    """
    request.session["msg"] = ""
    form = ""
    section_survey_id = ""
    section_type = ""
    section_id = ""
    if request.GET.get("section_id"):
        section_id = request.GET.get("section_id")
        section = Section_template.objects.get(pk=int(section_id))
        section_survey_id = section.survey_id
        section_type = section.type
        form = BranchingForm(section.survey_id, section.id, initial={"section": section_id})
        if request.method == "POST":
            form = BranchingForm(section.survey_id, section.id, request.POST)
            if form.is_valid():
                form.save()
                request.session["msg"] = _("branching is added successfully.")
                return HttpResponseRedirect(redirect_url_to_survey_list + "%s/#row%s" % (section.survey_id, section_id))
            else:
                form._errors["keys"] = _("duplicate keys with goto.")
                request.session["err_msg"] = True

    template = "frontend/survey/section_branch_change.html"
    data = {
        "form": form,
        "survey_id": section_survey_id,
        "section_type": section_type,
        "section_id": section_id,
        "err_msg": request.session.get("err_msg"),
        "action": "add",
        "SECTION_TYPE": SECTION_TYPE,
    }
    request.session["msg"] = ""
    request.session["err_msg"] = ""
    return render_to_response(template, data, context_instance=RequestContext(request))