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


Python Post.all方法代码示例

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


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

示例1: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
  def get(self, user):
    page = helper.sanitizeHtml(self.request.get('pagina'))
    target_user_str= helper.sanitizeHtml(helper.parse_post_id(user))
    perPage = 20
    page = int(page) if page else 1
    realPage = page - 1
    if realPage > 0:
      prevPage = realPage

    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
    target_user = User.all().filter('lowercase_nickname =', target_user_str).fetch(1)
    if len(target_user) > 0:
      posts = Post.all().filter('user =',target_user[0]).order('-created').fetch(perPage,perPage * realPage)
      if (page * perPage) < Post.all().filter('user =',target_user[0]).order('-created').count():
        nextPage = page + 1
      prefetch.prefetch_posts_list(posts)
      i = perPage * realPage + 1
      for post in posts:
        post.number = i
        i = i + 1
      if helper.is_json(self.request.url):
        posts_json = [p.to_json() for p in posts]
        if(self.request.get('callback')):
          self.response.headers['Content-Type'] = "application/javascript"
          self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'posts':posts_json})+');')
        else:
          self.response.headers['Content-Type'] = "application/json"
          self.response.out.write(simplejson.dumps({'posts':posts_json}))
      else:
        self.response.out.write(template.render('templates/main.html', locals()))
    else:
      self.redirect('/')
开发者ID:mantus,项目名称:Noticias-HAcker,代码行数:36,代码来源:main.py

示例2: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
    def post(self):
        session = get_current_session()
        url = self.request.get("url")
        title = helper.sanitizeHtml(self.request.get("title"))
        message = helper.sanitizeHtml(self.request.get("message"))
        nice_url = helper.sluglify(title)

        if session.has_key("user"):
            if len(nice_url) > 0:
                user = session["user"]
                if len(message) == 0:  # is it a post or a message?
                    # Check that we don't have the same URL within the last 'check_days'
                    since_date = date.today() - timedelta(days=7)
                    q = Post.all().filter("created >", since_date).filter("url =", url).count()
                    url_exists = q > 0
                    q = Post.all().filter("nice_url", nice_url).count()
                    nice_url_exist = q > 0
                    try:
                        if not url_exists:
                            if not nice_url_exist:
                                post = Post(url=url, title=title, message=message, user=user, nice_url=nice_url)
                                post.put()
                                vote = Vote(user=user, post=post, target_user=post.user)
                                vote.put()
                                Post.remove_cached_count_from_memcache()
                                self.redirect("/noticia/" + str(post.nice_url))
                            else:
                                session["post_error"] = "Este titulo ha sido usado en una noticia anterior"
                                self.redirect("/agregar")
                        else:
                            session["post_error"] = "Este link ha sido entregado en los ultimo 7 dias"
                            self.redirect("/agregar")
                    except db.BadValueError:
                        session["post_error"] = "El formato del link no es valido"
                        self.redirect("/agregar")
                else:
                    q = Post.all().filter("nice_url", nice_url).count()
                    nice_url_exist = q > 0
                    if not nice_url_exist:
                        post = Post(title=title, message=message, user=user, nice_url=nice_url)
                        post.put()
                        post.url = helper.base_url(self) + "/noticia/" + post.nice_url
                        post.put()
                        Post.remove_cached_count_from_memcache()
                        vote = Vote(user=user, post=post, target_user=post.user)
                        vote.put()
                        self.redirect("/noticia/" + post.nice_url)
                    else:
                        session["post_error"] = "Este titulo ha sido usado en una noticia anterior"
                        self.redirect("/agregar")
            else:
                session["post_error"] = "Necesitas agregar un titulo"
                self.redirect("/agregar")
        else:
            self.redirect("/login")
开发者ID:zetta,项目名称:Noticias-HAcker,代码行数:57,代码来源:SubmitNewStoryHandler.py

示例3: list_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
def list_post(request):
    posts = None
    if not is_admin():
        posts = Post.all().filter("is_published", True).order("-create_time")
    else:
        posts = Post.all().order("-create_time")
    return object_list(
        request,
        queryset=posts,
        allow_empty=True,
        template_name="list_post.html",
        extra_context={"is_author": is_author()},
        paginate_by=settings.POST_LIST_PAGE_SIZE,
    )
开发者ID:ytrstu,项目名称:niubi,代码行数:16,代码来源:views.py

示例4: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
    def get(self, year=None, month=None, day=None, slug=None, tag=None):
        datestart = datetime.date.min
        dateend = datetime.date.min

        if year:
            datestart = datestart.replace(year=year)
            dateend = dateend.replace(year=year+1)
        if month:
            datestart = datestart.replace(month=month)
            if month == 12:
                dateend = dateend.replace(year=year+1)
                dateend = dateend.replace(month=1)
            else:
                dateend = dateend.replace(month=month+1)
        if day:
            datestart = datestart.replace(day=day)
            one_day = datetime.timedelta(days=1)
            dateend = datestart + one_day

        print datetime.datetime.now()
        print datetime.datetime.utcnow()
        print datetime.datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone('Asia/Singapore'))

        posts = Post.all()\
                    .filter('datecreated >=', datestart)\
                    .filter('datecreated <', dateend)

        return render_template('blog/list.html', posts=posts)
开发者ID:azmikamis,项目名称:codercolumbus,代码行数:30,代码来源:blog.py

示例5: get

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

        items = []
        for post in posts:
            items.append(
                PyRSS2Gen.RSSItem(
                    title=post.title,
                    link="http://noticiashacker.com/noticia/" + str(post.key()),
                    description="",
                    guid=PyRSS2Gen.Guid("guid1"),
                    pubDate=post.created,
                )
            )

        rss = PyRSS2Gen.RSS2(
            title="Noticias Hacker",
            link="http://noticiashacker.com/",
            description="",
            lastBuildDate=datetime.now(),
            items=items,
        )
        print "Content-Type: text/xml"
        self.response.out.write(rss.to_xml("utf-8"))
开发者ID:manelik,项目名称:arXiv-news,代码行数:27,代码来源:main.py

示例6: list_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
def list_post(request):
    posts = Post.all().order('-create_time')
    if (not is_admin()):
        posts = posts.filter("is_published", True)  
    return object_list(request, queryset=posts, allow_empty=True,
            template_name='list_post.html', extra_context={'is_author': is_author()},
            paginate_by=settings.POST_LIST_PAGE_SIZE)  
开发者ID:lvbeck,项目名称:niubi,代码行数:9,代码来源:views.py

示例7: history

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
def history():
	show_count = 50
	startPage = int(request.args.get('page', 1))

	prevpage = startPage - 1
	if prevpage <= 0:
		prevpage = None
	nextpage = startPage + 1

	startOffset = startPage * show_count - show_count
	nextOffset = nextpage * show_count - show_count

	heekPost = PostRoot(key_name='heek', version=2)
	query = Post.all()
	query.ancestor(heekPost)
	query.order('-datetime')


	rows = [dict(text=post.text) for post in query.run(offset=startOffset, limit=show_count)]

	next_cnt = query.count(offset=nextOffset, limit=show_count)
	if next_cnt == 0:
		nextpage = None

	return render_template('history.html', contents=rows, prevpage=prevpage, nextpage=nextpage)
开发者ID:jangjunha,项目名称:heek-satcounter,代码行数:27,代码来源:main.py

示例8: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
  def get(self,post_id):
    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
    
    try:
      post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
      if  post  == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
        post = db.get( helper.parse_post_id( post_id ) ) 

      comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000)
      comments = helper.order_comment_list_in_memory(comments)
      prefetch.prefetch_comment_list(comments)
      display_post_title = True
      prefetch.prefetch_posts_list([post])
      if helper.is_json(post_id):
        comments_json = [c.to_json() for c in comments if not c.father_ref()] 
        if(self.request.get('callback')):
          self.response.headers['Content-Type'] = "application/javascript"
          self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'post':post.to_json(),'comments':comments_json})+')')
        else:
          self.response.headers['Content-Type'] = "application/json"
          self.response.out.write(simplejson.dumps({'post':post.to_json(),'comments':comments_json}))
      else:
        self.response.out.write(template.render('templates/post.html', locals()))
    except db.BadKeyError:
      self.redirect('/')
开发者ID:chubas,项目名称:Noticias-HAcker,代码行数:29,代码来源:PostHandler.py

示例9: show_entries

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
def show_entries():
    user = users.get_current_user()
    if user:
        session["logged_in"] = True

    posts = Post.all()
    return render_template("show_entries.html", entries=posts)
开发者ID:rbastian,项目名称:gae-flaskr-gauth,代码行数:9,代码来源:views.py

示例10: get_context_data

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
    def get_context_data(self, *args, **kwargs):

        ctx = super(PostList, self).get_context_data(*args, **kwargs)

        page = self.request.GET.get('p', 1)

        if self.request.user.is_authenticated():
            objects = Post.all().order("-post_date")
        else:
            objects = Post.published().order("-post_date")


        pager = Paginator(objects, PAGE_SIZE)

        try:
            page_obj = pager.page(page)
        except InvalidPageException:
            raise Http404

        ctx.update({
            'paginator': pager,
            'page_obj': page_obj,
        })

        return ctx
开发者ID:sleepyjames,项目名称:sleepyjames-aeblog,代码行数:27,代码来源:views.py

示例11: index

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
def index(page = 1):
    user = g.user
    posts = [
        { 
            'author': { 'nickname': 'John' }, 
            'body': 'Beautiful day in Portland!' 
        },
        { 
            'author': { 'nickname': 'Susan' }, 
            'body': 'The Avengers movie was so cool!' 
        }
    ]

    posts = Post.query.order_by(desc(Post.created)).paginate(page, POSTS_PER_PAGE, False).items
    pagination = Pagination(page=page, 
                    total=len(Post.all()), 
                    per_page=POSTS_PER_PAGE, 
                    search=False,
                    css_framework='bootstrap3', 
                    record_name='posts')
    return render_template('index.html',
    posts = posts,
    user = user,
    pagination=pagination,
    )
开发者ID:neukzhou,项目名称:flaskblog,代码行数:27,代码来源:views.py

示例12: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
  def get(self):
    posts = Post.all().order('-created').fetch(20)
    prefetch.prefetch_posts_list(posts)

    items = []
    for post in posts:
      if len(post.message) == 0:
        rss_poster = '<a href="'+post.url+'">'+post.url+'</a>'
      else:
        rss_poster = post.message
      rss_poster += ' por <a href="'+helper.base_url(self)+'/perfil/'+post.user.nickname+'">'+post.user.nickname+'</a>'

      link = helper.base_url(self)+'/noticia/' + str(post.key())
      if post.nice_url:
        link = helper.base_url(self)+'/noticia/' + str(post.nice_url)

      items.append(PyRSS2Gen.RSSItem(
          title = post.title,
          link = link,
          description = rss_poster,
          guid = PyRSS2Gen.Guid("guid1"),
          pubDate = post.created
      ))

    rss = PyRSS2Gen.RSS2(
            title = "Noticias Hacker",
            link = "http://noticiashacker.com/",
            description = "Noticias Hacker",
            lastBuildDate = datetime.now(),
            items = items
          )
    print 'Content-Type: text/xml'
    self.response.out.write(rss.to_xml('utf-8'))
开发者ID:DFectuoso,项目名称:Noticias-HAcker,代码行数:35,代码来源:RssHandler.py

示例13: delete_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
    def delete_post(cls, post_id, user_id):
        error_msg = None
        posts = Post.all().order('-created').fetch(limit=10)
        updated_post_list = posts
        post = Post.get_by_id(post_id)
        if user_id == post.created_by:

            # delete comments of the post
            comments = Comment.all().filter('post_id =', post_id).fetch(limit=10)
            for c in comments:
                Comment.delete(c)

            # delete likes of the post
            likes = Like.all().filter('post_id =', post_id).fetch(limit=10)
            for l in likes:
                Like.delete(l)

            # delete the post
            updated_post_list = cls.update_list_on_delete(
                object_list=posts,
                object_id=post_id
            )
            Post.delete(post)

        else:
            error_msg = 'You can delete only your own posts'

        return updated_post_list, error_msg
开发者ID:daliavi,项目名称:udacity-blog,代码行数:30,代码来源:service.py

示例14: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
  def post(self, post_id):
    session = get_current_session()
    if session.has_key('user'):
      message = helper.sanitizeHtml(self.request.get('message'))
      user = session['user']
      key = self.request.get('comment_key')
      if len(message) > 0 and key == keys.comment_key:
        try:
          post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
          if post  == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
            post = db.get( helper.parse_post_id( post_id ) ) 

          post.remove_from_memcache()
          comment = Comment(message=message,user=user,post=post)
          comment.put()
          helper.killmetrics("Comment","Root", "posted", session, "",self)
          vote = Vote(user=user, comment=comment, target_user=user)
          vote.put()
          Notification.create_notification_for_comment_and_user(comment,post.user)
          self.redirect('/noticia/' + post_id)
        except db.BadKeyError:
          self.redirect('/')
      else:
        self.redirect('/noticia/' + post_id)
    else:
      self.redirect('/login')
开发者ID:grillermo,项目名称:Noticias-HAcker,代码行数:28,代码来源:PostHandler.py

示例15: get_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import all [as 别名]
def get_post(slug):
    q = Post.all()
    q.filter("slug =", slug)
    post = q.get()
    if post is not None:
        return render_template('post.html', post=post)
    else:
        return render_template('404.html'), 404
开发者ID:spanners,项目名称:flask-stripe-registration,代码行数:10,代码来源:views.py


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