Beispiel #1
0
def question_update(request,survey_slug,question_id,
                    group_slug=None, group_slug_field=None,
                    group_qs=None,
                    template_name = 'survey/question_add.html',
                    extra_context=None,
                    *args, **kw):
    survey = get_object_or_404(Survey, slug=survey_slug)
    question =  get_object_or_404(SurveyQuestion,id=question_id)
    if question not in survey.questions.iterator():
        raise Http404()

    if request.method == "POST":
        request_post = request.POST.copy()
        question_form = SurveyQuestionForm(instance=question,data=request_post,
                                     files=request.FILES)

        if question_form.is_valid():
            new_question = question_form.save(commit=False)
            new_question.survey = survey
            new_question.save()
            return HttpResponseRedirect(reverse("survey-edit",None,(),
                                                {"survey_slug":survey_slug}))
    else:
        question_form = SurveyQuestionForm(instance=question)

    return render_to_response(template_name,
                              {'title': _("Update question"),
                               'question' : question,
                               'model_string' : "SurveyQuestion",
                               'form' : question_form},
                              context_instance=RequestContext(request))
Beispiel #2
0
def survey_question_change(request, id):
    """Update survey question for the logged in user

    **Attributes**:

        * ``form`` - SurveyQuestionForm
        * ``template`` - frontend/survey/survey_question_change.html

    **Logic Description**:

        *
    """
    survey_que = SurveyQuestion.objects.get(pk=int(id))
    form = SurveyQuestionForm(request.user, instance=survey_que)
    request.session['err_msg'] = ''
    if request.GET.get('delete'):
        # perform delete
        surveyapp_id = survey_que.surveyapp_id
        survey_response_list = SurveyResponse.objects\
                                .filter(surveyquestion=survey_que)
        for survey_resp in survey_response_list:
            survey_resp.delete()

        survey_que.delete()
        return HttpResponseRedirect('/survey/%s/' % (surveyapp_id))

    if request.method == 'POST':
        form = SurveyQuestionForm(request.user,
                                  request.POST,
                                  instance=survey_que)
        if form.is_valid():
            obj = form.save()
            return HttpResponseRedirect('/survey/%s/#row%s'  \
                % (obj.surveyapp_id, obj.id))
        else:
            request.session["err_msg"] = _('Question is not added.')

    template = 'frontend/survey/survey_question_change.html'
    data = {
        'form': form,
        'surveyapp_id': survey_que.surveyapp_id,
        'survey_question_id': id,
        'module': current_view(request),
        'err_msg': request.session.get('err_msg'),
        'action': 'update',
        }
    request.session['err_msg'] = ''
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Beispiel #3
0
def survey_question_add(request):
    """Add new Survey for the logged in user

    **Attributes**:

        * ``form`` - SurveyQuestionForm
        * ``template`` - frontend/survey/survey_question_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
    """
    surveyapp_id = request.GET.get('surveyapp_id')
    survey = SurveyApp.objects.get(pk=surveyapp_id)

    form = SurveyQuestionForm(request.user, initial={'surveyapp': survey})
    request.session['err_msg'] = ''
    if request.method == 'POST':
        form = SurveyQuestionForm(request.user, request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = User.objects.get(username=request.user)
            obj.save()
            request.session["msg"] = _('"%(question)s" is added.') %\
                                       {'question': request.POST['question']}
            return HttpResponseRedirect('/survey/%s/#row%s' \
                        % (obj.surveyapp_id, obj.id))
        else:
            request.session["err_msg"] = _('Question is not added.')
            #surveyapp_id = request.POST['surveyapp']

    template = 'frontend/survey/survey_question_change.html'

    data = {
        'form': form,
        'surveyapp_id': surveyapp_id,
        'err_msg': request.session.get('err_msg'),
        'action': 'add'
        }
    request.session['err_msg'] = ''
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Beispiel #4
0
def question_add(request,
                 survey_slug,
                 group_slug=None,
                 group_slug_field=None,
                 group_qs=None,
                 template_name='survey/question_add.html',
                 extra_context=None,
                 *args,
                 **kw):
    survey = get_object_or_404(Survey, slug=survey_slug)
    if request.method == "POST":
        request_post = request.POST.copy()
        question_form = SurveyQuestionForm(data=request_post,
                                           files=request.FILES)
        if question_form.is_valid():
            new_question = question_form.save(commit=False)
            new_question.survey = survey
            new_question.save()
            return HttpResponseRedirect(
                reverse("survey-edit", None, (), {"survey_slug": survey_slug}))

    else:
        question_form = SurveyQuestionForm()
    return render_to_response(template_name, {
        'title': _("Add a question"),
        'form': question_form
    },
                              context_instance=RequestContext(request))
Beispiel #5
0
def question_add(request,survey_slug,
               group_slug=None, group_slug_field=None,
               group_qs=None,
               template_name = 'survey/question_add.html',
               extra_context=None,
               *args, **kw):
    survey = get_object_or_404(Survey, slug=survey_slug)
    if request.method == "POST":
        request_post = request.POST.copy()
        question_form = SurveyQuestionForm(data=request_post,files=request.FILES)
        if question_form.is_valid():
            new_question = question_form.save(commit=False)
            new_question.survey = survey
            new_question.save()
            return HttpResponseRedirect(reverse("survey-edit",None,(),
                                                {"survey_slug":survey_slug}))

    else:
        question_form = SurveyQuestionForm()
    return render_to_response(template_name,
                              {'title': _("Add a question"),
                               'form' : question_form},
                              context_instance=RequestContext(request))
Beispiel #6
0
def survey_question_add_update(request, id, data, form_type,
                               after_initial_save, record_id):
    """ Ajax method to update the question """
    dajax = Dajax()

    if form_type == 'old_form':
        form = SurveyQuestionForm(data)

        if after_initial_save == 1 and record_id:
            survey_question = SurveyQuestion.objects.get(pk=int(record_id))
        else:
            survey_question = SurveyQuestion.objects.get(pk=int(id))

        form = SurveyQuestionForm(data, instance=survey_question)

    if form_type == 'new_form':
        form = SurveyQuestionNewForm(request.user, data)

    if form.is_valid():
        if form_type == 'old_form':
            object = form.save(commit=False)
            audio_message = form.cleaned_data.get('audio_message')
            object.message_type = audio_msg_type(audio_message)
            object.save()

        if form_type == 'new_form':
            obj = form.save(commit=False)
            obj.user = User.objects.get(username=request.user)
            obj.surveyapp = form.cleaned_data.get('surveyapp')
            audio_message = form.cleaned_data.get('audio_message')
            obj.message_type = audio_msg_type(audio_message)
            obj.save()
            dajax.assign('#id', 'value', obj.id)
        #dajax.alert("%s is successfully saved !!" % form.cleaned_data.get('question'))
    else:
        if form_type == 'new_form':
            dajax.remove_css_class('#new_survey_que_form_' + id + ' input',
                                   'error')
        if form_type == 'old_form':
            dajax.remove_css_class('#que_form_' + id + ' input', 'error')
        dajax.alert("error")
    return dajax.json()
Beispiel #7
0
def survey_question_change(request, id):
    """Update survey question for the logged in user

    **Attributes**:

        * ``form`` - SurveyQuestionForm
        * ``template`` - frontend/survey/survey_question_change.html

    **Logic Description**:

        *
    """
    survey_que = SurveyQuestion.objects.get(pk=int(id))
    form = SurveyQuestionForm(request.user, instance=survey_que)
    request.session['err_msg'] = ''
    if request.GET.get('delete'):
        # perform delete
        surveyapp_id = survey_que.surveyapp_id
        survey_response_list = SurveyResponse.objects\
                                .filter(surveyquestion=survey_que)
        for survey_resp in survey_response_list:
            survey_resp.delete()

        survey_que.delete()
        return HttpResponseRedirect('/survey/%s/' % (surveyapp_id))

    if request.method == 'POST':
        form = SurveyQuestionForm(request.user,
                                  request.POST,
                                  instance=survey_que)
        if form.is_valid():
            obj = form.save()
            return HttpResponseRedirect('/survey/%s/#row%s'  \
                % (obj.surveyapp_id, obj.id))
        else:
            request.session["err_msg"] = _('Question is not added.')

    template = 'frontend/survey/survey_question_change.html'
    data = {
        'form': form,
        'surveyapp_id': survey_que.surveyapp_id,
        'survey_question_id': id,
        'module': current_view(request),
        'err_msg': request.session.get('err_msg'),
        'action': 'update',
    }
    request.session['err_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Beispiel #8
0
def survey_question_add(request):
    """Add new Survey for the logged in user

    **Attributes**:

        * ``form`` - SurveyQuestionForm
        * ``template`` - frontend/survey/survey_question_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
    """
    surveyapp_id = request.GET.get('surveyapp_id')
    survey = SurveyApp.objects.get(pk=surveyapp_id)

    form = SurveyQuestionForm(request.user, initial={'surveyapp': survey})
    request.session['err_msg'] = ''
    if request.method == 'POST':
        form = SurveyQuestionForm(request.user, request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = User.objects.get(username=request.user)
            obj.save()
            request.session["msg"] = _('"%(question)s" is added.') %\
                                       {'question': request.POST['question']}
            return HttpResponseRedirect('/survey/%s/#row%s' \
                        % (obj.surveyapp_id, obj.id))
        else:
            request.session["err_msg"] = _('Question is not added.')
            #surveyapp_id = request.POST['surveyapp']

    template = 'frontend/survey/survey_question_change.html'

    data = {
        'form': form,
        'surveyapp_id': surveyapp_id,
        'err_msg': request.session.get('err_msg'),
        'action': 'add'
    }
    request.session['err_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Beispiel #9
0
def survey_question_add_update(request, id, data, form_type, after_initial_save, record_id):
    """ Ajax method to update the question """
    dajax = Dajax()

    if form_type == 'old_form':
        form = SurveyQuestionForm(data)

        if after_initial_save == 1 and record_id:
            survey_question = SurveyQuestion.objects.get(pk=int(record_id))            
        else:            
            survey_question = SurveyQuestion.objects.get(pk=int(id))

        form = SurveyQuestionForm(data, instance=survey_question)

    if form_type == 'new_form':
        form = SurveyQuestionNewForm(request.user, data)

    if form.is_valid():
        if form_type == 'old_form':
            object = form.save(commit=False)
            audio_message = form.cleaned_data.get('audio_message')
            object.message_type = audio_msg_type(audio_message)
            object.save()
            
        if form_type == 'new_form':            
            obj = form.save(commit=False)
            obj.user = User.objects.get(username=request.user)
            obj.surveyapp = form.cleaned_data.get('surveyapp')
            audio_message = form.cleaned_data.get('audio_message')
            obj.message_type = audio_msg_type(audio_message)
            obj.save()
            dajax.assign('#id', 'value', obj.id)
        #dajax.alert("%s is successfully saved !!" % form.cleaned_data.get('question'))
    else:
        if form_type == 'new_form':
            dajax.remove_css_class('#new_survey_que_form_'+id+' input','error')
        if form_type == 'old_form':
            dajax.remove_css_class('#que_form_'+id+' input','error')
        dajax.alert("error")
    return dajax.json()
Beispiel #10
0
def question_update(request,
                    survey_slug,
                    question_id,
                    group_slug=None,
                    group_slug_field=None,
                    group_qs=None,
                    template_name='survey/question_add.html',
                    extra_context=None,
                    *args,
                    **kw):
    survey = get_object_or_404(Survey, slug=survey_slug)
    question = get_object_or_404(SurveyQuestion, id=question_id)
    if question not in survey.questions.iterator():
        raise Http404()

    if request.method == "POST":
        request_post = request.POST.copy()
        question_form = SurveyQuestionForm(instance=question,
                                           data=request_post,
                                           files=request.FILES)

        if question_form.is_valid():
            new_question = question_form.save(commit=False)
            new_question.survey = survey
            new_question.save()
            return HttpResponseRedirect(
                reverse("survey-edit", None, (), {"survey_slug": survey_slug}))
    else:
        question_form = SurveyQuestionForm(instance=question)

    return render_to_response(template_name, {
        'title': _("Update question"),
        'question': question,
        'model_string': "SurveyQuestion",
        'form': question_form
    },
                              context_instance=RequestContext(request))