예제 #1
0
 def portal(self):
     closest_site = getSite()
     if closest_site is not None:
         for potential_portal in closest_site.aq_chain:
             if ISiteRoot in providedBy(potential_portal):
                 return potential_portal
     return None
def _get_portal():
    closest_site = getSite()
    if closest_site is not None:
        for potential_portal in closest_site.aq_chain:
            if ISiteRoot in providedBy(potential_portal):
                return potential_portal
    raise Exception("Unable to get the portal object.")
예제 #3
0
def get_field(context, field_name):
    schema_interfaces = []
    if hasattr(context, 'schema'):
        schema_interfaces = [context.schema]

    for interface in (schema_interfaces or providedBy(context)):
        if field_name in getFieldNames(interface):
            return interface[field_name]
    return None
예제 #4
0
def get_portal():
    """get the Plone portal object.

    It fetched w/o any further context by using the last registered site.
    So this work only after traversal time.
    """
    closest_site = getSite()
    if closest_site is not None:
        for potential_portal in closest_site.aq_chain:
            if IPloneSiteRoot in providedBy(potential_portal):
                return potential_portal
예제 #5
0
def get_portal():
    """get the Plone portal object.

    It fetched w/o any further context by using the last registered site.
    So this work only after traversal time.
    """
    closest_site = getSite()
    if closest_site is not None:
        for potential_portal in closest_site.aq_chain:
            if IPloneSiteRoot in providedBy(potential_portal):
                return potential_portal
예제 #6
0
def Modified(content, event):
    """ Max hooks modified handler """
    # Avoid execution when trigered on sharing changes
    is_sharing_event = providedBy(event)(ILocalrolesModifiedEvent)
    if is_sharing_event:
        return

    portal = getSite()
    pm = getToolByName(portal, 'portal_membership')
    pl = getToolByName(portal, 'portal_languages')
    default_lang = pl.getDefaultLanguage()

    community = findContainerCommunity(content)

    if not community or \
       IAppFile.providedBy(content) or \
       IAppImage.providedBy(content):
        # For some reason the file we are creating is not inside a community
        # or the content is created externaly through apps via the upload ws
        return

    username, oauth_token = getUserOauthToken(pm)
    maxclient = connectMaxclient(username, oauth_token)

    parts = dict(type=tipus[default_lang].get(content.portal_type, ''),
                 name=content.Title().decode('utf-8') or getattr(getattr(content, 'file', u''), 'filename', u'').decode('utf-8') or getattr(getattr(content, 'image', u''), 'filename', u'').decode('utf-8'),
                 link='{}/view'.format(content.absolute_url()),
                 un=articles[default_lang].get(content.portal_type, 'un'))

    activity_text = {
        'ca': u'He modificat {un} {type} "{name}" a {link}',
        'es': u'He modificado {un} {type} "{name}" a {link}',
        'en': u'I\'ve modified {un} {type} "{name}" a {link}',
    }

    addPost = addActivityPost(content)

    if addPost:
        if (content.portal_type == 'Image' or
           content.portal_type == 'File') and \
           content.description:
            activity_text = u'{} {}'.format(content.title, u'{}/view'.format(content.absolute_url()))

            try:
                maxclient.people[username].activities.post(object_content=activity_text, contexts=[dict(url=community.absolute_url(), objectType='context')])
            except:
                logger.warning('The username {} has been unable to post the default object creation message'.format(username))
        else:
            try:
                maxclient.people[username].activities.post(object_content=activity_text[default_lang].format(**parts), contexts=[dict(url=community.absolute_url(), objectType='context')])
            except:
                logger.warning('The username {} has been unable to post the default object creation message'.format(username))
예제 #7
0
def get():
    """Get the Plone portal object out of thin air.

    Without the need to import fancy Interfaces and doing multi adapter
    lookups.

    :returns: Plone portal object
    :rtype: Portal object
    :Example: :ref:`portal_get_example`
    """

    closest_site = getSite()
    if closest_site is not None:
        for potential_portal in closest_site.aq_chain:
            if ISiteRoot in providedBy(potential_portal):
                return potential_portal

    raise CannotGetPortalError(
        "Unable to get the portal object. More info on "
        "https://ploneapi.readthedocs.org/en/latest/api/exceptions.html"
        "#plone.api.exc.CannotGetPortalError")
예제 #8
0
def migrate_image_to_file(obj):
    image = obj.getImage()

    # Use the functionality of the UpgradeStep
    class MigrateToFile(UpgradeStep):
        def __call__(self):
            # This is an AT => AT migration; we just replace the class.
            self.migrate_class(obj, File)

    MigrateToFile(obj.portal_setup)

    # clear archetypes.schemaextender cache
    getattr(obj.REQUEST, CACHE_KEY).pop(IUUID(obj), None)

    ifaces_to_remove = (set(providedBy(obj)) -
                        set(implementedBy(obj.__class__)))
    map(partial(noLongerProvides, obj), ifaces_to_remove)

    obj.Schema()
    obj.setFile(image)
    obj.setDocumentDate(obj.created())
    obj.portal_type = 'File'
예제 #9
0
def get():
    """Get the Plone portal object out of thin air.

    Without the need to import fancy Interfaces and doing multi adapter
    lookups.

    :returns: Plone portal object
    :rtype: Portal object
    :Example: :ref:`portal_get_example`
    """

    closest_site = getSite()
    if closest_site is not None:
        for potential_portal in closest_site.aq_chain:
            if ISiteRoot in providedBy(potential_portal):
                return potential_portal

    raise CannotGetPortalError(
        "Unable to get the portal object. More info on "
        "https://ploneapi.readthedocs.org/en/latest/api/exceptions.html"
        "#plone.api.exc.CannotGetPortalError"
    )
예제 #10
0
def update_thumbnails_on_create(obj, event):
    for iface in component.providedBy(obj).flattened():
        for fname, field in schema.getFields(iface).items():
            if IImageField.providedBy(field):
                update_thumbs(obj, fname)