Esempio n. 1
0
def questionnaire_modify(request, quest_id=None, template='quest/questionnaire_modify.html'):
    if quest_id is None:
        quest = Questionnaire(owner=request.user)
        questions = None
    else:
        quest = get_object_or_404(Questionnaire, pk=quest_id, owner=request.user)
        questions = Question.objects.filter(questionnaire=quest.pk).order_by('number')

    if request.method == 'POST':
        form = QuestForm(request.POST, instance=quest)
        if form.is_valid():
            quest = form.save()
            quest.owner = request.user
            quest.save()
            return redirect("quest.views.questionnaire_modify", quest_id=quest.pk)
    else:
        form = QuestForm(instance=quest)

    context = RequestContext(request)
    return render_to_response(template,
            {'form': form, 'quest': quest, 'questions': questions, },
            context_instance=context)
Esempio n. 2
0
def quest_form(request):


    f = QuestForm(request.POST or None)

    if request.method == 'POST':
        if f.is_valid():
            f.save()
            return redirect(reverse('home'))
        else:
            print 'here'

    f = QuestForm()
    c = RequestContext(request, {
        'f': f,
    })
    t = loader.get_template('quest/quest_form.html')
    html = t.render(Context(c))
    data = {'html': html, 'success': True}



    return HttpResponse(simplejson.dumps(data), mimetype='application/javascript')