當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。