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


Python BlogPost.all方法代码示例

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


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

示例1: __init__

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
    def __init__(self):
        """load basic members using memcache"""
        logging.info("initialized")
        self.posts_tags_db=[]
        self.catdict={}
        self.posts_tags_dict={}
        self.posts=memcache.get(KEY)

      
        if self.posts is None:
            logging.info('cache is empty creating index')
            self.posts = BlogPost.all().order('-timestamp')
   
            createIndex(self.posts)
            memcache.add(KEY,self.posts)
        if isinstance(self.posts,list):self.nofposts=len(self.posts)-2
        else:self.nofposts=self.posts.count()-2
        self.tags=memcache.get(TAG)
        if self.tags is None:
            self.tags = Tag.all()
            memcache.add(TAG,self.tags)
        self.categories=memcache.get(CATEGORY)
        if self.categories is None:
            self.categories= Category.all()
            memcache.add(CATEGORY,self.categories)

        for post in self.posts:
            logging.info(['posts',post.title])
            self.posts_tags_db.extend(post.tags)
            tags=[]
            for key in post.tags:tags.append(db.get(key).tag)
            self.posts_tags_dict[post.key()]=tags
            self.catdict[post.category.key()]=post.category.category
        logging.info(['catdict',self.catdict])
        self.tagnames=list(chain.from_iterable(self.posts_tags_dict.values()))
开发者ID:,项目名称:,代码行数:37,代码来源:

示例2: get

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
    def get(self):
        posts = BlogPost.all().order("-date_created")

        return {
            "admin_section": "admin-blog-posts",
            "posts": posts,
        }
开发者ID:ashenwolf,项目名称:skoll-tech-portfolio,代码行数:9,代码来源:views_admin.py

示例3: get

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
 def get(self,page):
     posts = BlogPost.all().order('-pub_date').fetch(limit=10)
     self.templ_vals.update({
         'url':users.create_logout_url("/"),
         'posts':posts,
     })
     self.render_to_response('index.html',self.templ_vals)
开发者ID:yanzay,项目名称:pagankolo,代码行数:9,代码来源:main.py

示例4: refetch

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
 def refetch(self):
     self.posts =BlogPost.all().order('-timestamp')
     memcache.add(KEY,self.posts)
     self.tags = Tag.all()
     memcache.add(TAG,self.tags)
     self.categories= Category.all()
     memcache.add(CATEGORY,self.categories)
     createIndex(self.posts)
开发者ID:,项目名称:,代码行数:10,代码来源:

示例5: get

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
    def get(self, category = None):
        cur_category = None
        categories = BlogCategory.all()

        if category:
            cur_category = BlogCategory.all().filter("slug =", category).get()
            posts = BlogPost.all().filter("category =", cur_category).order("-date_created")
        else:
            posts = BlogPost.all().order("-date_created")
            cur_category = None

        return {
            "section": "blog",
            "posts": posts,
            "cur_category": cur_category,
            "categories": categories,
        }
开发者ID:ashenwolf,项目名称:skoll-tech-portfolio,代码行数:19,代码来源:views.py

示例6: getrecentposts

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def getrecentposts(limit=5):
    """ Get html for the [num] most recent posts.
        Return a list of (title, html) tuples. """
        
    q = BlogPost.all()
    q.order('post_date')
    posts = [(post.title, post.html) for post in q.run(limit=limit)]
    return posts
开发者ID:rlmv,项目名称:mysite,代码行数:10,代码来源:db.py

示例7: generate_resource

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
    def generate_resource(cls, post, resource):
        from models import BlogPost

        # Query all posts, and filter out drafts.
        q = BlogPost.all().order("-published")
        q.filter("published !=", datetime.datetime.max)

        html = utils.render_template("labnotes.html", {"generator_class": cls.__name__, "posts": q})
        static.set("/labnotes", html, config.html_mime_type)
开发者ID:gui11aume,项目名称:genomearchitecturelab,代码行数:11,代码来源:generators.py

示例8: getblogpost

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def getblogpost(title):
    """ Get a blog post titled 'title' from the data store.
        Must be an exact match. """
    q = BlogPost.all()
    q.filter("title =", title.lower())
    try:
        post = q.get()
        return post.title, post.html 
    except AttributeError:
        return None
开发者ID:rlmv,项目名称:mysite,代码行数:12,代码来源:db.py

示例9: generate_resource

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
    def generate_resource(cls, post, resource):
        from models import BlogPost

        # Query all posts, and filter out drafts.
        q = BlogPost.all().order("-published")
        q.filter("published !=", datetime.datetime.max)
        by_year = {}
        for post in q:
            by_year.setdefault(post.published.year, []).append(post)

        html = utils.render_template(
            "archive.html",
            {"generator_class": cls.__name__, "by_year": [by_year[y] for y in sorted(by_year, reverse=True)]},
        )
        static.set("/archive/", html, config.html_mime_type)
开发者ID:gui11aume,项目名称:thegrandlocus,代码行数:17,代码来源:generators.py

示例10: handleApost

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def handleApost(id):
    posts=memcache.get(KEY)
    tags=memcache.get(TAG)
    categories=memcache.get(CATEGORY)
        
    if not posts:
      
        posts = BlogPost.all().order("-timestamp").fetch(20)
        memcache.add(KEY,posts)

    if not tags:
        tags = Tag.all().fetch(20)
        memcache.add(TAG,tags)
    if not categories:
        categories= Category.all().fetch(20)
        memcache.add(CATEGORY,categories)
        
    obj=BlogPost.get_by_id(int(id))
    tagkeys=obj.tags
    
    if request.method=="GET":
        apost=APost(id=id)
        data=apost.retrieve()
        return jsonify(msg="OK",posts=data)
    elif users.is_current_user_admin() and request.method=="DELETE":
        apost=APost(id=id)
        apost.delete()
        return jsonify(msg="OK")
        
    elif  users.is_current_user_admin() and request.method=="PUT":
        title=request.json['title']
        body=request.json['body']
        date=request.json['date']
        category=request.json['category']
        posttags=request.json['tags']
        apost=APost(title,body,date,category,posttags,id)
        (data,returnedTags)=apost.update()
       
            
       
        return jsonify(msg="OK",tags=returnedTags,posts=data)
开发者ID:,项目名称:,代码行数:43,代码来源:

示例11: action

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def action(id=None):
    if 'posts' not in globals():
        global posts
        
    posts=memcache.get(KEY)
    tags=memcache.get(TAG)
    categories=memcache.get(CATEGORY)
        
    if not posts:
      
        posts = BlogPost.all().order("-timestamp").fetch(20)
        memcache.add(KEY,posts)

    if not tags:
        tags = Tag.all().fetch(20)
        memcache.add(TAG,tags)
    if not categories:
        categories= Category.all().fetch(20)
        memcache.add(CATEGORY,categories)
    data=[]
    

#   
    if request.method=='GET':
      
       # posts = BlogPost.all()
       # posts.order("-timestamp")

    
           # if category=="categories":
                Categories=[] 
                [Categories.append([categoryobj.category,categoryobj.key().id()]) for categoryobj in categories]
                Categories=map(lambda category:{"category":category[0],"catid":category[1]} ,Categories)
                logging.info(Categories)
      
  
                return jsonify(msg="OK",categories=Categories,header="Categories",type="categories")
开发者ID:,项目名称:,代码行数:39,代码来源:

示例12: db_delete

# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def db_delete():
    """ Delete all blog posts in the datastore. Be careful! """

    q = BlogPost.all()
    db.delete(post.key() for post in q.run())
    logging.info("Deleting blogposts...")
开发者ID:rlmv,项目名称:mysite,代码行数:8,代码来源:db.py


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