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


Python Post.query方法代码示例

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


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

示例1: panel

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
def panel(page=1):
    user = g.user
    #can't just use user as it is type <class 'werkzeug.local.LocalProxy'>
    #better way of doing this?
    awaiting_comments = {}
    post_awaiting_comments = []
    #paginate comments? what if there's 50 comments?
    #author = User.objects(id=user.id)[0] User.get_by_id(int(id))
    #author = User.get_by_id(int(user.key.id()))
    #Post.objects
    ##for i in Post.all().filter('author =', author).filter(comments__approved=False):
    ##    post_awaiting_comments = post_awaiting_comments + i.get_comments_awaiting()
    ##    awaiting_comments[i] = post_awaiting_comments
    ##    post_awaiting_comments = []
    #posts = Post.objects(author=author).paginate(page=page, per_page=POSTS_PER_PAGE)
    #posts = Post.all().filter('author =', author).order('-created_at').run(limit=POSTS_PER_PAGE)
    query = Post.query(Post.author == ndb.Key(User, int(user.key.id()))). \
        order(-Post.created_at)
    if page == 1:
        posts, cursor, more = query.fetch_page(POSTS_PER_PAGE)
        g.cursor = cursor
    else:
        if g.cursor:
            posts, cursor, more = query.fetch_page(POSTS_PER_PAGE, cursor)
    return render_template('users/panel.html',
        user=user,
        pagination=posts,
        comments=awaiting_comments)
开发者ID:ardinor,项目名称:mojibake-gae,代码行数:30,代码来源:views.py

示例2: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
 def get(self, username):
     user = User.user_by_name(username)
     posts = Post.query(ancestor=user.key).order(-Post.created).fetch(10)
     if self.format == 'html':
         self.render('blog.html', posts=posts)
     else:
         self.render_json(d=[post.serialize for post in posts])
开发者ID:MatthewBenjamin,项目名称:fsnd-blog,代码行数:9,代码来源:blog.py

示例3: test_can_get_edit_url

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
    def test_can_get_edit_url(self):
        self.login("[email protected]", admin=True)
        self._create_test_posts()

        test_post = Post.query().get()

        self.app.get(test_post.get_edit_url(), status=200)
开发者ID:tombatron,项目名称:tombatron-com,代码行数:9,代码来源:model_tests.py

示例4: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
    def get(self):
        posts = []
        cookie_user = self.get_user_from_cookie()
        if cookie_user:
            loggedin_user = cookie_user
        else:
            loggedin_user = None

        posts = Post.query(Post.is_draft == False).order(-Post.created)
        all_users = User.query()
        likes = Likes.query()

        list_dict = []

        for p in posts:
            p_dict = {}
            for u in all_users:
                if p.user == u.key:
                    p_dict['p_id'] = p.key.id()
                    p_dict['p_title'] = p.title
                    p_dict['p_content'] = p.content
                    p_dict['p_created'] = p.created
                    p_dict['a_name'] = u.fullname
                    p_dict['a_key'] = u.key
                    p_dict['a_id'] = u.key.id()
            for l in likes:
                if l.post == p.key:
                    p_dict['like_count'] = l.like_count
            comment_count = Comments.query(Comments.post == p.key).count()
            p_dict['c_count'] = comment_count
            list_dict.append(p_dict)

        return self.render('home.html', user=loggedin_user,
                           list_dict=list_dict)
开发者ID:ghoshabhi,项目名称:Multi-User-Blog,代码行数:36,代码来源:home_handler.py

示例5: load_user

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
def load_user():
    """Load currently logged in user and their current (today's) post, or a login URL if user is not logged in"""
    user = None
    user_post = None
    login_url = None
    
    try:
        if session['user']:
            user = User.get_by_id(session['user'])
    except KeyError:
        pass
    
    if user:
        try:
            user_post = Post.query(Post.posted_date==datetime.today(),Post.user==user.key).get()
        except IndexError:
            pass
    else:
        reddit = get_reddit()
        login_url = reddit.get_authorize_url(str(uuid4()),['identity','submit'],refreshable=True)

    g.user = user
    g.user_post = user_post
    g.login_url = login_url
    g.ga_id = app.config['GA_ID']
开发者ID:arunanm,项目名称:daily3,代码行数:27,代码来源:views.py

示例6: index

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
def index(page):
    #post_count = Post.query().fetch().count(100)  # limit=0
    p = Post.query(Post.visible == True).order(-Post.created_at)
    #if page > 1:
    #    page_offset = (page - 1) * POSTS_PER_PAGE
    #    posts = Post.query().filter("visible =", True).order("-created_at").run(offset=page_offset, limit=POSTS_PER_PAGE)
    #else:
        #posts = Post.query().filter("visible =", True).order("-created_at").run(limit=POSTS_PER_PAGE)
    #    posts = Post.query(Post.visible == True).order(-Post.created_at).fetch(limit=POSTS_PER_PAGE)
    #if not posts and page != 1:
    #    abort(404)
    #pagination = Pagination(page, POSTS_PER_PAGE, post_count)

    if page == 1:
        posts, cursor, more = p.fetch_page(POSTS_PER_PAGE)
        session['cursor'] = cursor.urlsafe()
    else:
        if 'cursor' in session:
            cursor = Cursor(urlsafe=session['cursor'])
            posts, cursor, more = p.fetch_page(POSTS_PER_PAGE, start_cursor=cursor)
            session['cursor'] = cursor


    #recent = Post.objects(visible=True).order_by('-created_at')[:5]
    return render_template("posts/list.html",
        posts=posts,
        more=more,
        pagination=''
        )  # recent=recent
开发者ID:ardinor,项目名称:mojibake-gae,代码行数:31,代码来源:views.py

示例7: idonotknow

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
def idonotknow(noun):
    posts = Post.query().filter(Post.category.IN([noun])).order(-Post.date)
    tagged_posts = Post.get_tagged_post(noun)
    return render_template('idonotknow.html',
                           noun=noun,
                           posts=posts,
                           tagged_posts=tagged_posts)
开发者ID:anthond,项目名称:blog-1,代码行数:9,代码来源:main.py

示例8: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
 def get(self):
     post_query = Post.query().order(-Post.time).fetch()
     place_query = Place.query().fetch()
     time = None
     for post in post_query:
         time = post.time.strftime("%a %d-%b-%Y %H:%M")
     self.render_template('index.html',{'posts':post_query, 'time':time, 'places': place_query})
开发者ID:crumpledpaper,项目名称:singgest,代码行数:9,代码来源:main.py

示例9: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
    def get(self, _id=None):
        size = self.request.get_range('size') or 10
        cursor = self.request.get('cursor') or None

        if not _id:
            posts, next_curs, more = Post.query(share=True).fetch_page(size, start_cursor=cursor)
        elif _id == 'me':
            posts, next_curs, more = Post.query(author=User.get_by_id(self.session['user'].email)).fetch_page(size, start_cursor=cursor)
        else:
            posts = [Post.get_by_id(_id)]
            next_curs = None
            more = False
        
        posts = [post.to_json() for post in posts]
        
        self.JsonResponse({"posts":posts, "more":more, "next_cursor": next_cursor})
开发者ID:georgefs,项目名称:ezselector,代码行数:18,代码来源:views.py

示例10: update

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
    def update(self):
        post = Post.query().get()
        if post:
            post.title = '%s *UPDATED*' % post.title
            post.put()

        return self.redirect_to('index')
开发者ID:ozburo,项目名称:babushka,代码行数:9,代码来源:handlers.py

示例11: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
def post(title=None, category=None):
    if title:
        post = Post.query(Post.title==title).get()
    else:
        post = Post.get_1lastest(category=category)

    if not post:
        return redirect(url_for("notfound", title=title))
		
    pre_post = post.get_pre(category=category)
    next_post = post.get_next(category=category)
    content, toc = md2html(post.content)

    last_posts = Post.get_lastest()
    
    txt = noTag(noTag(toc, 'div'), 'ul')
    toc = toc if txt.strip() else ''

    return render_template('post.html',
                           post=post,
                           last_posts=last_posts,
                           category=category,
                           pre_post=pre_post,
                           next_post=next_post,
                           toc=toc,
                           content=content)
开发者ID:brenden17,项目名称:blog,代码行数:28,代码来源:main.py

示例12: me

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
def me():
    posts = None
    if g.user:
        profile = g.user
        posts = Post.query(Post.user==profile.key).order(-Post.posted).fetch()
        return render_template('user_profile.html', profile=profile, posts=posts)
    else:
        return redirect(url_for('home'))
开发者ID:arunanm,项目名称:daily3,代码行数:10,代码来源:views.py

示例13: user_profile

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
def user_profile(username):
    posts = None
    profile = User.get_by_id(username)
    if profile:
        posts = Post.query(Post.user==profile.key).order(-Post.posted).fetch()
        return render_template('user_profile.html', profile=profile, posts=posts)
    else:
        abort(404)
开发者ID:arunanm,项目名称:daily3,代码行数:10,代码来源:views.py

示例14: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
 def get(self):
     posts = Post.query(Post.published == True).order(-Post.create)
     values = {
     'posts': posts.fetch(10),
     'update': posts.get().create,
     }
     self.response.headers['Content-Type'] = 'application/xml'
     self.generate('bacheca/atom.xml', values)
开发者ID:presveva,项目名称:tornei_all_italiana,代码行数:10,代码来源:bacheca.py

示例15: home

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import query [as 别名]
def home(request, category_slug):
    """
        Homepage

        @param request Incoming HTTP request
        @param category_slug (optional) Incoming category_slug (used in the request URL.)
    """
    # find category if passed into the request
    categories, statuses_to_display, archives, blogroll = common(request.user.is_authenticated())

    article_post_index = 0
    if 'start' in request.GET:
        article_post_index = int(request.GET['start'])

    search_tags = []
    selected_category = None

    if category_slug:
        for category in categories:
            if category.tag.slug == category_slug:
                search_tags.append(category.tag)
                selected_category = category

        # check if this is a tag
        if selected_category is None:
            try:
                search_tag = Tag.objects.get(slug=category_slug)
                search_tags.append(search_tag)
            except:
                print "No tag found for given slug '" + category_slug

    all_posts = Post.query(statuses_to_display,
                           search_tags
                           )

    # cap post start and end ranges based on available posts
    posts, first_post_id, next_post_index, prev_post_index = cull_posts(
                    all_posts,
                    article_post_index,
                    settings.CK_METABLOG_PER_PAGE_COUNT)

    context = {
        'page_title': settings.CK_SITE_TITLE,
        'categories': categories,
        'selected_category': selected_category,
        'blog_posts': posts,
        'archives': archives,
        'blogroll': blogroll,
        'first_post_id': first_post_id,
        'next_post_index': next_post_index,
        'prev_post_index': prev_post_index,
        'allow_rss_feed': True,
    }

    # render
    return render_to_response("home.html",
                              context,
                              context_instance=RequestContext(request))
开发者ID:samkusin,项目名称:django-metablog,代码行数:60,代码来源:views.py


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