Exemplo n.º 1
0
def insert_rating():
	# 1. check for session & user
	# 2. check for date, subject, sem, user combo before insert to prevent duplicates
	# 3. insert
	# 4. response

	subject_name = bottle.request.forms.get("subject")
	date = bottle.request.forms.get("date")
	sem = bottle.request.forms.get("sem")
	star = bottle.request.forms.get("star")
	batch = bottle.request.forms.get("batch")

	cookie = bottle.request.get_cookie("session")
	username = sessions.get_username(cookie)  # see if user is logged in

	response_obj = None
	if username is None:
		# print "welcome: can't identify user...redirecting to signup"
		response_obj = {
							"error":True,
							"data": "Cannot identify user"
						}
	else:
		isDuplicate = ratings.check_entry(date, subject_name, int(sem), username)

		if not isDuplicate:
			subject_rating = Rating(subject_name,date,batch,username,sem,star)
			subject_rating.set_date(date)

			result = ratings.insert_Rating(subject_rating)
			
			if result == None:
				response_obj = {
									"error":True,
									"data": "Error inserting document"
								}

			else:
				print "inserted document ", result
				response_obj = {
									"error":False,
									"data": "Success"
								}

		else:
			response_obj = {
								"error":True,
								"data": "Duplicate entry. Check data"
							}
	return json.dumps(response_obj)
Exemplo n.º 2
0
	def get_user_ratings(self, user):
		collection = self.rating_collection
		ratings = collection.find({'user' : user})

		modelled_rating_arr = []
		for rating in ratings:
			model_rating = Rating()
			model_rating.set_name(rating["subject_name"])
			model_rating.set_star(rating["star"])
			model_rating.set_date(rating["date"])
			model_rating.set_batch(rating["batch"])
			model_rating.set_username(rating["user"])
			model_rating.set_sem(rating["sem"])

			modelled_rating_arr.append(model_rating)
		return modelled_rating_arr
Exemplo n.º 3
0
	def get_user_ratings_by_sem(self, user, semno):
		collection = self.rating_collection

		ratings = collection.find({"user":user, "sem":int(semno)})

		modelled_rating_arr = []
		for rating in ratings:
			model_rating = Rating()
			model_rating.set_name(rating["subject_name"])
			model_rating.set_star(rating["star"])
			model_rating.set_date(rating["date"])
			model_rating.set_batch(rating["batch"])
			model_rating.set_username(rating["user"])
			model_rating.set_sem(rating["sem"])

			modelled_rating_arr.append(model_rating)
		print modelled_rating_arr
		return modelled_rating_arr
Exemplo n.º 4
0
	def get_all_ratings(self):
		collection = self.Rating_collection
		ratings = collection.find()

		modelled_rating_arr = []
		for rating in ratings:
			# model data from Rating
			
			# print Rating
			model_rating = Rating()
			model_rating.set_name(rating["subject_name"])
			model_rating.set_star(rating["star"])
			model_rating.set_date(rating["date"])
			model_rating.set_batch(rating["batch"])
			model_rating.set_batch(rating["user"])
			model_rating.set_batch(rating["sem"])
			
			# append modelled Rating to array
			modelled_rating_arr.append(model_rating)
		
		return modelled_rating_arr
Exemplo n.º 5
0
	def get_ratings_by_batch(self, batch):
		print "in get by batch"
		collection = self.rating_collection
		ratings = collection.find({"batchname":batch})

		modelled_rating_arr = []
		for rating in ratings:
			# model data from Rating
			
			# print Rating
			model_rating = Rating()
			model_rating.set_name(rating["subject_name"])
			model_rating.set_star(rating["star"])
			model_rating.set_date(rating["date"])
			model_rating.set_batch(rating["batch"])
			model_rating.set_batch(rating["user"])
			model_rating.set_batch(rating["sem"])
			
			# append modelled Rating to array
			modelled_rating_arr.append(model_rating)

		return modelled_Rating_arr