def fix_bookings_vendor_uid(ctx=None): """Add vendor_uid attribute to booking records. """ portal = getSite() soup = get_bookings_soup(portal) data = soup.storage.data need_rebuild = False for item in data.values(): update = False try: item.attrs['vendor_uid'] if not isinstance(item.attrs['vendor_uid'], uuid.UUID): update = True except KeyError: update = True if not update: continue buyable_uid = item.attrs['buyable_uid'] obj = get_object_by_uid(portal, buyable_uid) if not obj: shop = acquire_vendor_or_shop_root(portal) else: shop = acquire_vendor_or_shop_root(obj) vendor_uid = uuid.UUID(IUUID(shop)) item.attrs['vendor_uid'] = vendor_uid need_rebuild = True logging.info("Added vendor_uid to booking {0}".format( item.attrs['uid'])) if need_rebuild: soup.rebuild() logging.info("Rebuilt bookings catalog")
def test_acquire_vendor_or_shop_root(self): root = self.root self.assertEqual( acquire_vendor_or_shop_root(root['sub1']['subsub1']), root['sub1'] ) self.assertEqual(acquire_vendor_or_shop_root(root['sub2']), root)
def fix_bookings_vendor_uid(ctx=None): """Add vendor_uid attribute to booking records. """ portal = getSite() soup = get_bookings_soup(portal) data = soup.storage.data need_rebuild = False for item in data.values(): update = False try: item.attrs['vendor_uid'] if not isinstance(item.attrs['vendor_uid'], uuid.UUID): update = True except KeyError: update = True if not update: continue buyable_uid = item.attrs['buyable_uid'] obj = get_object_by_uid(portal, buyable_uid) if not obj: shop = acquire_vendor_or_shop_root(portal) else: shop = acquire_vendor_or_shop_root(obj) vendor_uid = uuid.UUID(IUUID(shop)) item.attrs['vendor_uid'] = vendor_uid need_rebuild = True logging.info( u"Added vendor_uid to booking {0}".format(item.attrs['uid']) ) if need_rebuild: soup.rebuild() logging.info("Rebuilt bookings catalog")
def fix_bookings_vendor_uid(ctx=None): """Add vendor_uid attribute to booking records. """ portal = getSite() soup = get_bookings_soup(portal) data = soup.storage.data need_rebuild = False for item in data.values(): if not 'vendor_uid' in item.attrs\ or not isinstance(item.attrs['vendor_uid'], uuid.UUID): buyable_uid = item.attrs['buyable_uid'] obj = uuidToObject(buyable_uid) shop = acquire_vendor_or_shop_root(obj) vendor_uid = uuid.UUID(IUUID(shop)) item.attrs['vendor_uid'] = vendor_uid need_rebuild = True logging.info( "Added vendor_uid to booking {0}".format(item.attrs['uid']) ) if need_rebuild: soup.rebuild() logging.info("Rebuilt bookings catalog")