Esempio n. 1
0
def survey(request, survey_version_id):
    """View for submitting the answers to a survey.

    URL name reference for this view: ``dform-survey``

    """
    version = get_object_or_404(SurveyVersion, id=survey_version_id)

    try:
        template = Template(settings.DFORM_SURVEY_SUBMIT)
        context = Context({'survey_version':version})
        submit_action = template.render(context)
    except AttributeError:
        submit_action = reverse('dform-survey', args=(version.id, ))

    if request.method == 'POST':
        form = SurveyForm(request.POST, survey_version=version)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(version.on_success())
    else:
        form = SurveyForm(survey_version=version)

    data = {
        'title':version.survey.name,
        'survey_version':version,
        'form':form,
        'submit_action':submit_action,
    }

    return render_page(request, 'dform/survey.html', data)
Esempio n. 2
0
    def test_renders(self):
        request = FakeRequest()
        expected = 'Hello World\n'

        result = render_page_to_string(request, 'sample.html', {'name':'World'})
        self.assertEqual(expected, result)

        response = render_page(request, 'sample.html', {'name':'World'})
        self.assertEqual(expected, response.content.decode('ascii'))
Esempio n. 3
0
def preview_sheet(request, preview_sheet_id):
    """Displays a sample Bootstrap page using the variables stored in the
    given :class:`PreviewSheet`

    @param preview_sheet_id: ID of :class:`PreviewSheet` object
    """
    preview = get_object_or_404(PreviewSheet, id=preview_sheet_id)
    data = {
        'preview':preview,
        'preview_css_url':reverse('bseditor-preview-css', args=(preview.id,))
    }

    return render_page(request, 'bseditor/preview_sheet.html', data)
Esempio n. 4
0
def edit_sheet(request, sheet_id):
    sheet = get_object_or_404(Sheet, id=sheet_id)

    data = {
        'sheet':sheet,
        'bstrap_vars':sheet.get_vars(),
        'cancel_url':reverse('admin:bseditor_sheet_changelist'),
        'ajax_colour_value_url':reverse('bseditor-ajax-colour-value'),
        'ajax_save_sheet':reverse('bseditor-ajax-save-sheet', args=(sheet.id,)),
        'ajax_save_preview':reverse('bseditor-ajax-save-preview', 
            args=(sheet.id,)),
    }

    return render_page(request, 'bseditor/edit_sheet.html', data)
Esempio n. 5
0
def survey_editor(request, survey_version_id):
    if survey_version_id == '0':
        # new survey
        survey = Survey.objects.create(name='New Survey')
        version = survey.latest_version
    else:
        version = get_object_or_404(SurveyVersion, id=survey_version_id)

    admin_link = reverse('admin:index')
    return_url = request.META.get('HTTP_REFERER', admin_link)
    save_url = reverse('dform-survey-delta', args=(version.id, ))
    data = {
        'survey_version':json.dumps(version.to_dict()),
        'save_url':save_url,
        'return_url':return_url,
    }

    return render_page(request, 'dform/edit_survey.html', data)
Esempio n. 6
0
def sample_survey(request, survey_version_id):
    """A view for displaying a sample version of a form.  The submit mechanism
    does nothing.

    URL name reference for this view: ``dform-sample-survey``

    :param survey_version_id:
        Id of a :class:`SurveyVersion` object
    """
    version = get_object_or_404(SurveyVersion, id=survey_version_id)

    form = SurveyForm(survey_version=version)
    data = {
        'title':'Sample: %s' % version.survey.name,
        'survey_version':version,
        'form':form,
        'submit_action':'',
    }

    return render_page(request, 'dform/survey.html', data)
Esempio n. 7
0
def survey_with_answers(request, survey_version_id, answer_group_id):
    """View for viewing and changing the answers to a survey that already has
    answers.

    URL name reference for this view: ``dform-survey-with-answers``
    """
    version = get_object_or_404(SurveyVersion, id=survey_version_id)
    answer_group = get_object_or_404(AnswerGroup, id=answer_group_id)

    try:
        template = Template(settings.DFORM_SURVEY_WITH_ANSWERS_SUBMIT)
        context = Context({
            'survey_version':version, 
            'answer_group':answer_group
        })
        submit_action = template.render(context)
    except AttributeError:
        submit_action = reverse('dform-survey-with-answers', args=(
            version.id, answer_group.id))

    if request.method == 'POST':
        form = SurveyForm(request.POST, survey_version=version,
            answer_group=answer_group)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(version.on_success())
    else:
        form = SurveyForm(survey_version=version, answer_group=answer_group)

    data = {
        'title':version.survey.name,
        'survey_version':version,
        'answer_group':answer_group,
        'form':form,
        'submit_action':submit_action,
    }

    return render_page(request, 'dform/survey.html', data)
Esempio n. 8
0
def embed(request):
    return render_page(request, 'embed.html')