當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.TopicForm類代碼示例

本文整理匯總了Python中forms.TopicForm的典型用法代碼示例。如果您正苦於以下問題:Python TopicForm類的具體用法?Python TopicForm怎麽用?Python TopicForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TopicForm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

def create():
    data = request.get_json()
    
    form = TopicForm(**data)
    if form.validate():
        form_data = form.data
        form_data['ip'] = request.remote_addr

        try:
            topic = g.user.create_topic(**form_data)
            alert = dict(
                type='success',
                messages=_("Your topic has been created successfully. You will be redirected to it shortly")
            )

            redirect = topic.get_url('view')
            cache.update_sorted_topics(topic, 'date_created')
            return jsonify({"data": topic.json_data(), "alert": alert, "redirect": redirect})
        except ModelException, me:
            db_session.rollback()
            return json_error(type=me.type, messages=me.message)
        except Exception, e:
            logging.error(e)
            db_session.rollback()
            return json_error_database()
開發者ID:laoshanlung,項目名稱:flask-demo,代碼行數:25,代碼來源:api_topics.py

示例2: topic_create

def topic_create(project_id):
    project = Project.query.get(project_id)
    if not current_user.in_team(project.team_id):
        abort(404)
    form = TopicForm(current_user, project, request.form.getlist('attachment'))
    if form.validate_on_submit():
        topic = form.saveTopic()
        if topic is not None:
            flash(u'保存成功')
            return redirect(url_for('topic_detail', topic_id=topic.id))
        else:
            flash(u'保存失敗,請聯係管理員', 'error')
    return render_template('project/topic_create.html', project=project, form=form)
開發者ID:Red54,項目名稱:Sophia,代碼行數:13,代碼來源:app.py

示例3: new

def new():
    form = TopicForm()
    flash(form.board_id.data)
    if form.validate_on_submit():
        u = User.query.filter_by(id = g.user.id).first()
        topic = Topic(board_id=form.board_id.data, category=form.category.data, author=u, title=form.title.data, content=form.content.data)
        db.session.add(topic)
        db.session.commit()
        flash("發表成功")
        return redirect(request.args.get("next") or url_for("index"))
    form.board_id.data = request.args.get('board_id', '')
    return render_template('new.html',
        form = form,
        title = '新建')
開發者ID:satnosun,項目名稱:webbz,代碼行數:14,代碼來源:views.py

示例4: forum

def forum(page=1):
    # Нужная страница
    if request.args.get('page'):
        page = int(request.args.get('page'))

    # Разбиение на страницы
    pagination = Pagination(page, TOPIC_PER_PAGE, ForumTopic.query.count())

    # Форма для постинга сообщений
    form_topic = TopicForm()
    form_message = MessageForm()

    # Если отправлена форма постинга
    if request.method == 'POST' and form_topic.validate_on_submit() and form_message.validate_on_submit():
        # Данные из формы c применением форматирования
        data_topic = form_topic.topic.data
        data_message = message_format(form_message.message.data, True)
        # Создание темы и обновление счётчиков у пользователя
        new_topic = ForumTopic(name=data_topic, author_id=current_user.id)
        current_user.message_count += 1
        current_user.topic_count += 1
        db.session.add(new_topic)
        # Коммит в этом месте нужен, чтобы появился ID
        db.session.commit()
        # Создание сообщения
        new_mes = ForumMessage(topic_id=new_topic.id, author_id=current_user.id, text=data_message)
        db.session.add(new_mes)
        db.session.commit()
        return(redirect(url_for('topic', topic_id=str(new_topic.id))))

    # Выборка всех тем с счётчиком сообщений для каждой
    # Подзапрос
    all_topics_subq = db.session.query(
        ForumMessage.topic_id, func.count(ForumMessage.id).label('mes_count')).\
        group_by(ForumMessage.topic_id).\
        subquery()
    # Основной запрос
    all_topics = db.session.query(
        ForumTopic, all_topics_subq.c.mes_count).\
        join(all_topics_subq, ForumTopic.id == all_topics_subq.c.topic_id).\
        order_by(ForumTopic.time_last.desc()).all()

    # Вернуть страницу
    return(render_template('forum.html',
        user=current_user,
        all_topics=all_topics,
        form_topic=form_topic,
        form_message=form_message,
        pagination=pagination))
開發者ID:smartpony,項目名稱:forum,代碼行數:49,代碼來源:views.py

示例5: new_topic

def new_topic():
    """
    Starts a new thread creating a new Topic and corresponding first Post in the database.
    """
    form = TopicForm(request.form)
    if form.validate_on_submit():
        topic = Topic(subject=form.subject.data)
        post = Post(message=form.message.data, ip_address=request.remote_addr, name=form.name.data,
                    email=form.email.data)
        topic.first_post = post
        post.topic = topic
        db.session.add(topic)
        db.session.commit()
        return redirect(url_for('view_topic', topic_id=topic.id))
    return render_template('new_topic.html', form=form)
開發者ID:ruipacheco,項目名稱:fruitshow,代碼行數:15,代碼來源:views.py

示例6: add_topic

def add_topic(request):
    '''Add a new topic'''
    tform = None
    if request.method == 'POST':
        tform = TopicForm(request.POST)
        if tform.is_valid():
            t = tform.save()
            'If topic was added successfully, send them to that topic page'
            return goto_topic(t, 'Now you can start adding options')
    
    if not tform:
        tform = TopicForm()

    return render_to_response('dovote/add_topic.html',
                              dict(tform=tform),
                              context_instance=RequestContext(request))
開發者ID:ngkabra,項目名稱:DoVote,代碼行數:16,代碼來源:views.py

示例7: post

 def post(self):
     node_id = force_int(self.get_argument('node_id', 0), 0)
     node = Node.get(id=node_id)
     user = self.current_user
     form = TopicForm(self.request.arguments)
     if form.validate():
         topic = form.save(user=user)
         topic.put_notifier()
         result = {'status': 'success', 'message': '主題創建成功',
                   'topic_url': topic.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(**result)
         return self.redirect(topic.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("topic/create.html", form=form, node=node)
開發者ID:ljtyzhr,項目名稱:collipa,代碼行數:17,代碼來源:topic.py

示例8: chat

def chat(user):
    # Creating new topics.
    if request.method == 'POST':
        if user.topics_full():
            return render_template('/index.html', topics=get_topics(), full=True,
                    user=user.user)
        form = TopicForm(request.form)
        if form.validate():
            form.add(user.user)
        return render_template('/index.html', topics=get_topics(), form=form,
                user=user.user)
    
    # Deleting topics.
    if request.method == 'GET' and request.args.get('del_topic', False):
        user.del_topic(request.args['del_topic'])
    form = TopicForm()
    return render_template('/index.html', topics=get_topics(), form=form,
            user=user.user)
開發者ID:claudiay,項目名稱:slothchat,代碼行數:18,代碼來源:views.py

示例9: post

 def post(self, topic_id):
     if not self.has_permission:
         return
     topic = Topic.get(id=topic_id)
     if not topic:
         return self.redirect_next_url()
     user = self.current_user
     form = TopicForm(self.request.arguments)
     if form.validate():
         topic = form.save(user=user, topic=topic)
         result = {'status': 'success', 'message': '主題修改成功',
                 'topic_url': topic.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect(topic.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("topic/create.html", form=form, node=topic.node)
開發者ID:SunnyKale,項目名稱:collipa,代碼行數:19,代碼來源:topic.py

示例10: get

 def get(self):
     node_id = force_int(self.get_argument('node_id', 0), 0)
     node = Node.get(id=node_id)
     if node:
         selected = node.name
     else:
         selected = None
     choices = Node.get_node_choices()
     form = TopicForm.init(choices=choices, selected=selected)
     return self.render("topic/create.html", form=form, node=node)
開發者ID:ljtyzhr,項目名稱:collipa,代碼行數:10,代碼來源:topic.py

示例11: get

 def get(self, topic_id):
     topic = Topic.get(id=topic_id)
     if topic and (topic.author == self.current_user or self.current_user.is_admin):
         selected = topic.node.name
     else:
         return self.redirect_next_url()
     choices = Node.get_node_choices()
     args = {'node_name': [selected], 'title': [topic.title], 'content':
             [topic.content]}
     form = TopicForm.init(choices=choices, selected=selected, args=args)
     return self.render("topic/create.html", form=form, node=topic.node)
開發者ID:ClayMoreBoy,項目名稱:collipa,代碼行數:11,代碼來源:topic.py

示例12: add_topic

def add_topic(request, event_id):
    e = Event.objects.get(id=event_id)

    if request.method == 'POST':
        f = TopicForm(request.POST)
        if f.is_valid():
            t = f.save(commit=false)#not push yet.
            #more values... to event yes.
            t.event = e
            t.save()
            return HttpResponseRedirect('/event/get/%s' % event_id)
    else:
        f=TopicForm()
    args ={}
    args.update(csrf(request))

    args['article']=a
    args['form']=f

    return render_to_response('add_topic.html',args)
開發者ID:adnpv,項目名稱:ILConfs-cld,代碼行數:20,代碼來源:views.py

示例13: bbs_add_topic

def bbs_add_topic():
    node_str = urllib.unquote(request.args.get('node', "").strip())
    node = None
    if node_str:
        node = Node.query.filter(Node.name==node_str).first()
        if not node:
            return render_template("node_not_found.html", next=url_for('.bbs_add_topic'), name=node_str)

    form = TopicForm(request.form)
    form.node.choices = Section.query.get_all_nodes()
    if node_str:
        form.node.data=node.title
    if request.method == 'POST' and form.validate():
        if not node:
            node = Node.query.filter(Node.title==form.data["node"].strip()).first()
            if not node:
                form.node.errors.append(u"節點不存在!")
                return render_template("add_topic.html", form=form)
        section = node.section
        topic = Topic(user=current_user, title=form.data['title'].strip(), content=form.data["content"],
                    tags=form.data["tags"], created=datetime.now(), last_modified=datetime.now(),
                    last_reply_at=datetime.now())
        topic.section = section
        topic.node = node

        #db.session.add(topic)
        node.topic_count += 1
        #db.session.add(node)
        section.topic_count += 1
        #db.session.add(section)
        current_user.profile.topics += 1
        db.session.add_all([topic, node, section, current_user.profile])
        db.session.commit()
        return redirect(url_for(".bbs_topic", id=topic.id))
    if node_str:
        action_url = url_for(".bbs_add_topic", node=node_str)
    else:
        action_url = url_for(".bbs_add_topic")
    return render_template("add_topic.html", form=form, action_url=action_url)
開發者ID:FashtimeDotCom,項目名稱:flaskbbs,代碼行數:39,代碼來源:views.py

示例14: get

 def get(self, topic_id):
     if not self.has_permission:
         return
     topic = Topic.get(id=topic_id)
     if topic:
         selected = topic.node.name
     else:
         return self.redirect_next_url()
     choices = Node.get_node_choices()
     args = {'node_name': [selected], 'title': [topic.title], 'content':
             [topic.content]}
     form = TopicForm.init(choices=choices, selected=selected, args=args)
     return self.render("topic/create.html", form=form, node=topic.node)
開發者ID:SunnyKale,項目名稱:collipa,代碼行數:13,代碼來源:topic.py

示例15: new

def new(request):
    if request.method == 'POST':
        topic_form = TopicForm(request.POST)
        post_form = PostForm(request.POST)

        if topic_form.is_valid() and post_form.is_valid():
            topic = topic_form.save()
            post = post_form.save(commit=False)
            post.topic = topic
            post.author = request.user
            post.save()
            return redirect('/forum/%d' % topic.id)
    else:
        topic_form = TopicForm()
        post_form = PostForm()

    return render_to_response('forum/new.html',
                              {
                                  'topic_form': topic_form,
                                  'post_form': post_form
                              },
                              context_instance=RequestContext(request))
開發者ID:Exide,項目名稱:django-luna,代碼行數:22,代碼來源:views.py


注:本文中的forms.TopicForm類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。