Exemplo n.º 1
0
	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))
Exemplo n.º 2
0
	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))
Exemplo n.º 3
0
	def get(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

		inventory = Inventory.get_inventory_by_user(user)
		items = inventory.get_items().fetch()

		logout_url = users.create_logout_url("/")

		relations = []
		for item in items:
			relations += ItemRoomRelation.query(ancestor=inventory.key).filter(ItemRoomRelation.item==item.key).fetch()

		i = 0
		relation_data = {}
		for relation in relations:
			i += 1
			if i > 5:
				break
			room_name = relation.room.get().name
			if room_name in relation_data:
				relation_data[room_name] += relation.item.get().price
			else:
				relation_data[room_name] = relation.item.get().price


		i = 0
		cols = ["#4789b", "#EF7014", "#4BA449", "#154995", "#757374"]

		relation_data_final = []
		for k in relation_data:
			i += 1
			relation_data_final.append({"title": str(k), "value": relation_data[k], "color": cols[i]})

		relation_data_final = sorted(relation_data_final, key=lambda x: x["value"], reverse=True)

		template_data = {}
		template_data['relations'] = relation_data_final

		self.response.write(json.dumps(relation_data_final))
Exemplo n.º 4
0
	def get(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

		inventory = Inventory.get_inventory_by_user(user)
		items = inventory.get_items().fetch()

		total_price = 0

		logout_url = users.create_logout_url("/")

		relations = []
		for item in items:
			relations += ItemRoomRelation.query(ancestor=inventory.key).filter(ItemRoomRelation.item==item.key).fetch()
			total_price += item.price

		relation_data = {}
		for relation in relations:
			item = relation.item.get()
			item_data = {'category': item.category, 'name': item.name, 'price': "${0:.2f}".format(item.price), 'encoded': urllib.quote(item.name)}

			if relation.room.get().name in relation_data:
				relation_data[relation.room.get().name].append(item_data)
				continue
			relation_data[str(relation.room.get().name)] = [item_data]
			logging.error(relation)

		logging.error(relation_data)

		template_data = {}
		template_data['relations'] = relation_data
		template_data['total_price'] = "${0:.2f}".format(total_price)
		template_data['logout_url'] = logout_url

		template = JINJA_ENVIRONMENT.get_template('userHomePage.html')
		self.response.write(template.render(template_data))
Exemplo n.º 5
0
	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

		name = self.request.get("name")

		inventory = Inventory.get_inventory_by_user(user)
		item = Item.query(ancestor=inventory.key).filter(Item.name==name).get()


		if item is not None:
			for relation in ItemRoomRelation.query(ancestor=inventory.key).filter(ItemRoomRelation.item==item.key).fetch():
				relation.key.delete()
			item.key.delete()

		self.redirect("home")
Exemplo n.º 6
0
	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

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

		if name is '':
			self.response.write("no room specified")
			ResidenceTourHandler

		residence = Residence.get_residence_by_user(user)
		room = Room.query(ancestor=residence.key).filter(Room.name==name).get()

		if room is None:
			room = Room(name=name, parent=residence.key)
			room.put()

		other_rooms = Room.query(Room.name==name).fetch()

		relations = []
		for other_room in other_rooms:
			relations += ItemRoomRelation.query(ItemRoomRelation.room==other_room.key).fetch()

		item_count = {}
		for relation in relations:
			category = relation.item.get().category
			if category in item_count:
				item_count[category] += 1
				continue
			item_count[category] = 1

		logging.error(item_count)

		inventory = Inventory.get_inventory_by_user(user)

		item_count_final = {}
		for item in item_count:
			my_count = Item.query(ancestor=inventory.key).filter(Item.category==item).count()

			if my_count == 0:
				item_count_final[str(item)] = ("", item_count[item] / max(len(other_rooms), 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"
				logging.error( "(" + up_count + my_tail + ")")
				item_count_final[str(item)] = ("(" + up_count + my_tail + ")", item_count[item] / max(len(other_rooms), 1) - 2 * my_count)
				

		item_count_final = sorted(item_count_final.items(), key=lambda x: x[1][1], reverse=True)

		logging.error(item_count_final)

		template = JINJA_ENVIRONMENT.get_template('tourItemPage.html')
		template_data = {}
		template_data['items'] = item_count_final
		template_data['room'] = room.name



		self.response.write(template.render(template_data))