Beispiel #1
0
	def get_user_by(id):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				query = "SELECT users.first_name, users.last_name, users.email, users.color_theme, users.image FROM users WHERE users.user_id = %s"
				cur.execute(query, (id,))
				obj = cur.fetchone()
				user =User()
				if(obj):
					user.first_name = obj[0]
					user.last_name = obj[1]
					user.full_name = ''
					if(obj[0]):
						user.full_name = user.full_name + str(obj[0])
					if(obj[1]):
						user.full_name = user.full_name+' '+str(obj[1])
					user.email = obj[2]
					user.color_theme = obj[3]
					user.image = obj[4]
					user.user_id = id
				else:
					return False
				cur.close()
				conn.close()
				return user
		except Exception as e:
			return e
Beispiel #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