How to use the guillotina.schema 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 / test_package.py View on Github external
class IExample(IResource):

    metadata("categories")

    index_field("boolean_field", type="boolean")
    boolean_field = schema.Bool(required=False)

    index_field("categories", field_mapping=CATEGORIES_MAPPING)
    categories = schema.List(
        title="categories", default=[], value_type=schema.JSONField(title="term", schema=TERM_SCHEMA)
    )

    textline_field = schema.TextLine(title="kk", widget="testing", required=False)
    text_field = schema.Text(required=False)
    dict_value = schema.Dict(key_type=schema.TextLine(), value_type=schema.TextLine(), required=False)
    datetime = schema.Datetime(required=False)

    write_permission(write_protected="example.MyPermission")
    write_protected = schema.TextLine(title="Write protected field", required=False)

    default_factory_test = schema.Text(defaultFactory=lambda: "foobar")

    context_default_factory_test = schema.Text(defaultFactory=ContextDefaultFactory())


@index_field.with_accessor(IExample, "categories_accessor", field="categories")
def categories_index_accessor(ob):
    if not ob.categories:
        raise NoIndexField
    else:
github plone / guillotina / guillotina / interfaces / text.py View on Github external
from zope.interface import Interface


_ = MessageFactory('guillotina')


class IRichText(IObject):
    """A text field that stores MIME type
    """

    default_mime_type = schema.ASCIILine(
        title=_(u"Default MIME type"),
        default='text/html',
    )

    output_mime_type = schema.ASCIILine(
        title=_(u"Default output MIME type"),
        default='text/x-html-safe'
    )

    allowed_mime_types = schema.Tuple(
        title=_(u"Allowed MIME types"),
        description=_(u"Set to None to disable checking"),
        default=None,
        required=False,
        value_type=schema.ASCIILine(title=u"MIME type"),
    )

    max_length = schema.Int(
        title=_(u'Maximum length'),
        description=_(u'in characters'),
        required=False,
github plone / guillotina / guillotina / interfaces / content.py View on Github external
required=False,
        default=None,
        readonly=True,
    )


class IResource(IBaseObject, ILocation):

    __acl__ = Attribute("")
    __gannotations__ = Attribute("")
    __uuid__ = Attribute("database object unique id")

    id = Attribute("")
    creators = Attribute("")
    contributors = Attribute("")
    type_name = guillotina.schema.TextLine(readonly=True)

    title = guillotina.schema.TextLine(
        title="Title", required=False, description="Title of the Resource", default=""
    )

    uuid = guillotina.schema.TextLine(title="UUID", required=True, readonly=True)

    modification_date = guillotina.schema.Datetime(title="Modification date", required=False)

    creation_date = guillotina.schema.Datetime(title="Creation date", required=False)

    __behaviors__ = guillotina.schema.FrozenSet(
        title="Enabled behaviors",
        required=False,
        description="Dynamic behaviors for the content type",
        default=frozenset({}),
github plone / guillotina / guillotina / documentation / __init__.py View on Github external
from guillotina import configure
from guillotina import schema
from guillotina.addons import Addon
from zope.interface import Interface


class IRegistryData(Interface):
    foobar = schema.TextLine()


@configure.addon(name="docaddon", title="Doc addon")
class TestAddon(Addon):
    @classmethod
    def install(cls, container, request):
        Addon.install(container, request)

    @classmethod
    def uninstall(cls, container, request):
        Addon.uninstall(container, request)
github plone / guillotina / guillotina / schema / fieldproperty.py View on Github external
def createFieldProperties(schema, omit=None):
    """Creates a FieldProperty fields in `schema` on the class it is called on.

    schema ... interface those fields should be added to class
    omit ... list of field names to be omitted in creation

    """
    omit = omit or []
    frame = sys._getframe(1)
    for name in guillotina.schema.getFieldNamesInOrder(schema):
        if name in omit:
            continue
        frame.f_locals[name] = FieldProperty(schema[name])
github plone / guillotina / guillotina / contrib / dbusers / content / users.py View on Github external
from guillotina.directives import read_permission
from guillotina.directives import write_permission
from guillotina.interfaces import Allow
from guillotina.interfaces import IFolder
from guillotina.interfaces import IPrincipal

import typing


class IUserManager(IFolder):
    pass


class IUser(IFolder, IPrincipal):

    username = schema.TextLine(title=_("Username"), required=False)

    index_field("email", index_name="user_email", type="keyword")
    email = schema.TextLine(title=_("Email"), required=False)

    index_field("name", index_name="user_name", type="textkeyword")
    name = schema.TextLine(title=_("Name"), required=False)

    read_permission(password="guillotina.Nobody")
    password = schema.TextLine(title=_("Password"), required=False)

    write_permission(user_groups="guillotina.ManageUsers")
    user_groups = schema.List(title=_("Groups"), value_type=schema.TextLine(), required=False)

    write_permission(user_roles="guillotina.ManageUsers")
    index_field("user_roles", type="textkeyword")
    user_roles = schema.List(title=_("Roles"), value_type=schema.TextLine(), required=False)
github plone / guillotina / guillotina / behaviors / dynamic.py View on Github external
class IFieldType(Interface):
    title = schema.Text(required=False)
    description = schema.Text(required=False)
    type = schema.Choice(values=["date", "integer", "text", "float", "keyword", "boolean"])
    required = schema.Bool(default=False, required=False)
    meta = schema.JSONField(
        title="Additional information on field",
        required=False,
        schema=json.dumps({"type": "object", "properties": {}}),
    )


class IDynamicFields(Interface):
    fields = fields.PatchField(
        schema.Dict(key_type=schema.Text(), value_type=schema.Object(schema=IFieldType))
    )


@configure.behavior(title="Dynamic fields", provides=IDynamicFields, for_="guillotina.interfaces.IResource")
class DynamicFieldsBehavior(ContextBehavior):
    """
    context behavior so we don't have to do an async load here...
    the data here shouldn't be very large as well
    """

    auto_serialize = False


class IDynamicFieldValues(Interface):
    values = fields.DynamicField(schema.Dict(key_type=schema.Text()))
github plone / guillotina / guillotina / fields / dynamic.py View on Github external
return field_converter(field, value, context)


class IDynamicType(Interface):
    """
    Used to dynamicly bind data to validate
    new values against
    """

    date = schema.Datetime(required=False)
    text = schema.Text(required=False)
    integer = schema.Int(required=False)
    float = schema.Float(required=False)
    boolean = schema.Bool(required=False)
    keyword = schema.UnionField(
        schema.List(required=False, value_type=schema.Text()), schema.Text(required=False), required=False
    )


def _validate_field(field, context, value):
    if "key" not in value or "value" not in value:
        raise ValueDeserializationError(field, value, f"Invalid data")

    from guillotina.behaviors.dynamic import find_field

    field = find_field(context, value["key"])
    # now, verify value...
    if not field:
        raise ValueDeserializationError(field, value, f"Dynamic field not found")
    field_type = field.get("type", "unknown")
    try:
        valid_type = namedtuple("temp_assign_type", [field_type])
github plone / guillotina / guillotina / interfaces / content.py View on Github external
class IResourceFactory(IFactory):

    type_name = guillotina.schema.TextLine(
        title="Portal type name", description="The portal type this is an FTI for"
    )

    schema = guillotina.schema.DottedName(
        title="Schema interface",
        description="Dotted name to an interface describing the type. "
        "This is not required if there is a model file or a "
        "model source string containing an unnamed schema.",
    )

    behaviors = guillotina.schema.List(
        title="Behaviors",
        description="A list of behaviors that are enabled for this type. "
        "See guillotina.behaviors for more details.",
        value_type=guillotina.schema.DottedName(title="Behavior name"),
    )

    add_permission = guillotina.schema.DottedName(
        title="Add permission",
        description="A oermission name for the permission required to " "construct this content",
    )


class IFolder(IResource, IAsyncContainer, ITraversable):
    """
    """
github plone / guillotina / guillotina / interfaces / text.py View on Github external
description=_(u'in characters'),
        required=False,
        min=0,
        default=None,
    )


class IRichTextValue(Interface):
    """The value actually stored in a RichText field.
    This stores the following values on the parent object
      - A separate persistent object with the original value
      - A cache of the value transformed to the default output type
    The object is immutable.
    """

    raw = schema.Text(
        title=_(u"Raw value in the original MIME type"),
        readonly=True,
    )

    mimeType = schema.ASCIILine(
        title=_(u"MIME type"),
        readonly=True,
    )

    outputMimeType = schema.ASCIILine(
        title=_(u"Default output MIME type"),
        readonly=True,
    )

    encoding = schema.ASCIILine(
        title=_(u"Default encoding for the value"),