Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if cursor.fetchone()['num_events'] == len(events):
return
if len(events) == 1:
[event] = events
event_args = (team_id, schedule_id, event['start'], event['end'], user_id, role_id)
logger.debug('inserting event: %s', event_args)
query = '''
INSERT INTO `%s` (
`team_id`, `schedule_id`, `start`, `end`, `user_id`, `role_id`
) VALUES (
%%s, %%s, %%s, %%s, %%s, %%s
)''' % table_name
cursor.execute(query, event_args)
else:
link_id = gen_link_id()
for event in events:
event_args = (team_id, schedule_id, event['start'], event['end'], user_id, role_id, link_id)
logger.debug('inserting event: %s', event_args)
query = '''
INSERT INTO `%s` (
`team_id`, `schedule_id`, `start`, `end`, `user_id`, `role_id`, `link_id`
) VALUES (
%%s, %%s, %%s, %%s, %%s, %%s, %%s
)''' % table_name
cursor.execute(query, event_args)
def create_events(self, team_id, schedule_id, user_id, events, role_id, cursor, skip_match=True, table_name='event'):
if len(events) == 1:
[event] = events
event_args = (team_id, schedule_id, event['start'], event['end'], user_id, role_id)
logger.debug('inserting event: %s', event_args)
query = '''
INSERT INTO `%s` (
`team_id`, `schedule_id`, `start`, `end`, `user_id`, `role_id`
) VALUES (
%%s, %%s, %%s, %%s, %%s, %%s
)''' % table_name
cursor.execute(query, event_args)
else:
link_id = gen_link_id()
for event in events:
event_args = (team_id, schedule_id, event['start'], event['end'], user_id, role_id, link_id)
logger.debug('inserting event: %s', event_args)
query = '''
INSERT INTO `%s` (
`team_id`, `schedule_id`, `start`, `end`, `user_id`, `role_id`, `link_id`
) VALUES (
%%s, %%s, %%s, %%s, %%s, %%s, %%s
)''' % table_name
cursor.execute(query, event_args)
cursor.execute('UPDATE `schedule` SET `last_scheduled_user_id` = %s WHERE `id` = %s', (user_id, schedule_id))