Exemple #1
0
def responses(class_key, question_key):
    answers = []

    try:
        class_ = ndb.Key(urlsafe=class_key).get()
        question = ndb.Key(urlsafe=question_key).get()

    except db.BadKeyError:
        class_ = None

    if class_ is None:
        return abort(404)

    surveys = StudentSurvey.query(ancestor=class_.key).fetch()

    for survey in surveys:
        answerss = Answer.query(Answer.question == question.key,
                                ancestor=survey.key).fetch()
        for answer in answerss:
            answers.append(str(answer.string_value))

    return render_template('responses.haml',
                           answers=answers,
                           question=question)

    return render_template('signup.haml')
Exemple #2
0
 def test_post_survey(self):
     question_key = Question(question='What do?', number=1, question_type='closed',
                             is_active=True).put()
     response = self.app.post('/survey', data={question_key.urlsafe(): 4})
     self.assertEqual(302, response.status_code)
     self.assertEqual(1, Answer.query().count())