コード例 #1
0
	def get_profile_details(user_id, role_id):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				select_query = "SELECT first_name, last_name, email, finanical_aid, middle_name, dob, gender, permanent_address,\
				present_address, alt_email, phone, course, image, color_theme FROM users WHERE user_id = %s"
				cur.execute(select_query,(user_id,))
				result = cur.fetchone()
				user = User()
				if(result):
					user.first_name=result[0]
					user.last_name=result[1]
					user.email = result[2]
					user.finanical_aid = result[3]
					user.middle_name = result[4]
					user.dob = result[5]
					user.gender = result[6]
					user.permanent_address = result[7]
					user.present_address = result[8]
					user.alt_email = result[9]
					user.phone = result[10]
					user.course = result[11]
					user.image = result[12]
					user.color_theme = result[13]
					if(int(role_id) == 3):
						gpa_query = "SELECT avg(gpa) FROM enrolled_courses WHERE user_id = %s"
						cur.execute(gpa_query, (user_id,))
						cgpa = cur.fetchone()[0]
						user.cgpa = 0
						if(cgpa):
							user.cgpa = round(float(cgpa),2)
					cur.close()
					conn.close()
					return user
				else:
					return False
			else:
				return False
		except Exception as e:
			return  e
コード例 #2
0
	def get_all(users, start, end):
		conn = None
		cur = None
		role_id = 3 #default to students
		if(users=="PROFESSORS"):
			role_id = 2
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				query = "SELECT users.first_name, users.last_name, users.email, users.user_id, users.color_theme,\
				users.image, users.finanical_aid, users.cgpa, users.dob FROM users, (SELECT user_id FROM user_role WHERE role_id = %s)\
				AS user_role WHERE users.user_id = user_role.user_id ORDER BY users.user_id LIMIT %s OFFSET %s"
				cur.execute(query, (role_id, end, start,))
				users = cur.fetchall()
				user_list = []
				if(len(users)):
					for response in users:
						user = User()
						user.first_name = response[0]
						user.last_name = response[1]
						user.full_name = ''
						if(response[0]):
							user.full_name = user.full_name + str(response[0])
						if(response[1]):
							user.full_name = user.full_name+' '+str(response[1])
						user.email = response[2]
						user.user_id = response[3]
						user.color_theme = response[4]
						user.image = response[5]
						user.finanical_aid = response[6]
						user.cgpa = response[7]
						user.dob = response[8]
						user_list.append(user)
				else:
					return False

				cur.close()
				conn.close()
				return user_list
		except Exception as e:
			return e