How to use the guillotina.configure function in guillotina

To help you get started, we’ve selected a few guillotina 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 / guillotina / guillotina / renderers.py View on Github external
return value.encode("utf-8")
        return None


class StringRenderer(Renderer):
    content_type = "text/plain"

    def get_body(self, value) -> bytes:
        if not isinstance(value, bytes):
            if not isinstance(value, str):
                value = ujson.dumps(value)
            value = value.encode("utf8")
        return value


@configure.renderer(name="text/html")
@configure.renderer(name="text/*")
class RendererHtml(Renderer):
    content_type = "text/html"

    def get_body(self, value: IResponse) -> Optional[bytes]:
        body = super().get_body(value)
        if body is not None:
            if b"" + body + b""
        return body


@configure.renderer(name="text/plain")
class RendererPlain(StringRenderer):
    content_type = "text/plain"
github plone / guillotina / guillotina / documentation / _generate.py View on Github external
name="myaddon",
        title="My addon")
    class MyAddon(Addon):

        @classmethod
        def install(cls, container, request):
            # install code
            pass

        @classmethod
        def uninstall(cls, container, request):
            # uninstall code
            pass

    config = aioapp.config
    configure.load_configuration(
        config, 'guillotina.documentation', 'addon')
    aioapp.config.execute_actions()
    load_cached_schema()
github plone / guillotina / guillotina / db / strategies / lock.py View on Github external
if "during rolling upgrades" in e.payload['message']:
                            response = False
                            some_request_failed = True
                        else:
                            raise

                if some_request_failed:
                    if not self._use_proxies:
                        # The cluster may have changed since last invocation
                        self._machines_cache = await self.machines()
                    if self._base_uri in self._machines_cache:
                        self._machines_cache.remove(self._base_uri)
            return response


@configure.adapter(
    for_=(IStorage, ITransaction),
    provides=ILockingStrategy, name="lock")
class LockStrategy(TIDOnlyStrategy):
    '''
    *this strategy relies on using etcd for locking*

    A transaction strategy that depends on locking objects in order to safely
    write to them.

    Application logic needs to implement the object locking.

    Unlocking should be done in the tpc_finish phase.
    '''

    def __init__(self, storage, transaction):
        self._storage = storage
github plone / guillotina / guillotina / behaviors / dublincore.py View on Github external
publisher = schema.Text(
        title="Publisher",
        description="The first unqualified Dublin Core 'Publisher' element value.",
        required=False,
    )

    contributors = schema.Tuple(
        title="Contributors",
        description="The unqualified Dublin Core 'Contributor' element values",
        value_type=schema.TextLine(),
        required=False,
    )


@configure.behavior(
    title="Dublin Core fields",
    provides=IDublinCore,
    marker=IMarkerDublinCore,
    for_="guillotina.interfaces.IResource",
)
class DublinCore(AnnotationBehavior):
    auto_serialize = True

    title = ContextProperty("title", None)
    creators = ContextProperty("creators", ())
    contributors = ContextProperty("contributors", ())
    creation_date = ContextProperty("creation_date", None)
    modification_date = ContextProperty("modification_date", None)
    tags = ContextProperty("tags", None)

    def __init__(self, context):
github plone / guillotina / guillotina / json / definitions.py View on Github external
from guillotina import configure


configure.json_schema_definition(
    "Addon",
    {
        "type": "object",
        "title": "Addon data",
        "properties": {"id": {"type": "string"}, "title": {"type": "string"}},
        "required": ["id"],
    },
)


configure.json_schema_definition(
    "AddonResponse",
    {
        "type": "object",
        "title": "Addons response data",
        "properties": {
github plone / guillotina / guillotina / db / strategies / simple.py View on Github external
from guillotina import configure
from guillotina import glogging
from guillotina.db.interfaces import IDBTransactionStrategy
from guillotina.db.interfaces import ITransaction
from guillotina.db.strategies.base import BaseStrategy


logger = glogging.getLogger("guillotina")


@configure.adapter(for_=ITransaction, provides=IDBTransactionStrategy, name="simple")
class SimpleStrategy(BaseStrategy):
    """
    Do not attempt to resolve conflicts but detect for them
    """

    async def tpc_begin(self):
        await self.retrieve_tid()
        await self._storage.start_transaction(self._transaction)

    async def tpc_vote(self):
        if not self.writable_transaction:
            return True

        current_tid = await self._storage.get_current_tid(self._transaction)
        if current_tid > self._transaction._tid:
            logger.warn(
github plone / guillotina / guillotina / annotations.py View on Github external
logger = logging.getLogger('guillotina')
_marker = object()


@implementer(IAnnotationData)
class AnnotationData(BaseObject, UserDict):
    """
    store data on basic dictionary object but also inherit from base object
    """


@configure.adapter(
    for_=IRegistry,
    provides=IAnnotations)
@configure.adapter(
    for_=IResource,
    provides=IAnnotations)
class AnnotationsAdapter(object):
    """Store annotations on an object
    """

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

    def get(self, key, default=None):
        """
        non-async variant
        """
        annotations = self.obj.__gannotations__
        if key in annotations:
            return annotations[key]
github plone / guillotina / guillotina / api / search.py View on Github external
@configure.service(
    context=IResource,
    method="DELETE",
    permission="guillotina.ManageCatalog",
    name="@catalog",
    summary="Delete search catalog",
    responses={"200": {"description": "Successfully deleted catalog"}},
)
async def catalog_delete(context, request):
    search = query_utility(ICatalogUtility)
    await search.remove_catalog(context)
    return {}