Beispiel #1
0
 def create_events(self, team_id, schedule_id, user_id, events, role_id,
                   cursor):
     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 `event` (
                 `team_id`, `schedule_id`, `start`, `end`, `user_id`, `role_id`
             ) VALUES (
                 %s, %s, %s, %s, %s, %s
             )'''
         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 `event` (
                     `team_id`, `schedule_id`, `start`, `end`, `user_id`, `role_id`, `link_id`
                 ) VALUES (
                     %s, %s, %s, %s, %s, %s, %s
                 )'''
             cursor.execute(query, event_args)
     cursor.execute('UPDATE `schedule` SET `last_scheduled_user_id` = %s',
                    user_id)
Beispiel #2
0
    def create_events(self,
                      team_id,
                      schedule_id,
                      user_id,
                      events,
                      role_id,
                      cursor,
                      skip_match=True,
                      table_name='event'):
        if len(events) == 0:
            return
        # Skip creating this epoch of events if matching events exist
        if skip_match:
            matching = ' OR '.join([
                '(start = %s AND end = %s AND role_id = %s AND team_id = %s)'
            ] * len(events))
            query_params = []

            for ev in events:
                query_params += [ev['start'], ev['end'], role_id, team_id]

            query = 'SELECT COUNT(*) AS num_events FROM %s WHERE %s' % (
                table_name, matching)

            cursor.execute(query, query_params)
            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)