Пример #1
0
def create_choice(request, poll_id):
    poll = get_object_or_404(Poll, id=poll_id)
    choice = Choice(poll=poll)
    if request.method == 'POST':
        form = ChoiceForm(request.POST, request.FILES, instance=choice)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('polls:administration:view', args=[poll.id]))
    else:
        form = ChoiceForm(initial={'poll':poll})
    return render(request, 'polls/administration/create_choice.html',
            {'form': form,
             'poll': poll,
             'active_module': 'polls'})
Пример #2
0
def home():
    form = FoodForm()
    # receive data
    if form.is_submitted():
        # get food choices
        food_choices = backend_functions.get_recipes(form.food.data)
        # load next page
        choiceForm = ChoiceForm()
        # receive data
        if choiceForm.validate_on_submit():
            # get recipe
            food_string = choiceForm.choice.data.replace(" ", "_")
            result = backend_functions.print_food(food_string)
            ### tryna add youtube stuff
            food_name = choiceForm.choice.data
            url = backend_functions.build_search_url(food_name)
            answer = backend_functions.get_result(url)
            table = backend_functions.addlist(answer)
            backend_functions.printStuff(table)
            result.append("\nYouTube Vidoes\n")
            for name, link, thumbnail in table:
                line = name + ": " + link + "\."
                result.append(line)
            ###
            # load results
            return render_template(
                "results.html", result=result)  # maybe add a redirect to home?
        return render_template("choices.html",
                               choiceForm=choiceForm,
                               options=food_choices)
    return render_template("home.html", title="ZotYum", form=form)
Пример #3
0
def extra_word():
    global data, extra_word, col_name, theme_name

    if request.method == 'GET':
        col_name, theme_name, data, extra_word = getData0()

    form = ChoiceForm()
    form.choose.choices = data.items()

    if form.validate_on_submit():
        if data[form.choose.data] == extra_word:
            answer = 1
            message = 'Вы правильно определили лишнее слово.'
        else:
            answer = 0
            message = 'Вы ошиблись в выборе лишнего слова. Лишнее слово - ' + extra_word.encode(
                'utf-8')
        putData(col_name, theme_name, 0, answer)
        return redirect(url_for('.interpreted', message=message))

    message = request.args['message']
    return render_template('extra_word.html',
                           title='Research',
                           form=form,
                           message=message)
Пример #4
0
def analysis(request):
    form = ChoiceForm(request.POST or None)

    if request.POST:
        query_url = request.POST["query_url"]
        query = feedparser.parse(query_url + str('.rss'))
        entry_count = len(query['entries'])
        all_entries = query['entries']
        choice = request.POST["example-select"]

        if request.user:
            new_query = Queries()
            new_query.url = query_url
            new_query.which_user = request.user

            new_query.save()

        c = {"request": request,
             "all_entries": all_entries,
             "choice": choice,
             "entry_count": entry_count}

        c.update(csrf(request))

        return render_to_response("results/utopian-io-reddit-feed.html", c)

    c = {"request": request,
         "form": form}

    c.update(csrf(request))

    return render_to_response("forms/make-choice.html", c)
Пример #5
0
def edit_choice(request, choice_id):
    choice = get_object_or_404(Choice, id=choice_id)
    if request.method == 'POST':
        form = ChoiceForm(request.POST, request.FILES, instance=choice)
        if form.is_valid():
            form.save()
            #            choice.choice = form.cleaned_data['choice']
            #            choice.votes = form.cleaned_data['votes']
            #            choice.save()
            return HttpResponseRedirect(reverse('polls:administration:view', args=[choice.poll.id]))
    else:

        form = ChoiceForm(instance=choice)
    return render(request, 'polls/administration/edit_choice.html',
            {'form': form,
             'choice': choice,
             'active_module': 'polls'})
Пример #6
0
 def test_choice_form(self):
     """Testing whether the choice form is valid."""
     form_data = {
         'text': "A great python framework",
         'point': 0,
         'question': self.question.id
     }
     form = ChoiceForm(data=form_data)
     self.assertTrue(form.is_valid())
Пример #7
0
def registration():
    form = ChoiceForm()
    if form.validate_on_submit():
        choice = form.choice.data
        if choice == "student":
            return redirect(url_for('register_student'))
        else:
            return redirect(url_for('register_tutor'))

    return render_template("registration.html",
                           pages=nav_bar_pages_list,
                           form=form)
Пример #8
0
def create_choice(request, quiz_id, question_id):
    """For superuser to create new choices."""
    if (request.user.is_superuser):
        question = get_object_or_404(Question, id=question_id)
        form = ChoiceForm(initial={'question': question})
        choices = Choice.objects.order_by('text')
        return render(
            request, 'createChoice.html', {
                'form': form,
                'quizID': int(quiz_id),
                'questionID': int(question_id),
                'question_name': question,
                'lists': choices
            })
    else:
        return render(request, 'invalidAttempt.html',
                      {'message': 'You are not a super user!'})
Пример #9
0
def add_choice(request, quiz_id, question_id):
    """Add the new choice that superuser created to the database."""
    if (request.user.is_superuser):
        if request.method == 'POST':
            form = ChoiceForm(request.POST)
            if form.is_valid():
                new_choice = form.save()
                new_choice.save()
                return HttpResponseRedirect(
                    reverse('create_choice',
                            kwargs={
                                'question_id': question_id,
                                'quiz_id': quiz_id
                            }))
            else:
                return render(request, 'invalidAttempt.html',
                              {'message': 'Invalid input!'})
    else:
        return render(request, 'invalidAttempt.html',
                      {'message': 'You are not a super user!'})