Пример #1
0
def section_add(request):
    """Add new Survey for the logged in user

    **Attributes**:

        * ``template`` - frontend/survey/section_change.html

    **Logic Description**:

        * Add a new survey which will belong to the logged in user
          via the SurveyForm & get redirected to the survey list
    """
    survey_id = request.GET.get('survey_id')
    survey = Survey_template.objects.get(pk=survey_id)
    form = PlayMessageSectionForm(request.user, initial={'survey': survey})

    request.session['err_msg'] = ''
    if request.method == 'POST':
        # Play message
        if int(request.POST.get('type')) == SECTION_TYPE.PLAY_MESSAGE:
            form_data = \
                section_add_form(request, PlayMessageSectionForm, survey, SECTION_TYPE.PLAY_MESSAGE)

        # hangup
        if int(request.POST.get('type')) == SECTION_TYPE.HANGUP_SECTION:
            form_data =\
                section_add_form(request, PlayMessageSectionForm, survey, SECTION_TYPE.HANGUP_SECTION)

        # DNC
        if int(request.POST.get('type')) == SECTION_TYPE.DNC:
            form_data =\
                section_add_form(request, PlayMessageSectionForm, survey, SECTION_TYPE.DNC)

        # Multiple Choice Section
        if int(request.POST.get('type')) == SECTION_TYPE.MULTI_CHOICE:
            form_data =\
                section_add_form(request, MultipleChoiceSectionForm, survey, SECTION_TYPE.MULTI_CHOICE)

        # Rating Section
        if int(request.POST.get('type')) == SECTION_TYPE.RATING_SECTION:
            form_data =\
                section_add_form(request, RatingSectionForm, survey, SECTION_TYPE.RATING_SECTION)

        # Capture Digits Section
        if int(request.POST.get('type')) == SECTION_TYPE.CAPTURE_DIGITS:
            form_data =\
                section_add_form(request, CaptureDigitsSectionForm, survey, SECTION_TYPE.CAPTURE_DIGITS)

        # Record Message Section
        if int(request.POST.get('type')) == SECTION_TYPE.RECORD_MSG:
            form_data =\
                section_add_form(request, RecordMessageSectionForm, survey, SECTION_TYPE.RECORD_MSG)

        # Call transfer Section
        if int(request.POST.get('type')) == SECTION_TYPE.CONFERENCE:
            form_data =\
                section_add_form(request, ConferenceSectionForm, survey, SECTION_TYPE.CONFERENCE)

        # Call transfer Section
        if int(request.POST.get('type')) == SECTION_TYPE.CALL_TRANSFER:
            form_data =\
                section_add_form(request, CallTransferSectionForm, survey, SECTION_TYPE.CALL_TRANSFER)

        if form_data.get('save_tag'):
            return HttpResponseRedirect(
                '/survey/%s/#row%s' %
                (form_data['new_obj'].survey_id, form_data['new_obj'].id))
        else:
            form = form_data['form']

    template = 'frontend/survey/section_change.html'
    data = {
        'form': form,
        'survey_id': survey_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))
Пример #2
0
def section_change(request, id):
    """Update survey question for the logged in user

    **Attributes**:

        * ``template`` - frontend/survey/section_change.html

    **Logic Description**:

        * update section object via section_update_form function
    """
    section = get_object_or_404(Section_template,
                                pk=int(id),
                                survey__user=request.user)
    if (section.type == SECTION_TYPE.PLAY_MESSAGE
            or section.type == SECTION_TYPE.HANGUP_SECTION
            or section.type == SECTION_TYPE.DNC):
        #PLAY_MESSAGE, HANGUP_SECTION & DNC
        form = PlayMessageSectionForm(request.user, instance=section)
    elif section.type == SECTION_TYPE.MULTI_CHOICE:
        #MULTI_CHOICE
        form = MultipleChoiceSectionForm(request.user, instance=section)
    elif section.type == SECTION_TYPE.RATING_SECTION:
        #RATING_SECTION
        form = RatingSectionForm(request.user, instance=section)
    elif section.type == SECTION_TYPE.CAPTURE_DIGITS:
        #CAPTURE_DIGITS
        form = CaptureDigitsSectionForm(request.user, instance=section)
    elif section.type == SECTION_TYPE.RECORD_MSG:
        #RECORD_MSG
        form = RecordMessageSectionForm(request.user, instance=section)
    elif section.type == SECTION_TYPE.CONFERENCE:
        #CONFERENCE
        form = ConferenceSectionForm(request.user, instance=section)
    elif section.type == SECTION_TYPE.CALL_TRANSFER:
        #CALL_TRANSFER
        form = CallTransferSectionForm(request.user, instance=section)

    request.session['err_msg'] = ''

    if request.method == 'POST' and request.POST.get('type'):
        # Play message or Hangup Section or DNC
        if (int(request.POST.get('type')) == SECTION_TYPE.PLAY_MESSAGE
                or int(request.POST.get('type')) == SECTION_TYPE.HANGUP_SECTION
                or int(request.POST.get('type')) == SECTION_TYPE.DNC):
            form_data = section_update_form(request, PlayMessageSectionForm,
                                            SECTION_TYPE.PLAY_MESSAGE, section)

        # Multiple Choice Section
        if int(request.POST.get('type')) == SECTION_TYPE.MULTI_CHOICE:
            form_data = section_update_form(request, MultipleChoiceSectionForm,
                                            SECTION_TYPE.MULTI_CHOICE, section)

        # Rating Section
        if int(request.POST.get('type')) == SECTION_TYPE.RATING_SECTION:
            form_data = section_update_form(request, RatingSectionForm,
                                            SECTION_TYPE.RATING_SECTION,
                                            section)

        # Capture Digits Section
        if int(request.POST.get('type')) == SECTION_TYPE.CAPTURE_DIGITS:
            form_data = section_update_form(request, CaptureDigitsSectionForm,
                                            SECTION_TYPE.CAPTURE_DIGITS,
                                            section)

        # Record Message Section Section
        if int(request.POST.get('type')) == SECTION_TYPE.RECORD_MSG:
            form_data = section_update_form(request, RecordMessageSectionForm,
                                            SECTION_TYPE.RECORD_MSG, section)

        # Call Transfer Section
        if int(request.POST.get('type')) == SECTION_TYPE.CALL_TRANSFER:
            form_data = section_update_form(request, CallTransferSectionForm,
                                            SECTION_TYPE.CALL_TRANSFER,
                                            section)

        # Conference Section
        if int(request.POST.get('type')) == SECTION_TYPE.CONFERENCE:
            form_data = section_update_form(request, ConferenceSectionForm,
                                            SECTION_TYPE.CONFERENCE, section)

        if form_data.get('save_tag'):
            return HttpResponseRedirect('/survey/%s/#row%s' %
                                        (section.survey_id, section.id))
        else:
            form = form_data['form']

    template = 'frontend/survey/section_change.html'
    data = {
        'form': form,
        'survey_id': section.survey_id,
        'section_id': section.id,
        'module': current_view(request),
        '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))
Пример #3
0
    def test_survey_forms(self):
        self.assertEqual(self.survey_template.name, "test_survey")
        #self.assertEqual(self.section_template.survey, self.survey_template)
        self.assertEqual(self.branching_template.section, self.section_template)
        self.assertEqual(self.result.section, self.section)

        form = PlayMessageSectionForm(self.user, instance=self.section_template)
        obj = form.save(commit=False)
        obj.question = "test question"
        obj.type = 1
        obj.survey = self.survey_template
        obj.save()

        form = MultipleChoiceSectionForm(self.user, instance=self.section_template)
        obj = form.save(commit=False)
        obj.type = 2
        obj.question = "test question"
        obj.key_0 = "apple"
        obj.survey = self.survey_template
        obj.save()

        form = RatingSectionForm(self.user,
                                 instance=self.section_template)
        obj = form.save(commit=False)
        obj.type = 3
        obj.question = "test question"
        obj.rating_laps = 5
        obj.survey_template = self.survey_template
        obj.save()

        form = CaptureDigitsSectionForm(self.user,
                                        instance=self.section_template)
        obj = form.save(commit=False)
        obj.type = 4
        obj.question = "test question"
        obj.number_digits = 2
        obj.min_number = 1
        obj.max_number = 100
        obj.survey = self.survey_template
        obj.save()

        form = RecordMessageSectionForm(self.user)
        obj = form.save(commit=False)
        obj.type = 5
        obj.question = "test question"
        obj.survey = self.survey_template
        obj.save()

        form = CallTransferSectionForm(self.user)
        obj = form.save(commit=False)
        obj.type = 6
        obj.question = "test question"
        obj.phonenumber = 1234567890
        obj.survey = self.survey_template
        obj.save()

        form = SMSSectionForm(self.user)
        obj = form.save(commit=False)
        obj.type = 10
        obj.question = "sms question"
        obj.sms_text = "this is test sms"
        obj.survey = self.survey_template
        obj.save()

        form = ScriptForm()
        obj = form.save(commit=False)
        obj.script = 'xyz'
        obj.survey = self.survey_template
        obj.save()

        form = SurveyDetailReportForm(self.user)