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


Python Entry.content方法代码示例

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


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

示例1: post

# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import content [as 别名]
    def post(self):
        # add new post or edit existed post
        t_values = {}
        current_post_id = self.request.POST["current_post_id"]
        post_title = self.request.POST["blog_title"]
        post_slug = get_safe_slug(self.request.POST["blog_slug"])
        post_content = self.request.POST["blog_content"]
        # find category
        blog_category_id = self.request.POST["blog_category_id"]
        post_category = Category.get_by_id(long(blog_category_id))
        if post_category:
            logging.info("find category %s for id %s" % (post_category.name, blog_category_id))
        else:
            logging.error("category id %s can't be located" % (blog_category_id))

        if current_post_id:
            logging.info("PostManager: post : edit post current_post_id = %s" % (current_post_id))
            # update existed post
            post = Entry.get_by_id(long(current_post_id))
            if post:
                t_values['alert_message'] = "Post %s has been updated!" % (post.title)
                post.title = post_title
                post.slug = post_slug
                post.content = post_content
                post.entrytype = "post"
                # update category count if this post is public
                if post.is_external_page and post.category != post_category:
                    if post.category and (post.category.entrycount > 0):
                        post.category.entrycount -= 1
                        post.category.put()
                    post_category.entrycount += 1
                    post.category.put()
                post.category = post_category
                post.put()
        else:
            logging.info("PostManager: post : new post title %s" % (self.request.POST['blog_title']))
            # create new post
            post = Entry()
            post.title = post_title
            post.slug = post_slug
            post.content = post_content
            post.entrytype = 'post'
            post.category = post_category
            # save as public or private?
            operation = self.request.POST["submit_action"]
            if operation == "save_publish":
                post.is_external_page = True
                # update category count
                post.category.entrycount += 1
                post.category.put()
            else:  # "save" operation
                post.is_external_page = False
            # save the post
            post.put()
            t_values['alert_message'] = "Post %s has been created!" % (post.title)

        # show all posts
        posts = Entry.all().filter("entrytype =", 'post')
        t_values['posts'] = posts
        return self.response.out.write(render_template("posts.html", t_values, "", True))
开发者ID:loongw,项目名称:another-gae-blog,代码行数:62,代码来源:admin.py

示例2: post

# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import content [as 别名]
	def post(self):

		if not self.is_login:
			self.redirect(users.create_login_url(self.request.uri))
		filename=self.param('filename')
		do_comment=self.paramint('c',0)
		if filename[:4]=='img/':#处理图片
			new_filename=filename.split('/')[1]
			mtype =new_filename.split('.')[1]
			bits = self.request.body
			media=Media.all().filter('name =',new_filename)
			if media.count()>0:
				media=media[0]
			else:
				media=Media()
			media.name=new_filename
			media.mtype=mtype
			media.bits=bits
			media.put()
			bid='_'.join(new_filename.split('_')[:-1])
			entries=Entry.all().filter('slug =',bid)
			if entries.count()>0:
				entry=entries[0]
				entry.content=entry.content.replace(filename,'/media/'+str(media.key()))
				entry.put()
			return

		if filename=="index.html" or filename[-5:]!='.html':
			return
		#处理html页面
		bid=filename[:-5]
		try:

			soup=BeautifulSoup(self.request.body)
			bp=soup.find(id='bp')
			title=self.getChineseStr( soup.title.text)
			logging.info(bid)
			pubdate=self.getdate( bp.find(id='bp-'+bid+'-publish').text)
			body=bp.find('div','blogpost')

			entries=Entry.all().filter('title = ',title)
			if entries.count()<1:
				entry=Entry()
			else:
				entry=entries[0]
##			entry=Entry.get_by_key_name(bid)
##			if not entry:
##				entry=Entry(key_name=bid)
			entry.slug=bid
			entry.title=title
			entry.author_name=self.login_user.nickname()
			entry.date=pubdate
			entry.settags("")
			entry.content=unicode(body)
			entry.author=self.login_user

			entry.save(True)
			if do_comment>0:
				comments=soup.find('div','comments','div')
				if comments:
					for comment in comments.contents:
						name,date=comment.h5.text.split(' - ')
						# modify by lastmind4
						name_date_pair = comment.h5.text
						if name_date_pair.index('- ') == 0:
							name_date_pair = 'Anonymous ' + name_date_pair
						name,date=name_date_pair.split(' - ')

						key_id=comment.h5['id']
						date=self.getdate(date)
						content=comment.contents[1].text
						comment=Comment.get_or_insert(key_id,content=content)
						comment.entry=entry
						comment.date=date
						comment.author=name
						comment.save()

		except Exception,e :
			logging.info("import error: %s"%e.message)
开发者ID:Alwnikrotikz,项目名称:micolog2,代码行数:81,代码来源:live_import.py

示例3: post

# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import content [as 别名]
	def post(self):





		if users.is_current_user_admin():
			key  = self.request.get('key')
			if key :
				e = db.get(key)



			else:
				e = Entry()

			type = self.request.get('type')
			if not type:
				type = 'link'
			title = self.request.get('title')
			e.title = title.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			url = self.request.get('url')
			purl= self.request.get('purl')
			if type == 'pic' and not key:
				e.url = purl.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			else:
				e.url = url.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
			content = self.request.get('content')
			e.content = content
			if not key:
				e.addtime +=datetime.timedelta(hours=+8)
			e.private = bool(int(self.request.get('private')))
			e.type = type
			if type =='pic' and not key:
				if url:
					try:
						result = urlfetch.fetch(url)
						if result.status_code == 200:
							e.image = db.Blob(result.content)
					except :
						self.response.out.write('获取图片超时!')
						return
				else:
					myfile = self.request.get("myfile")
					if not myfile:
						self.response.out.write( '没有选择文件!')
						return
					try:
						e.image = db.Blob(myfile)
					except :
						self.response.out.write( '文件上传失败!')
						return

			if key:#更新数据
				for oldtag in e.tags:
					tag = Tag.all().filter('name',oldtag)
					if(tag.count(1)>0):
						t = tag.get()
						if type == 'link':
							t.count_link -=1
						if type == 'note':
							t.count_note -=1
						if type == 'pic':
							t.count_pic -=1
						t.put()
			else:#新增数据
				max_pageCount =900 #超过此数据,则pageid递增
				entry = Entry.all().order('-addtime')
				if entry.count()>0:
					cur_pageid = entry.get().pageid
				else:
					cur_pageid = 0
				
				cur_pageCount = entry.filter('pageid =',cur_pageid).count(1000)
				
				if cur_pageCount>=max_pageCount:
					e.pageid = cur_pageid+1
				else:
					e.pageid = cur_pageid
				
			e.tags = []
			tag_names = self.request.get('tags').split()
			for tag_name in tag_names:
				tag = Tag.all().filter('name',tag_name)
				if(tag.count(1)>0):
					t = tag.get()
					if type == 'link':
						t.count_link +=1
					if type == 'note':
						t.count_note +=1
					if type == 'pic':
						t.count_pic +=1

					t.usetime = datetime.datetime.now()
					t.put()
				else:
					t = Tag()
					t.name = tag_name
					if type == 'link':
						t.count_link =1
#.........这里部分代码省略.........
开发者ID:zerofault-cn,项目名称:zerofault,代码行数:103,代码来源:main.py

示例4: post

# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import content [as 别名]
    def post(self):
        """Parsing queued feeds"""
        doc = feedparser.parse(self.request.body)

        # Bozo feed handling
        # stealed from PubSubHubbub subscriber repo
        if doc.bozo:
            logging.error("Bozo feed data. %s: %r", doc.bozo_exception.__class__.__name__, doc.bozo_exception)
            if hasattr(doc.bozo_exception, "getLineNumber") and hasattr(doc.bozo_exception, "getMessage"):
                line = doc.bozo_exception.getLineNumber()
                logging.error("Line %d: %s", line, doc.bozo_exception.getMessage())
                segment = self.request.body.split("\n")[line - 1]
                logging.info("Body segment with error: %r", segment.decode("utf-8"))
            return  # fail fast

        # WORKER['parser'] + `key`
        key = self.request.path[len(WORKER["parser"]) :]
        # Try to get the channel by key;
        # fallback to feed id, if not found;
        # and at last we'll resort to entry source id,
        # to find out the associated channel
        channel = None
        uid = doc.feed.id
        try:
            channel = Channel.get(key)
        except:
            channel = Channel.all().filter("uid =", uid).get()
        else:
            # First time get the notification,
            # so update channel's properties
            if channel and not channel.uid:
                channel.title = doc.feed.title.split(" - ")[0]
                channel.uid = uid
                # Fallback to topic feed, if no link found
                channel.link = doc.feed.get("link", channel.topic)
                channel.put()

        updates = []
        for e in doc.entries:
            author = e.author if e.get("author") else None
            content = e.content[0].value if e.get("content") else e.summary
            # Fallback to published if no updated field.
            t = e.updated_parsed if e.get("updated_parsed") else e.published_parsed
            updated = datetime(t[0], t[1], t[2], t[3], t[4], t[5])

            # If we have this entry already in datastore, then the entry
            # should be updated instead of inserted.
            ent = Entry.all().filter("uid =", e.id).get()
            if not ent:
                if not channel:
                    uid = e.source.id
                    channel = Channel.all().filter("uid =", uid).get()
                ent = Entry(
                    title=e.title,
                    link=e.link,
                    content=content,
                    author=author,
                    updated=updated,
                    uid=e.id,
                    channel=channel,
                )
                logging.info("Get new entry: %s" % e.id)
            else:
                ent.title = e.title
                ent.link = e.link
                ent.content = content
                ent.author = author
                ent.updated = updated
                logging.info("Get updated entry: %s" % e.id)

            updates.append(ent)

        db.put(updates)
开发者ID:juvenn,项目名称:microupdater,代码行数:75,代码来源:sub.py


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