Source

teapoll / survey / views.py

from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext

from . import models as survey_models

@login_required
def list_surveys(request):
  return render_to_response('survey/list_surveys.html', dict(
    surveys = survey_models.Survey.objects.all()),
    context_instance = RequestContext(request))

@login_required
def enter_survey_instance(request, survey_id):
  survey = get_object_or_404(survey_models.Survey, pk = survey_id)
  if request.method == 'POST':
    subject = survey.submit(request.POST, user = request.user)
    return render_to_response('survey/submit_done.html', dict(
      survey = survey, subject = subject), context_instance = RequestContext(request))

  return render_to_response('survey/enter.html', dict(
    survey = survey), context_instance = RequestContext(request))

@login_required
def list_subjects(request, survey_id):
  survey = get_object_or_404(survey_models.Survey, pk = survey_id)
  return render_to_response('survey/list_subjects.html', dict(
    survey = survey), context_instance = RequestContext(request))

@login_required
def edit_survey_instance(request, survey_id, subject_id):
  survey = get_object_or_404(survey_models.Survey, pk = survey_id)
  subject = get_object_or_404(survey_models.Subject, pk = subject_id)
  if request.method == 'POST':
    survey.submit(request.POST, subject)
    return render_to_response('survey/submit_done.html', dict(
      survey = survey, subject = subject), context_instance = RequestContext(request))

  answers = []
  for question in survey.questions.all():
    answer = survey.subject_answers.get(question = question, subject = subject)
    answers.append(answer)

  return render_to_response('survey/edit.html', dict(
    survey = survey,
    subject = subject,
    answers = answers), context_instance = RequestContext(request))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.