Пример #1
0
def copyLegislation(self):
    portal = getToolByName(self, 'portal_url').getPortalObject()
    folder = getattr(portal.en.legislation.directives,  'provisions-on-workload-ergonomical-and-psychosocial-risks')

    subfolders = self.ZopeFind(obj=folder, search_sub=1,
    obj_metatypes='ATFolder')
    langs = folder.getTranslationLanguages()
    for subf in subfolders:
        id, ob = subf
        if ob.Language() not in ('en',''):
            continue
        print "translating folder", ob.absolute_url()
        linguautils.translate_this(ob, [], 0, langs) 
        linguautils.exec_for_all_langs(ob, linguautils.workflow_action, transition="publish")

    documents = self.ZopeFind(obj=folder, search_sub=1,
        obj_metatypes='ATDocument')
    for doc in documents:
        id, ob = doc
        if ob.Language() not in ('en', ''):
            continue
        print "translating document", ob.absolute_url()
        linguautils.translate_this(ob, ['title', 'description', 'text'], 0, langs)
        linguautils.exec_for_all_langs(ob, linguautils.workflow_action, transition="publish")

    print "folder:", folder
    objs = self.ZopeFind(obj=folder, search_sub=1, obj_metatypes='Collage')

    for item in objs:
        id, ob = item
        id = id.split('/')[-1]
        print "id:", id
        print "url", ob.absolute_url()
        print item
        parent = Acquisition.aq_parent(ob)
        print parent
        parentlang = parent.Language()
        trans = parent.getTranslations()
        for lang in trans.keys():
            if lang == parentlang:
                continue
            target = trans[lang][0]
#            if getattr(Acquisition.aq_base(target), id, None) and type(getattr(Acquisition.aq_base(target), id, None)) == type(ob):
#                target.manage_delObjects(id)
            if not getattr(Acquisition.aq_base(target), id, None) or not \
            type(getattr(Acquisition.aq_base(target), id, None))==type(ob):
                cp = ob._getCopy(ob)
                target._setObject(id, cp)
                print "doing the copying", cp, [id]
            else:
                print "target in lang %s at %s already has obj with id %s" % (lang,
                target.absolute_url(), id)

    return "ok!"
Пример #2
0
    def block_portlets(self, action):
        status = IStatusMessage(self.request)
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()
        portlet_manager = data.get('portlet_manager', None)
        blockstatus = data.get('blockstatus', False)

        manager = data.get('portlet_manager', None)
        path = "/".join(context.getPhysicalPath())

        if manager is not None:
            managernames = [manager]
        else:
            managernames = utils.get_portlet_manager_names()

        status.addStatusMessage(u'Set portlet block status on %s' % ', '.join(
            managernames), type='info')
        managers = dict()
        for managername in managernames:
            managers[managername] = assignment_mapping_from_key(
                                            context,
                                            managername,
                                            CONTEXT_CATEGORY,
                                            path,
                                            )

        info, warnings, errors = utils.exec_for_all_langs(
                                                    context,
                                                    utils.block_portlets,
                                                    managers=managers,
                                                    blockstatus=blockstatus,
                                                    )

        self.handle_status(status, info, warnings, errors)
Пример #3
0
    def remove_subtype(self, action):
        """ sets ob to given subtype """
        status = IStatusMessage(self.request)
        context = Acquisition.aq_inner(self.context)
        status.addStatusMessage(u'Remove subtype', type='info')

        info, warnings, errors = utils.exec_for_all_langs(
                                                context,
                                                utils.remove_subtype,
                                                )

        self.handle_status(status, info, warnings, errors)
Пример #4
0
    def reindex_all(self, action):
        context = Acquisition.aq_inner(self.context)

        def _setter(ob, *args, **kw):
            ob.reindexObject()

        status = IStatusMessage(self.request)
        status.addStatusMessage(_(u"Reindex object"), type='info')

        info, warnings, errors = utils.exec_for_all_langs(context, _setter)

        self.handle_status(status, info, warnings, errors)
Пример #5
0
    def set_description(self, action):
        status = IStatusMessage(self.request)
        status.addStatusMessage(_(u"Set text as description"), type="info")
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()

        info, warnings, errors = utils.exec_for_all_langs(
                                    context,
                                    utils.set_po_description,
                                    text=data.get('text', ''),
                                    po_domain=data.get('po_domain', ''))

        self.handle_status(status, info, warnings, errors)
Пример #6
0
    def add_subtype(self, action):
        """ sets ob to given subtype """
        status = IStatusMessage(self.request)
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()
        subtype = data.get('subtype')
        status.addStatusMessage(u'Subtype object to %s' % subtype, type='info')
        info, warnings, errors = utils.exec_for_all_langs(
                                                context,
                                                utils.add_subtype,
                                                subtype=subtype,
                                                )

        self.handle_status(status, info, warnings, errors)
Пример #7
0
    def delete_property(self, action):
        """ deletes the given property """
        status = IStatusMessage(self.request)
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()
        property_id = data.get('property_to_delete')
        status.addStatusMessage(u'Delete property %s' % property_id,
            type='info')
        info, warnings, errors = utils.exec_for_all_langs(
                                                context,
                                                utils.delete_property,
                                                property_id=property_id,
                                                )

        self.handle_status(status, info, warnings, errors)
Пример #8
0
    def toggle_outdated(self, action):
        """ sets or unnsets the outdated flag """
        status = IStatusMessage(self.request)
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()
        outdated_status = data.get('outdated_status')
        status.addStatusMessage(u'Set outdated status to %s' % \
            str(outdated_status), type='info')
        info, warnings, errors = utils.exec_for_all_langs(
                                        context,
                                        utils.toggle_outdated,
                                        outdated_status=outdated_status,
                                        )

        self.handle_status(status, info, warnings, errors)
Пример #9
0
    def do_action(self, action):
        data, error = self.extractData()
        transition = data.get('transition')
        status = IStatusMessage(self.request)
        status.addStatusMessage(_(u"Perform workflow-action '%s' on this " \
            u"object and all translations" % transition),
            type="info")
        context = Acquisition.aq_inner(self.context)

        info, warnings, errors = utils.exec_for_all_langs(
                                                context,
                                                utils.workflow_action,
                                                transition=transition,
                                                )

        self.handle_status(status, info, warnings, errors)
Пример #10
0
    def cut_and_paste(self, action):
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()
        target_path = data.get('target_path', '')
        id_to_move = data.get('id_to_move', '')
        status = IStatusMessage(self.request)
        status.addStatusMessage(_(u"Move object %s to %s" % (id_to_move,
            target_path)), type="info")

        info, warnings, errors = utils.exec_for_all_langs(
                                                context,
                                                utils.cut_and_paste,
                                                target_path=target_path,
                                                id_to_move=id_to_move,
                                                target_id=id_to_move)
        self.handle_status(status, info, warnings, errors)
Пример #11
0
    def rename(self, action):
        status = IStatusMessage(self.request)
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()
        old_id = data.get('old_id', '')
        new_id = data.get('new_id', '')
        status.addStatusMessage(u'Rename from %s to %s.' % (old_id, new_id),
            type="info")
        info, warnings, errors = utils.exec_for_all_langs(
                                                context,
                                                utils.renamer,
                                                oldid=old_id,
                                                newid=new_id,
                                                )

        self.handle_status(status, info, warnings, errors)
Пример #12
0
    def remove_interface(self, action):
        data, error = self.extractData()
        interface_to_remove = data.get('interface_to_remove')
        status = IStatusMessage(self.request)
        status.addStatusMessage(_(u"Remove marker interface '%s' on this " \
            u"object and all translations" % interface_to_remove),
            type="info")
        context = Acquisition.aq_inner(self.context)

        info, warnings, errors = utils.exec_for_all_langs(
                                    context,
                                    utils.remove_interface,
                                    interface_to_remove=interface_to_remove,
                                    )

        self.handle_status(status, info, warnings, errors)
Пример #13
0
    def delete(self, action):
        """ sets ob to given subtype """
        status = IStatusMessage(self.request)
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()
        id_to_delete = data.get('id_to_delete')
        status.addStatusMessage(u'Delete object %s' % id_to_delete,
            type='info')
        info, warnings, errors = utils.exec_for_all_langs(
                                                context,
                                                utils.delete_this,
                                                id_to_delete=id_to_delete,
                                                target_id=id_to_delete,
                                                )

        self.handle_status(status, info, warnings, errors)
Пример #14
0
    def set_property(self, action):
        """ sets the given property """
        status = IStatusMessage(self.request)
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()
        property_id = data.get('property_id')
        property_value = data.get('property_value')
        if isinstance(property_value, unicode):
            property_value = property_value.encode('utf-8')
        status.addStatusMessage(u'Set property %s' % property_id, type='info')
        info, warnings, errors = utils.exec_for_all_langs(
                                    context,
                                    utils.set_property,
                                    property_id=property_id,
                                    property_type=data.get('property_type'),
                                    property_value=property_value,
                                    )

        self.handle_status(status, info, warnings, errors)
Пример #15
0
    def set_title(self, action):
        status = IStatusMessage(self.request)
        status.addStatusMessage(_(u"Set text as title"), type="info")
        context = Acquisition.aq_inner(self.context)
        data, error = self.extractData()

        info, warnings, errors = utils.exec_for_all_langs(
                                    context,
                                    utils.set_po_title,
                                    text=data.get('text', ''),
                                    po_domain=data.get('po_domain', ''))

        for msg in info:
            status.addStatusMessage(msg, type='info')
        for msg in warnings:
            status.addStatusMessage(msg, type='warning')
        for msg in errors:
            status.addStatusMessage(msg, type='error')

        self.request.response.redirect(self.context.REQUEST.get('URL'))
Пример #16
0
def delete_item(context, path, id):

    obj = context.restrictedTraverse(path)
    info, warnings, errors = utils.exec_for_all_langs(obj, utils.delete_this, id_to_delete=id, target_id=id)
Пример #17
0
def reindex(context, path):
    def _setter(ob, *args, **kw):
        ob.reindexObject()

    obj = context.restrictedTraverse(path)
    info, warnings, errors = utils.exec_for_all_langs(obj, _setter)
Пример #18
0
def make_private(context, path):
    obj = context.restrictedTraverse(path)
    info, warnings, errors = utils.exec_for_all_langs(obj, utils.workflow_action, transition="reject")
Пример #19
0
def lms_remove_links(context, path):
    obj = context.restrictedTraverse(path)
    info, warnings, errors = utils.exec_for_all_langs(obj, do_link_removal)
Пример #20
0
def make_outdated(context, path):
    obj = context.restrictedTraverse(path)
    info, warnings, errors = utils.exec_for_all_langs(obj, outdate_item, outdated_status=True)
Пример #21
0
def copyLegislation(self):
    portal = getToolByName(self, 'portal_url').getPortalObject()
    folder = getattr(
        portal.en.legislation.directives,
        'provisions-on-workload-ergonomical-and-psychosocial-risks')

    subfolders = self.ZopeFind(obj=folder,
                               search_sub=1,
                               obj_metatypes='ATFolder')
    langs = folder.getTranslationLanguages()
    for subf in subfolders:
        id, ob = subf
        if ob.Language() not in ('en', ''):
            continue
        print "translating folder", ob.absolute_url()
        linguautils.translate_this(ob, [], 0, langs)
        linguautils.exec_for_all_langs(ob,
                                       linguautils.workflow_action,
                                       transition="publish")

    documents = self.ZopeFind(obj=folder,
                              search_sub=1,
                              obj_metatypes='ATDocument')
    for doc in documents:
        id, ob = doc
        if ob.Language() not in ('en', ''):
            continue
        print "translating document", ob.absolute_url()
        linguautils.translate_this(ob, ['title', 'description', 'text'], 0,
                                   langs)
        linguautils.exec_for_all_langs(ob,
                                       linguautils.workflow_action,
                                       transition="publish")

    print "folder:", folder
    objs = self.ZopeFind(obj=folder, search_sub=1, obj_metatypes='Collage')

    for item in objs:
        id, ob = item
        id = id.split('/')[-1]
        print "id:", id
        print "url", ob.absolute_url()
        print item
        parent = Acquisition.aq_parent(ob)
        print parent
        parentlang = parent.Language()
        trans = parent.getTranslations()
        for lang in trans.keys():
            if lang == parentlang:
                continue
            target = trans[lang][0]
            #            if getattr(Acquisition.aq_base(target), id, None) and type(getattr(Acquisition.aq_base(target), id, None)) == type(ob):
            #                target.manage_delObjects(id)
            if not getattr(Acquisition.aq_base(target), id, None) or not \
            type(getattr(Acquisition.aq_base(target), id, None))==type(ob):
                cp = ob._getCopy(ob)
                target._setObject(id, cp)
                print "doing the copying", cp, [id]
            else:
                print "target in lang %s at %s already has obj with id %s" % (
                    lang, target.absolute_url(), id)

    return "ok!"
Пример #22
0
def make_expired(context, path):
    obj = context.restrictedTraverse(path)
    date = DateTime() - 1
    info, warnings, errors = utils.exec_for_all_langs(obj, expire_item, date=date)