示例#1
0
def update_jsregistry(context):
    '''
    Run generic setup actions.xml
    '''
    setup = api.portal.get_tool('portal_setup')
    setup.runImportStepFromProfile(PROFILE_ID, 'jsregistry')
    logger.info("jsregistry.xml has been run")
示例#2
0
def upgrade_tipologia(context):
    ''' From now on "durata" and "tipologia" are merged in one single field
    This is the upgrade step which perform the merge action on
    prenotazioni_folder objects
    '''
    def new_style_tipologie(value, duration):
        ''' Check is this value should be migrated
        '''
        if isinstance(value, unicode):
            value = value.encode('utf8')
        if isinstance(value, basestring):
            value = {'name': value or 'default', 'duration': str(duration)}
        return value

    catalog = api.portal.get_tool('portal_catalog')
    brains = catalog(portal_type="PrenotazioniFolder")
    for brain in brains:
        obj = brain.getObject()
        duration = getAnnotaionValue(obj, 'durata')
        items = [new_style_tipologie(item, duration)
                 for item
                 in getAnnotaionValue(obj, 'tipologia', ['default'])]
        obj.setTipologia(items)
    logger.info('Updated "tipologia" in prenotazioni_folder '
                ' for %s' % PROFILE_ID)
示例#3
0
def upgrade_propertiestool(context):
    '''
    Run generic setup propertiestool.xml
    '''
    setup = api.portal.get_tool('portal_setup')
    setup.runImportStepFromProfile(PROFILE_ID, 'propertiestool')
    logger.info("propertiestool.xml has been run")
示例#4
0
def update_actions(context):
    '''
    Run generic setup actions.xml
    '''
    setup = getToolByName(context, 'portal_setup')
    setup.runImportStepFromProfile(PROFILE_ID, 'actions')
    logger.info("actions.xml has been run")
示例#5
0
def install_missing_products(context):
    '''
    Install quintagroup.formlib.captcha
    '''
    missing_products = ['quintagroup.captcha.core']
    qi = getToolByName(context, 'portal_quickinstaller')
    for product in missing_products:
        if not qi.isProductInstalled(product):
            logger.info('Installing %s' % product)
            qi.installProduct(product)
示例#6
0
def upgrade_week_values(context):
    ''' Upgrade values of "settimana_tipo" in prenotazioni_folder content type
    '''
    catalog = api.portal.get_tool('portal_catalog')
    brains = catalog(portal_type="PrenotazioniFolder")
    for brain in brains:
        obj = brain.getObject()
        span = getAnnotaionValue(obj, 'durata')
        week = obj.getSettimana_tipo()
        if week:
            for day in week:
                get_merge_time(day, span)
    logger.info('Updated "settimana_tipo" in prenotazioni_folder '
                'for %s' % PROFILE_ID)
示例#7
0
def install_missing_products(context):
    '''
    Install quintagroup.formlib.captcha and perform a workflow update
    '''
    missing_products = ['quintagroup.captcha.core']
    qi = getToolByName(context, 'portal_quickinstaller')
    for product in missing_products:
        if not qi.isProductInstalled(product):
            logger.info('Installing %s' % product)
            qi.installProduct(product)
    # Workflow update
    setup = getToolByName(context, 'portal_setup')
    setup.runImportStepFromProfile(PROFILE_ID, 'workflow')
    logger.info("Workflow has been updated")
示例#8
0
def fix_container(context):
    ''' Fix the container for Prenotazione object
    '''
    catalog = api.portal.get_tool('portal_catalog')
    brains = catalog(portal_type="PrenotazioniFolder")
    for brain in brains:
        obj = brain.getObject()
        booker = IBooker(obj)
        conflict_manager = IConflictManager(obj)
        bookings = conflict_manager.unrestricted_prenotazioni()
        for booking in bookings:
            booker.fix_container(booking.getObject())
        logger.info("Fixed %s objects for %s" %
                    (len(bookings), '/'.join(obj.getPhysicalPath()))
                    )
示例#9
0
def set_expiration_date(context):
    ''' Upgrade all IPrenotazione object in order to provide the expiration
    date for each reservation
    '''

    catalog = api.portal.get_tool('portal_catalog')
    brains = catalog(portal_type="PrenotazioniFolder")
    for brain in brains:
        obj = brain.getObject()
        durata = getAnnotaionValue(obj, 'durata')
        if durata:
            durata = float(getAnnotaionValue(obj, 'durata')) / MIN_IN_DAY
            conflict_manager = IConflictManager(obj)
            prenotazioni = conflict_manager.unrestricted_prenotazioni()

            for prenotazione in prenotazioni:
                p = prenotazione.getObject()
                p.setData_scadenza(p.getData_prenotazione() + durata)
    logger.info("All IPrenotazione documents have been updated")
示例#10
0
def upgrade_types(context):
    ''' Upgrade portal_types to read the new PrenotazioniWeek type
    '''
    portal_setup = api.portal.get_tool('portal_setup')
    portal_setup.runImportStepFromProfile(PROFILE_ID, 'factorytool')
    logger.info('factorytool.xml updated for %s' % PROFILE_ID)
    portal_setup.runImportStepFromProfile(PROFILE_ID, 'rolemap')
    logger.info('rolemap.xml updated for %s' % PROFILE_ID)
    portal_setup.runImportStepFromProfile(PROFILE_ID, 'typeinfo')
    logger.info('types.xml updated for %s' % PROFILE_ID)
示例#11
0
def reindex_subject(context):
    ''' The Subject has to be reindexed
    '''
    pc = api.portal.get_tool('portal_catalog')
    brains = pc(portal_type="Prenotazione")
    total = len(brains)
    logger.info('Found %s objects to upgrade' % len(brains))
    done = 0
    for brain in brains:
        obj = brain.getObject()
        obj.reindexObject(idxs=['Subject'])
        done += 1
        if done % 100 == 0:
            commit()
            logger.info('Progress %s/%s' % (done, total))
    logger.info('Progress %s/%s' % (done, total))