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


Python Category.get_all方法代码示例

本文整理汇总了Python中models.Category.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python Category.get_all方法的具体用法?Python Category.get_all怎么用?Python Category.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Category的用法示例。


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

示例1: new_article

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def new_article():
    form = forms.EditArticleForm()
    media_form = get_media_form()
    form.categories.choices = [(cat.id, cat.name) for cat in Category.query.order_by('name').all()]
    if form.validate_on_submit():
        data = form.data
        categories = [Category.query.get(i) for i in data['categories']]
        article = Article(data['title'], data['pagedown'], data['description'], data['image'], categories)
        db.session.add(article)
        db.session.commit()
        return redirect(url_for('get_article', article_id=article.id))
    return render_template('edit_article.html', categories=Category.get_all(), form=form, media_form=media_form)
开发者ID:pulmro,项目名称:pulmro-blog,代码行数:14,代码来源:views.py

示例2: get_article

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def get_article(article_id):
    article = Article.query.get(article_id)
    previous_article = article.get_previous()
    article.body_html = Markup(markdown(article.body))
    next_article = article.get_next()
    link_next = {'title': None, 'url': url_for('index')} if next_article is None\
        else {'title': next_article.title, 'url': next_article.get_absolute_url()}
    link_previous = {'title': None, 'url': url_for('index')} if previous_article is None\
        else {'title': previous_article.title, 'url': previous_article.get_absolute_url()}
    comments = [comment for comment in article.comments.filter(Comment.parent_id == 0).order_by('date').all()]
    form = forms.CommentRespondForm()
    return render_template('article.html', categories=Category.get_all(), article=article, link_previous=link_previous,
                           link_next=link_next, form=form, comments=comments)
开发者ID:pulmro,项目名称:pulmro-blog,代码行数:15,代码来源:views.py

示例3: edit_article

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def edit_article(article_id):
    form = forms.EditArticleForm(request.form)
    media_form = get_media_form()
    #print form.data
    # Populate form with all available categories
    form.categories.choices = [(cat.id, cat.name) for cat in Category.query.order_by('name').all()]
    if form.validate_on_submit():
        data = form.data
        Article.query.filter_by(id=article_id).update({"title": data['title'], "body": data['pagedown'],
                                                       "description": data['description'],
                                                       "thumbnail_id": data['image']})
        Article.query.get(article_id).categories = [Category.query.get(i) for i in data['categories']]
        db.session.commit()
        return redirect(url_for('get_article', article_id=article_id))
    else:
        print form.errors
    article = Article.query.get(article_id)
    form.title.data = article.title
    form.pagedown.data = article.body
    form.description.data = article.description
    form.categories.data = [cat.id for cat in article.categories]
    if article.thumbnail:
	form.image.set_data(article.thumbnail_id, article.thumbnail.get_url())
    return render_template('edit_article.html', categories=Category.get_all(), form=form, media_form=media_form)
开发者ID:pulmro,项目名称:pulmro-blog,代码行数:26,代码来源:views.py

示例4: get_course

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def get_course(course_id):
    category = Category.query.get(course_id)
    articles = category.articles
    return render_template('category.html', category=category, articles=articles, categories=Category.get_all())
开发者ID:pulmro,项目名称:pulmro-blog,代码行数:6,代码来源:views.py

示例5: index

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
def index():
    
    #recent_articles = Article.query.order_by('created_at desc').limit(3).all()
    return render_template('index.html', categories=Category.get_all())
开发者ID:pulmro,项目名称:pulmro-blog,代码行数:6,代码来源:views.py

示例6:

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import get_all [as 别名]
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from lib.controller import Controller
from models import Category
import webapp2
import settings

categories = '|'.join(Category.get_all())
Controller.url_mapping = [
                          (r'^/([0-9]+)$', ('service', 'Article')),
                          (r'^/user/([0-9]+)$', ('user', 'Index')),
                          (r'^/user/me$', ('user', 'Index')),
                        ]
if categories:
    Controller.url_mapping.append((ur'^/(%s)$' % categories, ('service', 'Category')))

app = webapp2.WSGIApplication([('/.*', Controller)], debug=settings.DEV)
开发者ID:fguy,项目名称:openalive,代码行数:20,代码来源:bootstrap.py


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