def execute(self, database_connection, arguments, cookies): cursor = database_connection.cursor() cursor.execute(self.sql) table = sportslib.HTMLTable("ID", "Name", "Sport", "Edit", "Delete") row = cursor.fetchone() while row is not None: link = sportslib.Link("admin_division_edit", row[0], str(row[0])) edit_link = sportslib.Link("admin_division_edit", row[0], "edit") table.add_row(link, row[1], row[2], edit_link, 'X') row = cursor.fetchone() return {'TABLE_OF_DIVISIONS': table}
def execute(self, database_connection, arguments, cookies): cursor = database_connection.cursor() cursor.execute(self.sql) table = sportslib.HTMLTable("ID", "First Name", "Last Name", "Position", "Edit", "Delete") row = cursor.fetchone() while row is not None: link = sportslib.Link("admin_player_edit", row[0], str(row[0])) edit_link = sportslib.Link("admin_player_edit", row[0], "edit") table.add_row(link, row[1], row[2], row[3], edit_link, 'X') row = cursor.fetchone() return {'TABLE_OF_PLAYERS': table}
def execute(self, database_connection, arguments, cookies): return { 'cookies': { 'auth': '_', }, 'location': sportslib.Link('admin_login').url() }
def execute(self, database_connection, arguments, cookies): data = {'error': ''} login = arguments.getvalue("username", "").strip() password = hashlib.sha1( arguments.getvalue("password", "").encode('utf-8')).hexdigest() submit = arguments.getvalue("submit", "").strip() if login and password and submit: cursor = database_connection.cursor() cursor.execute(self.sql, (login, password)) row = cursor.fetchone() if row: data['cookies'] = {'auth': sportslib.build_auth_cookie(row[0])} # Redirect to sports list admin page. data['location'] = sportslib.Link('admin_sports').url() return data if submit: data['error'] = 'Wrong login or password.' if sportslib.get_logged_in_user_id(): data['location'] = sportslib.Link('admin_sports').url() return data
def save(self, database_connection, arguments, cookies, data): if data['title'] == '' or data['description'] == '': data['error'] = 'All fields are required' return data cursor = database_connection.cursor() if data['id'] == '': cursor.execute(self.insert_sql, (data['title'], data['description'])) else: cursor.execute(self.update_sql, (data['title'], data['description'], data['id'])) database_connection.commit() data['location'] = sportslib.Link('admin_sports').url() return data
def start(self): if self.action.startswith( 'admin_' ) and self.action != 'admin_login' and not sportslib.get_logged_in_user_id( ): return {'location': sportslib.Link('admin_login').url()} result = {'error': ''} try: self.database_connection = mysql.connector.connect( user=appconfig.database_user, password=appconfig.database_password, database=appconfig.database_name, host=appconfig.database_host) result = self.actionInstance.execute(self.database_connection, self.arguments, self.cookies) if 'error' not in result.keys(): result['error'] = '' except mysql.connector.Error as err: result['error'] = str(err) finally: if self.database_connection: self.database_connection.close() self.database_connection = None return result