当前位置: 首页>>代码示例>>Python>>正文


Python forms.QuestionForm类代码示例

本文整理汇总了Python中forms.QuestionForm的典型用法代码示例。如果您正苦于以下问题:Python QuestionForm类的具体用法?Python QuestionForm怎么用?Python QuestionForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QuestionForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_question

def add_question(request):
    context = {}

    settings = Settings.get_by_user(request.user)
    initial = {}

    if settings.group:
        initial["groups"] = [settings.group.id]

    if request.method == "POST":
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            question.added_by = request.user
            question.save()

            revision = QuestionRevision(
                question=question, user=request.user,
                text=form.cleaned_data["body"], active=True)
            revision.save()
            return HttpResponseRedirect("/question/%s" % question.id)
    else:
        form = QuestionForm(initial=initial)

    context["form"] = form


    return r2r(request, "add_question", context)
开发者ID:Veterun,项目名称:questions,代码行数:28,代码来源:views.py

示例2: ask

def ask(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = form.save(commit=False)
            if request.user.is_authenticated():
                question.user = request.user
            question.save()
            return render(request, 'ask_librarian/frontend/thanks.html', {
                'question': question,
            })
    else:
        if request.user.is_authenticated():
            form = QuestionForm(
                initial={
                    'fio': request.user.last_name + u' ' + request.user.first_name,
                    'email': request.user.email,
                }
            )
        else:
            form = QuestionForm()

    return render(request, 'ask_librarian/frontend/ask.html', {
        'form': form
    })
开发者ID:isergey,项目名称:chel,代码行数:25,代码来源:views.py

示例3: question_add

def question_add():
    # was form posted?
    if request.method == 'POST':
        form = QuestionForm(request.form)
        if form.validate_on_submit():
            question = Question(
                title=request.form['title'],
                text=request.form['text'],
                date=datetime.now(),
                user_id=current_user.id)

            # Answer save in db
            db.session.add(question)
            db.session.commit()

            return redirect(url_for('index'))

        else:
            # Show errors in form
            flash_errors(form)

    else:
        form = QuestionForm()

    return render_template('question_add.html', form=form)
开发者ID:alexander-vielimchanitsia,项目名称:Questions-Answers,代码行数:25,代码来源:views.py

示例4: main

def main():
	error = None 
	form = QuestionForm()
	if request.method == 'POST':
		if form.validate_on_submit():
			newName = form.name.data
			newEmail = form.email.data
			newQuestion = form.question.data
			new_question = Question(
				newName,
				newEmail,
				newQuestion
			)

			msg = Message("Your question submitted",
					recipients = [newEmail],
					sender = '[email protected]',
					body = u'Hello {}\n Your question was submitted through the site frenchonline. We will answer it ASAP ! '.format(newName)
					)

			admin_msg = Message ("You have a new question",
					recipients = ['[email protected]'],
					sender = '[email protected]',
					body = u'Your contact {} asked a question with the content \n----------\n"{}"\n----------\n, \nPlease answer through this email {}'.format(newName, newQuestion, newEmail)
				)
			db.session.add(new_question)
			db.session.commit()
			mail.send(msg)
			mail.send(admin_msg)
	return render_template('index.html', form = form, error = error)
开发者ID:mohammadgoli,项目名称:frenchonline,代码行数:30,代码来源:views.py

示例5: qpool_edit

def qpool_edit(request, id):
    question = get_object_or_404(Question, pk=id)
    categs = [(c.name.capitalize(), c.name) for c in Category.objects.all()]

    if request.method == 'POST':
        form = QuestionForm(request.POST, instance=question)
        if form.is_valid():
            newq = form.save()
            newq.proposed_by = request.user
            if newq.endorsed_by is None:
                newq.endorsed_by = request.user
                newq.save()
            return redirect('qpool_home', cat=newq.category.name)
        else:
            print "nevalid"
    else:
        show_users = False
        if question:
            if question.category:
                if question.category.name == 'proposed':
                    show_users = True

        form = QuestionForm(instance=question)

    return render_to_response('cpanel/qpool_edit.html',
                              {'question': question,
                               'form': form,
                               'module': 'qpool',
                               'categs': categs},
                              context_instance=RequestContext(request))
开发者ID:TobyWanKenobi,项目名称:wouso,代码行数:30,代码来源:views.py

示例6: question_edit

def question_edit(request, id=None):
    if id is not None:
        question = get_object_or_404(Question, pk=id)
    else:
        question = None

    categs = [(c.name.capitalize(), c.name) for c in Category.objects.all()]

    if request.method == 'POST':
        form = QuestionForm(request.POST, instance=question)
        if form.is_valid():
            newq = form.save()
            if (newq.endorsed_by is None):
                newq.endorsed_by = request.user
                newq.save()
            return HttpResponseRedirect(reverse('wouso.interface.cpanel.views.qpool_home', args = (newq.category.name,)))
    else:
        show_users = False
        if question:
            if question.category:
                if question.category.name == 'proposed':
                    show_users = True

        form = QuestionForm(instance=question, users=show_users)

    return render_to_response('cpanel/question_edit.html',
                              {'question': question,
                               'form': form,
                               'module': 'qpool',
                               'categs': categs},
                              context_instance=RequestContext(request))
开发者ID:LucianU,项目名称:wouso,代码行数:31,代码来源:views.py

示例7: send_newsletter

def send_newsletter():
    form = QuestionForm()
    if request.method == 'POST':
        recievers = Newsletter.query.order_by(Newsletter.id.desc()).all()
        if form.validate() == False:
            flash('Wymagane wszystkie pola.')
            return render_template('admin/send_newsletter.html', form=form)
        else:
            msg = Message(sender=("[email protected]"))
            for reciever in recievers:
                msg.add_recipient(reciever.email)
            msg.subject = " %s " % (form.subject.data)
            msg.body = """
            %s
            Aby wypisac sie z tego newslettera wejdz w zakladke pomoc na naszej stronie.
            """ % (form.message.data)
            mail.send(msg)
            print 'Newsletter do %s zostal wyslany' % (msg.recipients)
            flash('Newsletter zostal wyslany.')
        return redirect('/admin/newsletter')
    elif request.method == 'GET':
        print 'ok'
    return render_template('admin/send_newsletter.html',
	                       form=form,
                           title='Wysylanie newslettera')
开发者ID:zpidreamteam,项目名称:ZPI,代码行数:25,代码来源:admin_panel.py

示例8: SaveQuestionForm

def SaveQuestionForm(request):
    if request.is_ajax():
        data = request.POST.copy()
        faq_form = QuestionForm(data)
        if faq_form.is_valid():
            saved_object = faq_form.save()
            subject = u'%s - Новый вопрос' % settings.SITE_NAME
            subject = u''.join(subject.splitlines())
            message = render_to_string(
                'faq/admin_message_template.html',
                    {
                    'saved_object': saved_object,
                    'site_name': settings.SITE_NAME,
                }
            )
            try:
                emailto = Settings.objects.get(name='workemail').value
            except Settings.DoesNotExist:
                emailto = False

            if emailto:
                msg = EmailMessage(subject, message, settings.DEFAULT_FROM_EMAIL, [emailto])
                msg.content_subtype = "html"
                msg.send()

            return HttpResponse('success')
        else:
            faq_form_html = render_to_string(
                'faq/faq_form.html',
                    {'form': faq_form}
            )
            return HttpResponse(faq_form_html)
    else:
        return HttpResponseBadRequest()
开发者ID:wd5,项目名称:sibirtrans,代码行数:34,代码来源:views.py

示例9: new_question

def new_question():
    """Creates a new question"""
    form = QuestionForm()
    if request.method == 'POST' and form.validate_on_submit():
        question = Question(
            content=form.content.data,
            added_by=users.get_current_user(),
            location=get_location(form.location.data)
        )
        try:
            question.put()
            question_id = question.key.id()

            create_nearby_question(question_id)

            flash(u'Question %s successfully saved.' % question_id, 'success')
            add_question_to_search_index(question)


            return redirect(url_for('list_questions_for_user'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('list_questions_for_user'))
    else:
        flash_errors(form)
        return redirect(url_for('list_questions_for_user'))
开发者ID:ahbuntu,项目名称:ece1779,代码行数:26,代码来源:views.py

示例10: edit_question

def edit_question(request, question_id):
    a_question = get_object_or_404(Question, pk=question_id)
    form = QuestionForm (request.POST or None, instance = a_question)
    if form.is_valid():
        question = form.save()
        return redirect(reverse("polls:index"))

    return render (request, "polls/edit_template.html", {'form': form })
开发者ID:nestier,项目名称:tutodjango,代码行数:8,代码来源:views.py

示例11: add_question

def add_question():
    form = QuestionForm()
    if form.validate_on_submit():
        add_question = Questions(question=request.form['question'], user_id=g.user.id)
        db_session.add(add_question)
        db_session.commit()
        flash('Question Add!')
        return redirect(url_for('questions'))
    return render_template('add_question.html', title='Add question', form=form)
开发者ID:zedzew,项目名称:QueCom,代码行数:9,代码来源:views.py

示例12: add_new_question

def add_new_question(request):
    if request.POST:
        form = QuestionForm(request.POST)
        if form.is_valid():
            new_question = form.save()
#            return HttpResponseRedirect('/question/updated/%s/' %(new_question.id))
            return HttpResponseRedirect('/question/show/')
    else:
        form = QuestionForm()
    return render_to_response('question_model_form.html', dict(form=form))
开发者ID:shinriyo,项目名称:bucho,代码行数:10,代码来源:views.py

示例13: index

def index():
    form = QuestionForm()
    if form.validate_on_submit():
        question = Question(body=form.question.data, voite=None)
        db.session.add(question)
        db.session.commit()
        flash('Question was added')
        return redirect(url_for('index'))
    questions_all = Question.query.all()
    return render_template('index.html', title='Home', form=form, questions=questions_all)
开发者ID:nataliamm,项目名称:web_app,代码行数:10,代码来源:views.py

示例14: add_question

def add_question(request):
    form = QuestionForm()
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            form.instance.user = request.user
            form.save()
            return HttpResponseRedirect(reverse('index'))
    
    return request_response(request, 'answers/add_question.html', {'form':form})
开发者ID:seedwithroot,项目名称:django-answers,代码行数:10,代码来源:views.py

示例15: create

def create(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            form.save()
            mail_admins('Someone made a question!', 'http://' + request.get_host() + '/admin/quiz/question/?state=NEW')
            return HttpResponseRedirect('/quiz/created')
    else:
        form = QuestionForm()
    return render(request, 'quiz/create.html',
        {'form':form, 'title':'Create question'})
开发者ID:knatten,项目名称:cppquiz,代码行数:11,代码来源:views.py


注:本文中的forms.QuestionForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。