Example #1
0
def get_users_by_ids(user_ids):
	cursor = handled_execute(db_conn, """
		SELECT userId,email,phone,firstName,lastName,nickName,portrait,biography,
		showLastName,searchableByName,useBrowserGeolocation
		FROM users WHERE userId = ANY (%s)""", (user_ids,))

	user_rows = cursor.fetchall()
	user_objs = []
	for row in user_rows:
		(user_id, email, phone, first_name, last_name, nick_name, portrait, biography,
			show_last_name, name_search, browser_geo) = row

		user_prefs = UserPreferences(show_last_name, name_search, browser_geo)
		user_obj = User(email, phone, first_name, last_name, nick_name, portrait, biography, user_prefs)
		user_obj.user_id = user_id

		user_objs.append(user_obj)

	return user_objs
Example #2
0
def get_user_by_field(field, value):
	cursor = handled_execute(db_conn, """
			SELECT userId,email,phone,firstName,lastName,nickName,portrait,biography,
			showLastName,searchableByName,useBrowserGeolocation
			FROM users WHERE %s=%s;""", (AsIs(field), value))

	user_row = cursor.fetchone()

	returned_user = None
	if(user_row != None):
		(user_id, email, phone, first_name, last_name, nick_name, portrait, biography,
			show_last_name, name_search, browser_geo) = user_row

		returned_prefs = UserPreferences(show_last_name, name_search, browser_geo)
		returned_user = User(email, phone, first_name, last_name, nick_name, portrait, biography, returned_prefs)

		returned_user.user_id = user_id
	else:
		raise DAOException("No user found in database with field " + str(field) + " with value " + str(value))

	return returned_user