How to use the zope.component.adapter function in Zope

To help you get started, we’ve selected a few Zope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plone / plone.app.dexterity / plone / app / dexterity / browser / types.py View on Github external
elif len(selected) > 0:
            url = '{0}/@@models-export?selected={1}'.format(
                self.context.context.absolute_url(),
                urllib.parse.quote(selected)
            )
            self.request.response.redirect(url)


class TypesEditFormWrapper(FormWrapper):
    """ Render Plone frame around our form with little modifications """

    form = TypeEditForm
    index = FiveViewPageTemplateFile('typesformwrapper.pt')


@adapter(IDexterityFTI)
@implementer(ITypeSettings)
class TypeSettingsAdapter(object):

    def __init__(self, context):
        self.context = context

    @property
    def id(self):
        return self.context.getId()

    title = UTF8Property('title')
    description = UTF8Property('description')

    @property
    def container(self):
        return self.context.container
github plone / plone.app.dexterity / plone / app / dexterity / permissions.py View on Github external
# if we have explicit permissions, check them
                permission = queryUtility(
                    IPermission,
                    name=permission_name
                )
                if permission:
                    return checker(permission.title, context)

            # If the field is in the schema, but no permission is
            # specified, fall back to the default edit permission
            return checker(self.DEFAULT_PERMISSION, context)
        else:
            raise AttributeError('No such field: {0}'.format(field_name))


@adapter(IForm)
class GenericFormFieldPermissionChecker(DXFieldPermissionChecker):
    """Permission checker for when we just have an add view"""

    DEFAULT_PERMISSION = 'Add portal content'

    def __init__(self, view):
        if getattr(view, 'form_instance', None) is not None:
            view = view.form_instance
        if getattr(view, 'create', None):
            content = view.create({})
            self.context = content.__of__(view.context)
        else:
            self.context = view.context

        self._request = MockRequest()
        self.view = view
github plone / plone.restapi / src / plone / restapi / serializer / __init__.py View on Github external
@adapter(IPloneSiteRoot)
def SerializeSiteRootToJson(context):
    result = {
        '@context': 'http://www.w3.org/ns/hydra/context.jsonld',
        '@id': context.absolute_url(),
        '@type': 'SiteRoot',
        'parent': {},
    }
    result['member'] = [
        {
            '@id': member.absolute_url(),
            'title': member.title,
            'description': member.description
        }
        for member in context.objectValues()
        if IContentish.providedBy(member)
    ]
github plone / plone.schemaeditor / plone / schemaeditor / browser / field / edit.py View on Github external
_marker = object()


class IFieldTitle(Interface):
    title = schema.TextLine(
        title=schema.interfaces.ITextLine['title'].title,
        description=schema.interfaces.ITextLine['title'].description,
        default=u'',
        required=True,
    )


@implementer(IFieldTitle)
@adapter(IField)
class FieldTitleAdapter(object):

    def __init__(self, field):
        self.field = field

    def _read_title(self):
        return self.field.title

    def _write_title(self, value):
        self.field.title = value
    title = property(_read_title, _write_title)


class IFieldProxy(Interface):
    """Marker interface for field being edited by schemaeditor"""
github zopefoundation / z3c.form / src / z3c / form / browser / checkbox.py View on Github external
@zope.component.adapter(zope.schema.interfaces.IBool, interfaces.IFormLayer)
@zope.interface.implementer(interfaces.IFieldWidget)
def SingleCheckBoxFieldWidget(field, request):
    """IFieldWidget factory for CheckBoxWidget."""
    widget = FieldWidget(field, SingleCheckBoxWidget(request))
    widget.label = u'' # don't show the label twice
    return widget
github plone / plone.restapi / src / plone / restapi / deserializer / controlpanels.py View on Github external
from zope.schema import getFields
from zope.schema.interfaces import ValidationError
from plone.dexterity.interfaces import IDexterityContent
from zope.component import queryMultiAdapter
from plone.restapi.interfaces import IFieldDeserializer
from z3c.form.interfaces import IManagerValidator


@implementer(IDexterityContent)
class FakeDXContext(object):
    """Fake DX content class, so we can re-use the DX field deserializers
    """


@implementer(IDeserializeFromJson)
@adapter(IControlpanel)
class ControlpanelDeserializeFromJson(object):
    def __init__(self, controlpanel):
        self.controlpanel = controlpanel
        self.schema = self.controlpanel.schema
        self.schema_prefix = self.controlpanel.schema_prefix

        self.registry = getUtility(IRegistry)

        self.context = self.controlpanel.context
        self.request = self.controlpanel.request

    def __call__(self):
        data = json_body(self.controlpanel.request)

        proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix)
github mgedmin / zodbbrowser / src / zodbbrowser / value.py View on Github external
class DecoyPersistentDict(PersistentMapping):
        """Decoy to avoid ZCML errors while supporting both ZODB 3.8 and 3.9."""

    @adapter(DecoyPersistentDict)
    class PersistentDictValue(PersistentValue):
        """Decoy to avoid ZCML errors while supporting both ZODB 3.8 and 3.9."""
        delegate_to = DictValue

else:  # pragma: nocover
    @adapter(PersistentDict)
    class PersistentDictValue(PersistentValue):
        delegate_to = DictValue


@adapter(ProvidesClass)
@implementer(IValueRenderer)
class ProvidesValue(GenericValue):
    """zope.interface.Provides object renderer.

    The __repr__ of zope.interface.Provides is decidedly unhelpful.
    """

    def _repr(self):
        return '' % ', '.join(i.__identifier__
                                            for i in self.context._Provides__args[1:])
github zopefoundation / z3c.form / src / z3c / form / browser / checkbox.py View on Github external
@zope.component.adapter(zope.schema.interfaces.IField, interfaces.IFormLayer)
@zope.interface.implementer(interfaces.IFieldWidget)
def CheckBoxFieldWidget(field, request):
    """IFieldWidget factory for CheckBoxWidget."""
    return FieldWidget(field, CheckBoxWidget(request))
github zopefoundation / z3c.form / src / z3c / form / term.py View on Github external
@zope.component.adapter(
    zope.interface.Interface,
    interfaces.IFormLayer,
    zope.interface.Interface,
    zope.schema.interfaces.ICollection,
    interfaces.IWidget)
def CollectionTerms(context, request, form, field, widget):
    terms = field.value_type.bind(context).vocabulary
    return zope.component.queryMultiAdapter(
        (context, request, form, field, terms, widget),
        interfaces.ITerms)
github socialplanning / opencore / opencore / nui / project / preferences.py View on Github external
@adapter(IProject, IObjectWillBeRemovedEvent)
def handle_flet_uninstall(project, event=None):
    supporter = IFeatureletSupporter(project)
    for flet_id in supporter.getInstalledFeatureletIds():
        supporter.removeFeaturelet(flet_id, raise_error=False)