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


Python Post.gql方法代码示例

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


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

示例1: get

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import gql [as 别名]
  def get(self):
    self.user()
    (forum, siteroot, tmpldir) = forum_siteroot_tmpldir_from_url(self.request.path_info)
    if not forum or forum.is_disabled:
      return self.redirect("/")
    forum.title_or_url = forum.title or forum.url

    topic_id = self.request.get('id')
    if not topic_id:
      return self.redirect(siteroot)

    topic = db.get(db.Key.from_path('Topic', int(topic_id)))
    if not topic:
      return self.redirect(siteroot)

    # is_moderator = users.is_current_user_admin()
    is_moderator = False
    if topic.is_deleted and not is_moderator:
      return self.redirect(siteroot)

    is_archived = False
    # Note: auto-archiving disabled
    #now = datetime.datetime.now()
    #week = datetime.timedelta(days=7)
    #week = datetime.timedelta(seconds=7)
    #if now > topic.created_on + week:
    #  is_archived = True

    # 200 is more than generous
    MAX_POSTS = 200
    if is_moderator:
      posts = Post.gql("WHERE forum = :1 AND topic = :2 ORDER BY created_on", forum, topic).fetch(MAX_POSTS)
    else:
      posts = Post.gql("WHERE forum = :1 AND topic = :2 AND is_deleted = False ORDER BY created_on", forum, topic).fetch(MAX_POSTS)

    if is_moderator:
      for p in posts:
        if 0 != p.user_ip:
          p.user_ip_str = long2ip(p.user_ip)
        if p.user_homepage:
          p.user_homepage = sanitize_homepage(p.user_homepage)

    tvals = {
      'role': self.role,
      'username': self.username,
      'siteroot' : siteroot,
      'forum' : forum,
      'analytics_code' : forum.analytics_code or "",
      'topic' : topic,
      'is_moderator' : is_moderator,
      'is_archived' : is_archived,
      'posts' : posts
    }
    tmpl = os.path.join("templates/topic.html")
    self.template_out(tmpl, tvals)
开发者ID:ignovak,项目名称:uarat,代码行数:57,代码来源:main.py

示例2: get

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import gql [as 别名]
  def get(self):
    forum = Forum.from_url(self.request.path_info)
    user = users.get_current_user()
    is_admin = users.is_current_user_admin()
    
    if not forum or (forum.is_disabled and not is_admin):
      return self.redirect("/")
    
    if not is_admin and not self.settings.check_ip(self.request.remote_addr):
      return self.response.out.write('Your IP address has been banned')

    if not is_admin and not self.settings.check_user( user ):
      return self.redirect( users.create_login_url("/") )

    offset, topics = Topic.getlist(forum, is_admin=is_admin, offset=self.request.get("from") or None)
    for topic in topics:
      topic.excerpt = Post.gql("WHERE topic = :1 ORDER BY created_on", topic)[0].get_excerpt()

    tvals = {
      'user': user,
      'analytics_code': forum.analytics_code or "",
      'siteurl': self.request.url,
      'isadmin': is_admin,
      'forum' : forum,
      'forum_urls': [f.url for f in Forum.all()],
      'topics': topics,
      'offset': offset,
      'login_url': users.create_login_url(forum.root()),
      'logout_url': users.create_logout_url(forum.root())
    }

    self.template_out("skins/default/topic_list.html", tvals)
开发者ID:skid,项目名称:fofou,代码行数:34,代码来源:main.py

示例3: get

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import gql [as 别名]
 def get(self,category):
   if users.is_current_user_admin():
     posts = Post.gql('where catalog =:1 ORDER BY date desc',category)
   else:
     posts = util.getPublicCategory(category) #only cahced public items
   if(posts is None):
     return self.redirect('/')
   else:
     template_values = {
       'posts': posts,
     }
     self.generate('../templates/view.html', template_values)
开发者ID:BlowBlood,项目名称:blowblood,代码行数:14,代码来源:blog.py

示例4: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import gql [as 别名]
  def post(self):
    forum = Forum.from_url(self.request.path_info)
    is_admin = users.is_current_user_admin()
    user = users.get_current_user()
    
    if not forum or (forum.is_disabled and not is_admin):
      return self.redirect("/")

    if not is_admin and not self.settings.check_ip(self.request.remote_addr):
      return self.response.out.write('Your IP address has been banned')

    if not is_admin and not self.settings.check_user( user ):
      return self.redirect( users.create_login_url("/") )

    name = self.request.get('name').strip()
    email = self.request.get('email').strip()
    subject = self.request.get('subject').strip()
    message = to_unicode( self.request.get('message') ).strip()
    homepage = self.request.get('homepage').strip()
    homepage = "" if homepage == "http://" else homepage
    remember = bool(self.request.get('remember'))
    
    try: 
      topic_id = int( self.request.get('topic_id') or 0 )
      if topic_id:
        topic = db.get(db.Key.from_path('Topic', topic_id))
      else:
        topic = None
    except ValueError:
      topic = None
    
    if topic and topic.is_locked:
      return self.redirect( "%stopic?id=%s" % (forum.root(), topic.id) )
    
    # Perform simple validation
    errors = { 'valid': True }
    
    # First post must have a subject
    if not topic and not subject: 
      errors['valid'] = False
      errors['subject'] = "Subject required for new topic"
    
    if not message:
      errors['valid'] = False
      errors['message'] = "Message is required"
    
    # sha.new() doesn't accept Unicode strings, so convert to utf8 first
    sha1_digest = sha.new( message.encode('UTF-8') ).hexdigest()
    if Post.gql("WHERE sha1_digest = :1 AND topic = :2", sha1_digest, topic).get():
      errors['valid'] = False
      errors['message'] = "This is a duplicate post"

    if not errors['valid']:
      return self.template_out("skins/default/post.html", {
        'isadmin': is_admin,
        'user': user,
        'errors': errors,
        'forum': forum,
        'topic': topic and { 'id': topic_id, 'subject': topic.subject },
        'post': { 'message': message, 'subject': subject },
        'fuser': { 'name': name, 'email': email, 'homepage': homepage, 'remember_me': remember }
      })

    # Get user either by google user id or cookie. Create user objects if don't already exist    

    if user:
      fuser = FofouUser.gql("WHERE user = :1", user).get()
    else: 
      fuser = FofouUser.gql("WHERE cookie = :1", self.cookie).get()

    if not fuser:
      fuser = FofouUser(
        user = user or users.User('[email protected]'),
        remember_me = remember, 
        email = email or '[email protected]', 
        name = name or 'Anonymous', 
        homepage = homepage,
        cookie = self.cookie )
    else:
      fuser.remember_me = remember
      fuser.email = email or '[email protected]'
      fuser.name = name or 'Anonymous'
      fuser.homepage = homepage

    if not topic:
      topic = Topic(forum=forum, subject=subject, created_by=fuser.name)
      forum.num_topics += 1
    else:
      topic.ncomments += 1
      forum.num_posts += 1
    
    topic.put()
    fuser.put()
    
    post = Post(
      topic = topic, 
      user = fuser, 
      user_ip = self.request.remote_addr, 
      message = message, 
      sha1_digest = sha1_digest, 
#.........这里部分代码省略.........
开发者ID:skid,项目名称:fofou,代码行数:103,代码来源:main.py

示例5: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import gql [as 别名]
  def post(self):
    user = self.user()
    if not user:
      return self.redirect('/?error=noUser')
    (forum, siteroot, tmpldir) = forum_siteroot_tmpldir_from_url(self.request.path_info)
    if not forum or forum.is_disabled:
      logging.info('no forum')
      return self.redirect("/")
    if self.request.get('Cancel'): 
      logging.info('cancel')
      return self.redirect(siteroot)

    self.send_cookie()

    vals = ['TopicId', 'Subject', 'Message', 'Url']
    (topic_id, subject, message, homepage) = req_get_vals(self.request, vals)
    message = to_unicode(message)

    homepage = sanitize_homepage(homepage)
    tvals = {
      'role': self.role,
      'username': self.username,
      'siteroot' : siteroot,
      'forum' : forum,
      "prevSubject" : subject,
      "prevMessage" : message,
      "prevUrl" : homepage,
      "prevTopicId" : topic_id
    }
    
    # validate captcha and other values
    errclass = None
    if not message: errclass = "message_class"
    # first post must have subject
    if not topic_id and not subject: errclass = "subject_class"

    # sha.new() doesn't accept Unicode strings, so convert to utf8 first
    message_utf8 = message.encode('UTF-8')
    s = sha.new(message_utf8)
    sha1_digest = s.hexdigest()

    duppost = Post.gql("WHERE sha1_digest = :1", sha1_digest).get()
    if duppost: errclass = "message_class"

    if errclass:
      tvals[errclass] = "error"
      tmpl = os.path.join("templates/post.html")
      return self.template_out(tmpl, tvals)

    if not topic_id:
      topic = Topic(forum=forum, subject=subject, created_by=user.nickname)
      topic.put()
    else:
      topic = db.get(db.Key.from_path('Topic', int(topic_id)))
      #assert forum.key() == topic.forum.key()
      topic.ncomments += 1
      topic.put()

    user_ip_str = get_remote_ip()
    p = Post(topic=topic, forum=forum, user=user, user_ip=0, user_ip_str=user_ip_str, message=message, sha1_digest=sha1_digest, user_homepage = homepage)
    p.put()
    memcache.delete(rss_memcache_key(forum))
    if topic_id:
      logging.info('topic id')
      self.redirect(siteroot + "topic?id=" + str(topic_id))
    else:
      logging.info('no topic id')
      self.redirect(siteroot)
开发者ID:ignovak,项目名称:uarat,代码行数:70,代码来源:main.py


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