コード例 #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