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


Python Post.put方法代码示例

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


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

示例1: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [as 别名]
  def post(self):
    user = self.getAuthentificatedUser()
    if not user:
      return
    try:
      id = int(self.request.get('post_id'))
      post = Post().get(db.Key.from_path('Post', id))
      if post.author != user:
        self.redirect('/')
        return
      body = db.Text(strip_ml_tags(self.request.get('body')))
      postmarkup = create(use_pygments=False)
      post.body = postmarkup(body)
      # replace('\n','<br />')
      if post.body != '':
        post.put()
          # re-index it!
        ix = getdatastoreindex("post_"+str(post.key().id()), schema=SEARCHSCHEMA)
        writer = ix.writer()
        writer.add_document(body=u"%s" % post.body)
        writer.commit()   
    except:
      pass
 
    if self.request.get('page'):
      self.redirect('/view?id=' + str(self.request.get('id')) + '&page=' + self.request.get('page'))
    else:
      self.redirect('/view?id=' + str(self.request.get('id')))
开发者ID:itsredwan,项目名称:tunedforum,代码行数:30,代码来源:main.py

示例2: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [as 别名]
 def post(self):
   user = self.getAuthentificatedUser()
   if not user:
     return
   try:
     id = int(self.request.get('id'))
     topic = Topic().get(db.Key.from_path('Topic', id))
   except:
      self.redirect('/')
      return
   post = Post(parent=topic.key())
   post.topic = topic
   if users.get_current_user():
     post.author = users.get_current_user()
   body = db.Text(strip_ml_tags(self.request.get('body')))
   postmarkup = create(use_pygments=False)
   post.body = postmarkup(body)
   # replace('\n','<br />')
   if post.body != '':
     post.put()
     message = mail.EmailMessage(sender=user.email(), subject="New message in small-forum")
     message.to = "log1 <[email protected]>"
     message.body = post.body + """ ... testing e-mail notification. Sorry if you get this message accidently."""
     message.send()
   #topic = Topic().all().filter('id =', int(self.request.get('id')))
   #topic = topic[0]
   #topic.getUserList()
   # To Do
   if self.request.get('page'):
     self.redirect('/view?id=' + str(self.request.get('id')) + '&page=' + self.request.get('page'))
   else:
     self.redirect('/view?id=' + str(self.request.get('id')))
开发者ID:phphtmlcreator,项目名称:Very-Small-Forum-For-GAE,代码行数:34,代码来源:main.py

示例3: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [as 别名]
 def post(self):
   user = self.getAuthentificatedUser()
   if not user:
     return
   try:
     id = int(self.request.get('id'))
     topic = Topic().get(db.Key.from_path('Topic', id))
   except:
      self.redirect('/')
      return
   post = Post(parent=topic.key())
   post.topic = topic
   if users.get_current_user():
     post.author = users.get_current_user()
   body = db.Text(strip_ml_tags(self.request.get('body')))
   postmarkup = create(use_pygments=False)
   post.body = postmarkup(body)
   # replace('\n','<br />')
   if post.body != '':
     post.put()
     #mailAdditionalText = """ ... testing e-mail notification. Sorry if you get this message accidently."""
     #post.sendMailToAll(user.email(), mailAdditionalText)
     #####
     #message = mail.EmailMessage(sender=user.email(), subject="New message in small-forum")
     #message.to = "log1 (sms) <[email protected]>"
     #message.body = post.body
     #message.send()
     #####
   # To Do
   if self.request.get('page'):
     self.redirect('/view?id=' + str(self.request.get('id')) + '&page=' + self.request.get('page'))
   else:
     self.redirect('/view?id=' + str(self.request.get('id')))
开发者ID:ahyangyi,项目名称:killard,代码行数:35,代码来源:main.py

示例4: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [as 别名]
    def post(self):
        pdict = self.request.POST
        
        try:
            #def new(cls, title, category_keyname, author_keyname, url, keyword, tags, content, status=PostStatus.NORMAL, format=PostFormat.PLAIN, enablecomment=True):
            tags = pdict.get("post.tags").split(",")
            for i in tags:
                Tag.Incr(i)

            pkey = Post.new(title=pdict.get("post.title"),
                            category_keyname=pdict.get("post.category").decode(config.CHARSET).encode("utf-8"),
                            author_keyname=self.session.get("curr_ukey").decode(config.CHARSET).encode("utf-8"),
                            url=pdict.get("post.url"),
                            keyword=pdict.get("post.keyword").split(","),
                            tags=tags,
                            content=pdict.get("post.content"),
                            format=pdict.get("post.format") )
            p = Post.id(pkey.id())
            p.realurl = realurl(p)
            Post.put(p)
            Post.refresh_total()

        except Exception, ex:
            context = {}
            context.update(self.request.POST)
            context["errors_msg"] = ex
            context["page_name"] = u"添加文章"
            context["page_title"] = u"添加文章" 
            context["all_category"] = Category.get_all()
            self.render("admin_post_editor.html", context)
开发者ID:dreampuf,项目名称:bana,代码行数:32,代码来源:admin_views.py

示例5: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [as 别名]
    def post(self):
        subject = self.request.get("subject")
        content = self.request.get("content")

        if subject and content:
            post = Post(subject = subject, content = content)
            post.put()
            memcache.set('time', time.time())

            post_id = post.key().id()

            self.redirect("/%i" % post_id)
        else:
            error = "both subject and content required to post"
            self.render_page(error = error, subject = subject, content = content)
开发者ID:jamespullar,项目名称:cs253,代码行数:17,代码来源:main.py

示例6: PostForm

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [as 别名]
class PostForm(Form):
	title = TextField('Titulo:', [
		validators.Length(min=5, max=60, message="O Titulo deve ter entre 5 a 60 caracteres.")
	])
	text =  TextAreaField('Texto:', [
		validators.Length(min=5, message="O Texto deve ter no minimo 5 caracteres.")
	])
	tags = TextField('Tags:',[
		validators.required(message="Informe uma tag.")
	])
		
	def __init__(self, model_instance = None, *args, **kwargs):
		"""Método construtor da classe, preenche model ao criar form."""
		kwargs['csrf_enabled'] = False
		super(PostForm, self).__init__(*args, **kwargs)
		self.model = None
		if model_instance:
			self.title.data = model_instance.title
			self.text.data = model_instance.text
			self.tags.data = self.get_tags( model_instance.tags )
			self.model = model_instance
			 
	def save(self):
		"""Método responsável em salvar post no bigtable."""
		if self.model:
			self.model.title = self.title.data
			self.model.text = self.text.data
			self.model.tags = self.set_tags(self.tags.data)
		else:	
			self.model = Post(
							title = self.title.data,
							text = self.text.data,
							tags = self.set_tags(self.tags.data)
						)
		self.model.put()
		return self.model

	def get_tags(self, tags):
		"""Metodo que recupera valor do atributo tags."""
		tstr = ""
		for tag in tags:
			tstr += "%s," % tag
		return tstr[:-1]

	def set_tags(self, tags):
		"""Método que define valor para o atributo tags."""
		tag = TagCategory()
		return tag.string_to_category( tags )	
开发者ID:Algy,项目名称:micro-blog,代码行数:50,代码来源:forms.py

示例7: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [as 别名]
def post():
	token = request.form['token']
	username = request.form['username']
	fb = GraphAPI(token)
	try:
		data = fb.get_object("me")
		if username != data['username']:
			return 'fail'
	except:
		return 'fail'
	print data
	print request.form
	subject = request.form['subject']
	subject_name = request.form['subject_name']
	obj = request.form['object']
	obj_name = request.form['object_name']
	answer = request.form['answer']
	lang = request.form['language']
	hashkey = request.form['hashkey']
	print 'here'
	post = Post(
		created_by=username,
		subject=subject,
		subject_name=subject_name,
		obj=obj,
		obj_name=obj_name,
		answer=answer,
		lang=lang,
		hashkey=str(uuid.uuid1()),
		key_name=subject+'||'+obj)
	post.put()
	print request.url, request.url_root
	link = request.url_root + subject + '/' + obj + '/'
	edit = link + 'edit/' + post.hashkey
	res = {
		'link': link,
		'edit': edit
	}
	return json.dumps(res)
开发者ID:spicavigo,项目名称:issheoverhim,代码行数:41,代码来源:app.py

示例8: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [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

示例9: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import put [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.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。