Example #1
0
 def add_worksheet_item(self, worksheet_uuid, item):
     '''
     Appends a new item to the end of the given worksheet. The item should be
     a (bundle_uuid, value) pair, where the bundle_uuid may be None and the
     value must be a string.
     '''
     (bundle_uuid, value) = item
     item_value = {
       'worksheet_uuid': worksheet_uuid,
       'bundle_uuid': bundle_uuid,
       'value': value,
       'sort_key': None,
     }
     with self.engine.begin() as connection:
         connection.execute(cl_worksheet_item.insert().values(item_value))
Example #2
0
 def add_worksheet_item(self, worksheet_uuid, item):
     '''
     Appends a new item to the end of the given worksheet. The item should be
     a (bundle_uuid, value, type) pair, where the bundle_uuid may be None and the
     value must be a string.
     '''
     (bundle_uuid, subworksheet_uuid, value, type) = item
     if value == None: value = ''  # TODO: change tables.py to allow nulls
     item_value = {
       'worksheet_uuid': worksheet_uuid,
       'bundle_uuid': bundle_uuid,
       'subworksheet_uuid': subworksheet_uuid,
       'value': value,
       'type': type,
       'sort_key': None,
     }
     with self.engine.begin() as connection:
         connection.execute(cl_worksheet_item.insert().values(item_value))
Example #3
0
    def add_shadow_worksheet_items(self, old_bundle_uuid, new_bundle_uuid):
        '''
        For each occurrence of old_bundle_uuid in any worksheet, add
        new_bundle_uuid right after it (a shadow).
        '''
        with self.engine.begin() as connection:
            # Find all the worksheet_items that old_bundle_uuid appears in
            query = select([cl_worksheet_item.c.worksheet_uuid, cl_worksheet_item.c.sort_key]).where(cl_worksheet_item.c.bundle_uuid == old_bundle_uuid)
            old_items = connection.execute(query)
            #print 'add_shadow_worksheet_items', old_items

            # Go through and insert a worksheet item with new_bundle_uuid after
            # each of the old items.
            new_items = []
            for old_item in old_items:
                new_item = {
                  'worksheet_uuid': old_item.worksheet_uuid,
                  'bundle_uuid': new_bundle_uuid,
                  'type': worksheet_util.TYPE_BUNDLE,
                  'value': '',  # TODO: replace with None once we change tables.py
                  'sort_key': old_item.sort_key,  # Can't really do after, so use the same value.
                }
                new_items.append(new_item)
                connection.execute(cl_worksheet_item.insert().values(new_item))