本文整理汇总了Python中models.Tags.query方法的典型用法代码示例。如果您正苦于以下问题:Python Tags.query方法的具体用法?Python Tags.query怎么用?Python Tags.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tags
的用法示例。
在下文中一共展示了Tags.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import query [as 别名]
def get(self):
user = users.get_current_user()
tag_str = self.request.get('tag')
if user:
tag = Tags.query(Tags.user == user, Tags.name == tag_str).get()
if tag is None:
newtag = Tags()
newtag.name = tag_str
newtag.user = user
else:
newtag = tag
newtag.put()
示例2: get_all_tags
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import query [as 别名]
def get_all_tags(self,id):
'''
Returns all tags for specified user
'''
#get users tags
tags_query = Tags.query(ancestor=helper.trip_key(id))
tags = tags_query.fetch(1)
if tags:
tags = tags[0]
location = [str(x) for x in tags.location]
type = [str(x) for x in tags.type]
season = [str(x) for x in tags.season]
else:
location = []
type = []
season = []
tags = []
tags.append(location)
tags.append(type)
tags.append(season)
return tags
示例3: post
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import query [as 别名]
def post(self):
_,id,_,_ = self.get_user()
#get specific trip
trip_key = self.request.get('trip_id')
tripk = ndb.Key(urlsafe=trip_key)
trip = tripk.get()
#get new values
new_name = self.request.get('trip_name')
if new_name:
trip.trip_name = new_name
new_description = self.request.get('description')
if new_description:
trip.description = new_description
new_cities = self.get_cities(self.request.get('cities'))
if new_cities:
trip.cities = new_cities
new_avatar = self.request.get('img')
if new_avatar:
trip.trip_avatar = new_avatar
new_from_date = self.request.get('from_date')
if new_from_date:
try:
new_from_date = datetime.strptime( new_from_date, '%d/%m/%Y')
except:
try:
new_from_date = datetime.strptime( new_from_date, '%Y-%m-%d')
except:
new_from_date = datetime.strptime( '2000-01-01', '%Y-%m-%d')
trip.from_date = new_from_date
new_to_date = self.request.get('to_date')
if new_to_date:
try:
new_to_date = datetime.strptime( new_to_date, '%d/%m/%Y')
except:
try:
new_to_date = datetime.strptime( new_to_date, '%Y-%m-%d')
except:
new_to_date = datetime.strptime( '2000-01-01', '%Y-%m-%d')
trip.to_date = new_to_date
if self.request.get('visibility') == 'True':
trip.visibility = True
else:
trip.visibility = False
#crete tags for trip
locationl = helper.creatList(self.request.get('location'))
typel = helper.creatList(self.request.get('type'))
seasonl = helper.creatList(self.request.get('season'))
trip.trip_tags = Tags(location=locationl,type=typel,season=seasonl)
#put new tags in users tags
tags_query = Tags.query(ancestor=helper.trip_key(id))
tags = tags_query.fetch(1)
if tags:
tags = tags[0]
tags.location = helper.union(tags.location,locationl)
tags.type = helper.union(tags.type,typel)
tags.season = helper.union(tags.season,seasonl)
else:
new_loc_tags = locationl
new_type_tags = typel
new_seasion_tags = seasonl
tags = Tags(parent=helper.trip_key(id),location=new_loc_tags,type=new_type_tags,season=new_seasion_tags)
tags.put()
trip.put()
self.redirect('/tripmanager/onetrip?trip_id='+ tripk.urlsafe())