Exemple #1
0
    def create_deform(self, schema: colander.Schema, request: Request, context: object, mode: EditMode, buttons: List[deform.Button], model: type) -> deform.Form:
        """Create a Deform based on a given generated schema.

        This

        * Adds CSRF token to schema

        * Calles schema customizer

        * Binds schema to request and context or calls custom schema binder

        * Creates the form instance
        """

        # Make sure we have CSRF token

        add_csrf(schema)

        # Customize schema
        customizer = self.schema_customizer or _noop_customizer
        customizer(schema=schema, request=request, context=context, mode=mode, model=model)

        # Bind schema
        binder = default_schema_binder or self.schema_binder
        schema = binder(schema=schema, request=request, context=context, mode=mode, model=model)

        form = deform.Form(schema, buttons=buttons, resource_registry=ResourceRegistry(request))
        return form
Exemple #2
0
    def create_form(self, mode:EditMode, buttons=(), nested=None) -> deform.Form:
        """Automatically create a Deform form based on the underlying SQLALchemy model.

        We read ``self.includes`` for field names and colander.SchemaNode objects which should appear in the form.

        The automatically generated form schema can be customized by subclass ``customize_schema()`` and ``bind_schema()`` hooks.

        :param buttons: Passed to Deform as form buttons

        :param nested: Recurse to SQLAlchemy relationships and try to build widgets and subforms for them. TODO: This is likely to go away.
        """
        model = self.get_model()
        includes = self.includes

        schema = self.field_mapper.map(mode, self.request, self.context, model, includes, nested=nested)

        # Make sure we have CSRF token
        add_csrf(schema)

        self.customize_schema(schema)

        schema = self.bind_schema(schema)

        # Create the form instance using the default resource registry
        form = deform.Form(schema, buttons=buttons, resource_registry=ResourceRegistry(self.request))
        return form
Exemple #3
0
    def get_form(self):
        """Get Deform object we use on the admin page."""

        schema_factory = getattr(self.request.registry, "asset_schema", None)
        if not schema_factory:
            schema = AssetSchema()
        else:
            schema = schema_factory(self.request)

        add_csrf(schema)

        schema = self.bind_schema(schema)

        return deform.form.Form(schema,
            buttons=self.get_buttons(),
            resource_registry=ResourceRegistry(self.request))
Exemple #4
0
    def get_form(self):
        """Get Deform object we use on the admin page."""

        schema_factory = getattr(self.request.registry, "asset_schema", None)
        if not schema_factory:
            schema = AssetSchema()
        else:
            schema = schema_factory(self.request)

        add_csrf(schema)

        schema = self.bind_schema(schema)

        return deform.form.Form(schema,
                                buttons=self.get_buttons(),
                                resource_registry=ResourceRegistry(
                                    self.request))
Exemple #5
0
    def create_deform(self, schema: colander.Schema, request: Request,
                      context: object, mode: EditMode,
                      buttons: List[deform.Button],
                      model: type) -> deform.Form:
        """Create a Deform based on a given generated schema.

        This

        * Adds CSRF token to schema

        * Calles schema customizer

        * Binds schema to request and context or calls custom schema binder

        * Creates the form instance
        """

        # Make sure we have CSRF token

        add_csrf(schema)

        # Customize schema
        customizer = self.schema_customizer or _noop_customizer
        customizer(schema=schema,
                   request=request,
                   context=context,
                   mode=mode,
                   model=model)

        # Bind schema
        binder = default_schema_binder or self.schema_binder
        schema = binder(schema=schema,
                        request=request,
                        context=context,
                        mode=mode,
                        model=model)

        form = deform.Form(schema,
                           buttons=buttons,
                           resource_registry=ResourceRegistry(request))
        return form