Ejemplo n.º 1
0
def CreateQuestion(request):
    if not has_moderation_privileges(request.user):
        return HttpResponseForbidden()
    question_text = request.POST.get('question_text')
    question = Question(question_text=question_text, is_published=1)
    question.save()  #persist question

    #check for first option
    option_counter = 1
    has_more_options = True
    option_name = 'option' + str(option_counter)
    if not request.POST.has_key(option_name):
        has_more_options = False

    while has_more_options:
        option_text = request.POST.get(option_name)
        if option_text == None or option_text == '':
            continue
        q_option = Question_option(question=question, option_text=option_text)
        q_option.save()  #persist option

        #check for further options
        option_counter = option_counter + 1
        option_name = 'option' + str(option_counter)
        if not request.POST.has_key(option_name):
            has_more_options = False

    request.session[
        'message'] = 'The question has been published to the url: \n http://localhost:8000/questions/' + str(
            question.id)

    return redirect('/administration/')
Ejemplo n.º 2
0
def CreateQuestion(request):
    if not has_moderation_privileges(request.user):
        return HttpResponseForbidden()
    question_text = request.POST.get('question_text')
    question = Question(question_text=question_text, is_published=1)
    question.save() #persist question

    #check for first option
    option_counter=1
    has_more_options = True
    option_name = 'option'+str(option_counter)
    if not request.POST.has_key(option_name):
        has_more_options=False

    while has_more_options:
        option_text = request.POST.get(option_name)
        if option_text==None or option_text=='':
            continue
        q_option = Question_option(question=question, option_text=option_text)
        q_option.save() #persist option

        #check for further options
        option_counter=option_counter+1
        option_name = 'option'+str(option_counter)
        if not request.POST.has_key(option_name):
            has_more_options=False

    request.session['message'] = 'The question has been published to the url: \n http://localhost:8000/questions/'+str(question.id)

    return redirect('/administration/')
Ejemplo n.º 3
0
 def test_was_published_recently_with_recent_question(self):
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True)
Ejemplo n.º 4
0
 def test_was_published_recently_with_old_question(self):
     time = timezone.now() - datetime.timedelta(days=30)
     old_question = Question(pub_date=time)
     self.assertEqual(old_question.was_published_recently(), False)