當前位置: 首頁>>代碼示例>>Python>>正文


Python Entry.put方法代碼示例

本文整理匯總了Python中model.Entry.put方法的典型用法代碼示例。如果您正苦於以下問題:Python Entry.put方法的具體用法?Python Entry.put怎麽用?Python Entry.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在model.Entry的用法示例。


在下文中一共展示了Entry.put方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

# 需要導入模塊: from model import Entry [as 別名]
# 或者: from model.Entry import put [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 put [as 別名]
    def post(self):
        target = self.request.get('target')
        amount = int(self.request.get('amount'))
        location = self.request.get('location')
        date = datetime.datetime.strptime(self.request.get('date'), '%Y-%m-%d').date()
        succeed = True#self.request.get('succeed')
        story = self.request.get('story')
         
        entry = Entry(target=target, amount=amount, location=location, date=date, succeed=succeed, story=story, author=users.get_current_user())
        entry.put()

        self.redirect('/')
開發者ID:yaozhifeng,項目名稱:i-bribe,代碼行數:14,代碼來源:main.py

示例3: get

# 需要導入模塊: from model import Entry [as 別名]
# 或者: from model.Entry import put [as 別名]
	def get(self):
		'''i=0
		n = self.request.get('n')
		if not n:
			n='1'
		csvfile='data/data'+n+'.csv'
		
		self.response.headers['Content-Type'] = 'text/html'
		csvreader = csv.reader(file(os.path.join(os.path.dirname(__file__),csvfile))) 
		
		for line in csvreader:
			e = Entry()
			e.title = line[0].decode('utf-8')
			e.url = line[1].decode('utf-8')
			e.content = line[2].decode('utf-8')
			e.private = False

			tag_name=line[3].decode('utf-8')
			t_q = Tag.all()
			t_q = t_q.filter('name =',tag_name)
			if(t_q.count(1)>0):
				t = t_q.get()
				t.count_link+=1
				t.usetime=datetime.datetime.now()
				t.put()
			else:
				t = Tag()
				t.name = tag_name
				t.count_link=1
				t.usetime=datetime.datetime.now()
				t.put()
			e.tags.append(db.Category(tag_name))
			
			e.put()
			i +=1
			self.response.out.write('%d ' % i)
			self.response.out.write('%s ' % e.key())
			self.response.out.write('%s <br />' % line[0])
		'''
		n = self.request.get('n')
		if not n:
			n=0
		else:
			n=int(n)
		for i in range(1,1000):
			e = Entry()
			e.title=str(i+n*999)
			e.pageid=n
			e.put()
			self.response.out.write('%d ' % i)
			self.response.out.write('%s <br />' % e.key())
開發者ID:zerofault-cn,項目名稱:zerofault,代碼行數:53,代碼來源:loadcsv.py

示例4: test_put

# 需要導入模塊: from model import Entry [as 別名]
# 或者: from model.Entry import put [as 別名]
 def test_put(self):
     context = Context(http=MockHttp(HTTP_SRC_DIR), entry="http://example.org/entry/67")
     entry = Entry(context)
     (headers, body) = entry.put(body="<entry></entry>")
     self.assertEqual(200, headers.status)
     self.assertFalse(entry.has_media())
     self.assertEqual(0, len(body))
開發者ID:myblup,項目名稱:atompubbase,代碼行數:9,代碼來源:test_entry.py

示例5: post

# 需要導入模塊: from model import Entry [as 別名]
# 或者: from model.Entry import put [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


注:本文中的model.Entry.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。