Exemplo n.º 1
0
def choice_update(request,question_id, choice_id,
                group_slug=None, group_slug_field=None,
                group_qs=None,
                template_name = 'survey/choice_add.html',
                extra_context=None,
                *args, **kw):
    question = get_object_or_404(Question, id=question_id)
    choice = get_object_or_404(Choice, id=choice_id)
    if choice not in question.choices.iterator():
        raise Http404()
    if request.method == "POST":
        request_post = request.POST.copy()
        choice_form = ChoiceForm(instance=choice,data=request_post,
                                 files=request.FILES)
        if choice_form.is_valid():
            new_choice = choice_form.save(commit=False)
            new_choice.question = question
            new_choice.save()
            return HttpResponseRedirect(reverse("survey-edit",None,(),
                                                {"survey_slug":question.survey.slug}))
    else:
        choice_form = ChoiceForm(instance=choice)
    return render_to_response(template_name,
                              {'title': _("Update choice"),
                               'choice' : choice,
                               'question' : question,
                               'model_string' : "Choice",
                               'form' : choice_form},
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
Arquivo: views.py Projeto: zouf/as2
def choice_add(
    request,
    question_id,
    group_slug=None,
    group_slug_field=None,
    group_qs=None,
    template_name="survey/choice_add.html",
    extra_context=None,
    *args,
    **kw
):
    question = get_object_or_404(Question, id=question_id)

    if request.method == "POST":
        request_post = request.POST.copy()
        choice_form = ChoiceForm(data=request_post, files=request.FILES)
        if choice_form.is_valid():
            new_choice = choice_form.save(commit=False)
            new_choice.question = question
            new_choice.save()
            return HttpResponseRedirect(reverse("survey-edit", None, (), {"survey_slug": question.survey.slug}))
    else:
        choice_form = ChoiceForm()

    return render_to_response(
        template_name, {"title": _("Add a choice"), "form": choice_form}, context_instance=RequestContext(request)
    )
Exemplo n.º 3
0
def index(request):
    examples = [
        'controlling Exposure', 'changing Temperature', 'modifying Highlights',
        'changing Shadows', 'Zooming in/out', 'changing the Constrast'
    ]

    if request.method == 'POST':
        f = ChoiceForm(request.POST)

        if f.is_valid():
            newChoice = f.save()

            if request.session.get('previous_responses', False):
                prev_response_array = request.session['previous_responses']
                prev_response_array.append({
                    'program': newChoice.program,
                    'text': newChoice.text
                })
                request.session['previous_responses'] = prev_response_array
            else:
                request.session['previous_responses'] = [{
                    'program': newChoice.program,
                    'text': newChoice.text
                }]

            return render(
                request, 'index.html', {
                    'previous': 1,
                    'previous_responses':
                    request.session['previous_responses'],
                    'example': random.choice(examples)
                })

    if request.session.get('previous_responses', False):
        return render(
            request, 'index.html', {
                'previous': 1,
                'previous_responses': request.session['previous_responses'],
                'example': random.choice(examples)
            })
    else:
        return render(
            request, 'index.html', {
                'previous': None,
                'previous_responses': None,
                'example': random.choice(examples)
            })
Exemplo n.º 4
0
def choice_update(request,
                  question_id,
                  choice_id,
                  group_slug=None,
                  group_slug_field=None,
                  group_qs=None,
                  template_name='survey/choice_add.html',
                  extra_context=None,
                  *args,
                  **kw):
    question = get_object_or_404(Question, id=question_id)
    choice = get_object_or_404(Choice, id=choice_id)
    if choice not in question.choices.iterator():
        raise Http404()
    if request.method == "POST":
        request_post = request.POST.copy()
        choice_form = ChoiceForm(instance=choice,
                                 data=request_post,
                                 files=request.FILES)
        if choice_form.is_valid():
            new_choice = choice_form.save(commit=False)
            new_choice.question = question
            new_choice.save()
            return HttpResponseRedirect(
                reverse("survey-edit", None, (),
                        {"survey_slug": question.survey.slug}))
    else:
        choice_form = ChoiceForm(instance=choice)
    return render_to_response(template_name, {
        'title': _("Update choice"),
        'choice': choice,
        'model_string': "Choice",
        'form': choice_form
    },
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
def choice_add(request,
               question_id,
               group_slug=None,
               group_slug_field=None,
               group_qs=None,
               template_name='survey/choice_add.html',
               extra_context=None,
               *args,
               **kw):
    question = get_object_or_404(Question, id=question_id)

    if request.method == "POST":
        request_post = request.POST.copy()
        choice_form = ChoiceForm(data=request_post, files=request.FILES)
        if choice_form.is_valid():
            new_choice = choice_form.save(commit=False)
            new_choice.question = question
            new_choice.save()
            return HttpResponseRedirect(
                reverse("survey-edit", None, (),
                        {"survey_slug": question.survey.slug}))
    else:
        choice_form = ChoiceForm()

    return render_to_response(template_name, {
        'title': _("Add a choice"),
        'question': question,
        'survey': question.survey,
        'form': choice_form
    },
                              context_instance=RequestContext(request))
Exemplo n.º 6
0
def index(request):
  examples = ['controlling Exposure', 'changing Temperature', 'modifying Highlights', 'changing Shadows', 'Zooming in/out', 'changing the Constrast']

  if request.method == 'POST':
    f = ChoiceForm(request.POST)
    
    if f.is_valid():
      newChoice = f.save()

      if request.session.get('previous_responses', False):
        prev_response_array = request.session['previous_responses']
        prev_response_array.append({'program':newChoice.program, 'text':newChoice.text})
        request.session['previous_responses'] = prev_response_array
      else:
        request.session['previous_responses'] = [{'program':newChoice.program, 'text':newChoice.text}];

      return render(request, 'index.html', {'previous':1, 'previous_responses':request.session['previous_responses'], 'example':random.choice(examples)})

  if request.session.get('previous_responses', False):
    return render(request, 'index.html', {'previous':1, 'previous_responses':request.session['previous_responses'], 'example':random.choice(examples)})
  else:
    return render(request, 'index.html', {'previous':None, 'previous_responses':None, 'example':random.choice(examples)})