當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。