def search_participants(self, term): sql = """ select cast(ag_login_id as varchar(100)) as ag_login_id from ag_consent where lower(participant_name) like %s or lower(participant_email) like %s""" conn_handler = SQLConnectionHandler() liketerm = '%%' + term + '%%' return [x[0] for x in conn_handler.execute_fetchall( sql, [liketerm, liketerm])]
def __init__(self, con=None): self._metadataDatabaseConnection = None if con is None: self.connection = psycopg2.connect( user=AMGUT_CONFIG.user, password=AMGUT_CONFIG.password, database=AMGUT_CONFIG.database, host=AMGUT_CONFIG.host, port=AMGUT_CONFIG.port) else: self.connection = con cur = self.connection.cursor() cur.execute('set search_path to public, ag') self._sql = SQLConnectionHandler(con)
def getHumanParticipants(self, ag_login_id): conn_handler = SQLConnectionHandler() # get people from new survey setup return_res = [] new_survey_sql = ("SELECT participant_name FROM ag_login_surveys " "WHERE ag_login_id = %s") results = conn_handler.execute_fetchall(new_survey_sql, [ag_login_id]) return_res.extend(row[0] for row in results) # get people from old surveys old_survey_sql = ("SELECT participant_name FROM ag_human_survey where " "ag_login_id = %s") results = conn_handler.execute_fetchall(new_survey_sql, [ag_login_id]) return_res.extend(row[0] for row in results) return return_res
# ----------------------------------------------------------------------------- import importlib from amgut.lib.config_manager import AMGUT_CONFIG from amgut.lib.locale_data import media_locale from amgut.lib.data_access.ag_data_access import AGDataAccess from redis import Redis from amgut.lib.data_access.sql_connection import SQLConnectionHandler r_server = Redis(host=AMGUT_CONFIG.redis_host, port=AMGUT_CONFIG.redis_port, db=AMGUT_CONFIG.redis_db_id) try: db_conn = SQLConnectionHandler() AG_DATA_ACCESS = AGDataAccess() except: # this SHOULD only trigger when the environment is being created... print "Can't get db_conn!" db_conn = None AG_DATA_ACCESS = None current_locale_module = '.'.join( ['amgut.lib.locale_data', AMGUT_CONFIG.locale]) try: current_locale = importlib.import_module(current_locale_module) except ImportError: raise ImportError("Cannot import locale! %s" % current_locale_module)