def registerTransform(context, name, module):
    transforms = getToolByName(context, 'portal_transforms')
    if name not in transforms.objectIds():
        transforms.manage_addTransform(name, module)
        LOG.info("Registered transform '%s'" % name)
    else:
        LOG.info("Transform '%s' always registered" % name)
def unregisterTransform(context, name):
    transforms = getToolByName(context, 'portal_transforms')
    if name in transforms.objectIds():
        transforms.unregisterTransform(name)
        LOG.info("Removed transform '%s'" % name)
    else:
        LOG.info("Transform '%s' was not registered" % name)
예제 #3
0
    def __call__(self):
        pm = self.context.portal_membership
        # Comma separated member IDs
        userids = self.request.get('userids', None)
        new_editor = self.request.get('editor', '').strip()
        if userids is None:
            userids = pm.listMemberIds()
        else:
            userids = userids.split(',')

        available = self.context.portal_properties.site_properties.available_editors
        if new_editor != '' and new_editor not in available:
            return u'Editor %s is not supported by site_properties.available_editors: %s' % (new_editor, available)

        total_members = len(userids)
        total = 0
        for memberId in userids:
            member = pm.getMemberById(memberId)
            if member:
                editor = member.getProperty('wysiwyg_editor', None)
                if editor != new_editor:
                    total += 1
                    member.setMemberProperties({'wysiwyg_editor': new_editor})
                    if new_editor:
                        LOG.info('%s: Editor %s has been set.', memberId, new_editor)
                    else:
                        LOG.info('%s: Default editor has been set', memberId)
        if new_editor:
            return u'Editor %s has been set for %d members out of %d' % (new_editor, total, total_members)
        else:
            return u'Default editor has been set for %d members out of %d.' % (total, total_members)
def uninstallControlPanel(context):
    """
    Uninstall CKeditor control panel
    Since the xml uninstall profile does not work
    """
    controlpanel = getToolByName(context, 'portal_controlpanel')
    controlpanel.unregisterConfiglet(id='CKEditor')
    LOG.info("CKEditor configlet removed")
def importFinalSteps(context):

    if context.readDataFile('collective.ckeditor.txt') is None:
        return
    site = context.getSite()
    registerTransform(site, 'ck_ruid_to_url',
                      'collective.ckeditor.transforms.ck_ruid_to_url')
    registerTransformPolicy(site, DOCUMENT_DEFAULT_OUTPUT_TYPE,
                            REQUIRED_TRANSFORM)
    LOG.info('CKEditor for Plone installed')
예제 #6
0
def uninstallSteps(context):
    if context.readDataFile('collective.ckeditor.uninstall.txt') is None:
        return
    site = context.getSite()
    uninstallControlPanel(site)
    uninstallSiteProperties(site)
    unregisterTransform(site, 'ck_ruid_to_url')
    unregisterTransformPolicy(site, DOCUMENT_DEFAULT_OUTPUT_TYPE,
                              REQUIRED_TRANSFORM)
    LOG.info('CKEditor for Plone uninstalled')
def unregisterTransformPolicy(context, output_mimetype, required_transform):
    transforms = getToolByName(context, 'portal_transforms')
    tpolicies = transforms.listPolicies()
    for p in tpolicies:
        out_type = p[0]
        if out_type == output_mimetype:
            policies = list(p[1])
            if required_transform in policies:
                policies.remove(required_transform)
                transforms.manage_delPolicies([output_mimetype])
                if policies:
                    transforms.manage_addPolicy(output_mimetype, policies)
            break
    LOG.info("Removed transform policy for '%s' mimetype" % output_mimetype)
def registerTransformPolicy(context, output_mimetype, required_transform):
    transforms = getToolByName(context, 'portal_transforms')
    tpolicies = transforms.listPolicies()
    mimetype_registered = False
    for p in tpolicies:
        out_type = p[0]
        if out_type == output_mimetype:
            policies = list(p[1])
            if required_transform not in policies:
                policies.append(required_transform)
                transforms.manage_delPolicies([output_mimetype])
                transforms.manage_addPolicy(output_mimetype, policies)
            mimetype_registered = True
            break
    if not mimetype_registered:
        transforms.manage_addPolicy(output_mimetype, [required_transform])
    LOG.info("Registered policy for '%s' mimetype" % output_mimetype)
예제 #9
0
 def upload_image(self):
     container = component.getMultiAdapter(
         (self.context, self.request),
         name='folder_factories').add_context()
     upload = self.request.form['upload']
     try:
         image = api.content.create(container=container,
                                    type='Image',
                                    file=upload,
                                    id=upload.filename,
                                    safe_id=True)
     except Unauthorized:
         LOG.warning("Upload image not allowed at {}".format(
             container.absolute_url()))
         raise
     navroot = api.portal.get_navigation_root(context=self.context)
     image_url = "/".join(('resolveuid', api.content.get_uuid(image)))
     result = {"uploaded": 1, "fileName": image.getId(), "url": image_url}
     return json.dumps(result)