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


Python Room.query方法代码示例

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


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

示例1: get

# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import query [as 别名]
	def get(self):

		user = users.get_current_user()

		if user is None:
			login_url = users.create_login_url('/welcome')
			self.response.write('<html><body>{}</body></html>'.format('<a href="' + login_url + '">Sign in</a>'))
			return

		residence = Residence.get_residence_by_user(user)
		inventory = Inventory.get_inventory_by_user(user)

		other_homes = Residence.query(Residence.own==residence.own).fetch()

		logging.error(other_homes)

		rooms = []
		for home in other_homes:
			rooms += Room.query(ancestor=home.key).filter(Room.name!="miscellaneous").fetch()

		room_count = {}
		for room in rooms:
			name = room.name
			if name in room_count:
				room_count[name] += 1
				continue
			room_count[name] = 1

		room_count_final = {}
		for room in room_count:
			my_count = Room.query(ancestor=residence.key).filter(Room.name==room).count()

			if my_count == 0:
				room_count_final[str(room)] = ("", room_count[room] / max(len(other_homes), 1))
			else:
				up_count = str(my_count + 1)
				my_tail = ""
				if up_count[-1:] in ["0", "4", "5", "6", "7", "8", "9"]:
					my_tail = "th"
				elif up_count[-1:] in ["2"]:
					my_tail = "nd"
				elif up_count[-1:] in ["1"]:
					my_tail = "st"
				elif up_count[-1:] in ["3"]:
					my_tail = "rd"
				room_count_final[str(room)] = (" (" + up_count + my_tail + ")", room_count[room] / max(len(other_homes), 1) - 2 * my_count)
		
		room_count_final = sorted(room_count_final.items(), key=lambda x: x[1][1], reverse=True)

		template = JINJA_ENVIRONMENT.get_template('tourRoomPage.html')
		template_data = {'rooms': room_count_final}

		self.response.write(template.render(template_data))
开发者ID:alexweaver,项目名称:tdp-hackathon-2016,代码行数:55,代码来源:main.py

示例2: post

# 需要导入模块: from models import Room [as 别名]
# 或者: from models.Room import query [as 别名]
	def post(self):

		user = users.get_current_user()

		if user is None:
			login_url = users.create_login_url('/home')

			template_data = {}
			template_data['login_url'] = login_url

			template = JINJA_ENVIRONMENT.get_template('login.html')
			self.response.write(template.render(template_data))
			return

		residence = Residence.get_residence_by_user(user)

		category = self.request.get('category')
		name = self.request.get('name')
		price = self.request.get('price')


		room_name = self.request.get("room")

		if name.strip() == '' or category.strip() == '':
			if room_name == "miscellaneous":
				self.redirect("home")
			else:
				self.redirect("/room-tour?room=" + urllib.quote(room_name))
			return

		price = float(price)

		inventory = Inventory.get_inventory_by_user(user)
		item = Item(category=category, name=name, price=price, parent=inventory.key)
		item.put()


		residence = Residence.get_residence_by_user(user)
		room = Room.query(ancestor=residence.key).filter(Room.name==room_name).get()
		if room is None:
			room = Room(name=room_name, parent=residence.key)
			room.put()
		
		relation = ItemRoomRelation(item=item.key, room=room.key, parent=inventory.key)
		relation.put()

		if room_name == "miscellaneous":
			self.redirect("/home")
			return



		self.redirect("/room-tour?room=" + urllib.quote(room_name))
开发者ID:alexweaver,项目名称:tdp-hackathon-2016,代码行数:55,代码来源:main.py


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