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


Python Tag.put方法代码示例

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


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

示例1: post

# 需要导入模块: from model import Tag [as 别名]
# 或者: from model.Tag import put [as 别名]
    def post(self):
        """Creates a new tag for the logged in user"""
        user = utils.get_current_user()
        title = self.request.get('title')
        new_title = self.request.get('newTitle') or None
        
        if not user:
            self.error(403)
            return
        
        if not title:
            self.error(400)

        # Create new tag
        if not new_title:
            m = Tag.all().ancestor(user).filter('title_lower =', title.lower()).get()
            
            if m:
                # Not unique
                self.error(409)
                return

            m = Tag(
                parent=user,
                title=title,
                title_lower=title.lower(),
            )
            m.put()

        # Rename Tag
        else:
            m = Tag.all().ancestor(user).filter('title_lower =', new_title.lower()).get()
            if m:
                # Not unique
                self.error(409)
                return

            m = Tag.all().ancestor(user).filter('title_lower =', title.lower()).get()
            if not m:
                # Original tag not found
                self.error(404)
                return

            m.title = new_title
            m.title_lower = new_title.lower()
            m.save()

        self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.out.write('ok')
开发者ID:studyindenmark,项目名称:newscontrol,代码行数:52,代码来源:tags.py

示例2: get

# 需要导入模块: from model import Tag [as 别名]
# 或者: from model.Tag import put [as 别名]
 def get(self,format):
     tags = Tag.all().run()
     db.delete(tags)
     
     firstLevelTags = [
         "ActionScript",
         "Asp",
         "BASIC",
         "C",
         "C++",
         "Clojure",
         "COBOL",
         "ColdFusion",
         "Erlang",
         "Fortran",
         "Groovy",
         "Haskell",
         "Java",
         "JavaScript",
         "Lisp",
         "Perl",
         "PHP",
         "Python",
         "Ruby",
         "Scala",
         "Scheme",
         "haxe",
         "nodejs",
         'framework',
         'tool',
         'wiki',
         'tutorial',
         'howto',
         'library',
         'service',
         'language'
     ]
     
     for tag in firstLevelTags:
         t = Tag(name=tag.lower())
         t.put()
         
     entries = Entry.all()
     for e in entries:
         newtags = getTagKeys(e.tagsRaw)
         e.tags = newtags
         e.put()
         
     simplewebapp.formatResponse(format, self, "OK")
     
开发者ID:outbounder,项目名称:api-techbrowser,代码行数:51,代码来源:reset.py

示例3: post

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