from .rendering import ImageFactory

def _iter_block_image_factories():
    for factory in Configuration.instance.image_factories:
        if factory.applicable_to_blocks:
            yield factory

def _block_image_factories_enumeration(ctx):
    return list(_iter_block_image_factories())

_block_image_factories_default = schema.DynamicDefault(
    lambda: first(_iter_block_image_factories())
)

_mandatory_dropdown = display_factory(
    "cocktail.html.DropdownSelector",
    empty_option_displayed = False
)


class BlockImageFactoryReference(schema.Reference):

    def __init__(self, *args, **kwargs):
        
        kwargs.setdefault("required", True)
        kwargs.setdefault("type", ImageFactory)
        kwargs.setdefault("enumeration", _block_image_factories_enumeration)
        kwargs.setdefault("default", _block_image_factories_default)                
        kwargs.setdefault("edit_control", _mandatory_dropdown)

        if "bidirectional" not in kwargs and "related_end" not in kwargs:
            kwargs["related_end"] = schema.Collection()
Пример #2
0
.. moduleauthor:: Martí Congost <*****@*****.**>
"""
from cocktail.modeling import extend, call_base
from cocktail.translations import translations
from cocktail import schema
from cocktail.html.datadisplay import display_factory
from woost.models import Publishable

Publishable.add_member(
    schema.Reference(
        "access_restriction",
        type="woost.extensions.restrictedaccess.accessrestriction."
        "AccessRestriction",
        bidirectional=True,
        indexed=True,
        edit_control=display_factory("cocktail.html.RadioSelector",
                                     empty_option_displayed=True),
        search_control="cocktail.html.DropdownSelector",
        member_group="publication"))


@extend(Publishable.access_restriction)
def translate_value(self, value, language=None, **kwargs):

    if not value:
        return translations("Publishable.access_restriction=None", language,
                            **kwargs)

    return call_base(value, language, **kwargs)
Пример #3
0
                   default=True,
                   listed_by_default=False,
                   member_group="meta.open_graph"))

Publishable.add_member(
    schema.Reference("open_graph_type",
                     type=OpenGraphType,
                     required=Publishable["open_graph_enabled"],
                     related_end=schema.Collection(block_delete=True),
                     default=schema.DynamicDefault(
                         lambda: OpenGraphType.get_instance(code="article")),
                     indexed=True,
                     listed_by_default=False,
                     member_group="meta.open_graph",
                     edit_control=display_factory(
                         "cocktail.html.DropdownSelector",
                         grouping=lambda type: type.category)))


def _get_publishable_properties(self):

    properties = {
        "og:title": translations(self),
        "og:type": self.open_graph_type.code,
        "og:url": self.get_uri(host=".")
    }

    image = self.get_open_graph_image()
    if image:
        if isinstance(image, Publishable):
            image = image.get_image_uri("facebook", host=".")
Пример #4
0
class Role(Item):
    """A set of capabilities assigned to one or more users.
    
    Each role defines an access profile for a distinct set of application users
    (editors, moderators, administrators, etc.). By grouping users into roles,
    managing permissions and defining the access policy for a site becomes
    easier.

    Roles can also extend other roles. A derived role will inherit all
    permissions from its base roles, recursively. This ability makes it
    possible to grow a site's access policy by means of specialization.
    """
    type_group = "users"

    members_order = [
        "title", "base_roles", "child_roles", "users", "permissions",
        "user_views", "default_content_type", "hidden_content_types"
    ]

    title = schema.String(required=True,
                          unique=True,
                          indexed=True,
                          normalized_index=True,
                          full_text_indexed=True,
                          descriptive=True,
                          translated=True)

    base_roles = schema.Collection(items="woost.models.Role",
                                   bidirectional=True)

    child_roles = schema.Collection(items="woost.models.Role",
                                    bidirectional=True,
                                    editable=False)

    users = schema.Collection(items="woost.models.User", bidirectional=True)

    permissions = schema.Collection(items="woost.models.Permission",
                                    bidirectional=True,
                                    integral=True)

    user_views = schema.Collection(items="woost.models.UserView",
                                   bidirectional=True)

    default_content_type = schema.Reference(class_family=Item)

    hidden_content_types = schema.Collection(
        items=schema.Reference(class_family=Item),
        edit_inline=True,
        edit_control=display_factory(
            "woost.views.ContentTypePicker",
            selection_mode=MULTIPLE_SELECTION,
            filter_item=lambda content_type: content_type.visible and
            content_type.visible_from_root))

    implicit = schema.Boolean(required=True,
                              default=False,
                              indexed=True,
                              editable=False)

    def iter_roles(self, include_self=True, recursive=True):
        """Iterates over the role and its bases.

        Roles are sorted from most specific to most general.

        @param include_self: If True, the role itself will be included in the
            produced sequence. If False, the role will be excluded and only its
            bases (and their bases, depending on the value of L{recursive})
            will be yielded.
        @type: bool

        @param recursive: If True, the method will be called recursively on
            each base role, producing the whole inheritance tree.
        @type recursive: bool

        @return: An iterable sequence containing the role and its bases.
        @rtype: L{Role} sequence
        """
        if include_self:
            yield self

        if recursive:
            for base in self.base_roles:
                for ancestor in base.iter_roles():
                    yield ancestor
        else:
            for base in self.base_roles:
                yield base

    def iter_permissions(self, permission_type=None):
        """Iterates over the permissions granted to the role.

        Both the role's own permissions and those inherited from its bases are
        returned.

        @param permission_type: If given, restricts the list of returned
            permissions to those of the given type (or a subclass of that
            type). By default, all permissions are yielded, regardless of their
            type.
        @type permission_type: L{Permission} subclass

        @return: An iterable sequence of permissions granted to the role and
            its bases.
        @rtype: L{Permission} sequence
        """
        for permission in self.permissions:
            if permission_type is None or isinstance(permission,
                                                     permission_type):
                yield permission

        for base_role in self.base_roles:
            for permission in base_role.iter_permissions(permission_type):
                yield permission