Esempio n. 1
0
class ReceiptItemSequence(colander.SequenceSchema):
    receipt_item = ReceiptItemSchema(
        widget=MappingWidget(
            template='receipt_item_mapping.jinja2',
            item_template='receipt_item_mapping_item.jinja2'
        )
    )
Esempio n. 2
0
def metadata_schema_node(prop: InstrumentedAttribute,
                         model: DeclarativeMeta) -> colander.SequenceSchema:
    """Get the schema of a collection of metadata."""

    # Deferred which returns a dictionary with metadata name as key and metadata definition as value.
    # Needed to get the metadata types on UI side.
    metadata_definitions_dict = colander.deferred(
        lambda node, kw: {
            m["name"]: _translate_available_metadata(m, kw["request"])
            for m in metadata_definitions(kw["request"].registry.settings,
                                          model)
        })

    return colander.SequenceSchema(
        MetadataSchemaNode(
            Metadata,
            name="metadata",
            metadata_definitions=metadata_definitions_dict,
            validator=regex_validator,
            widget=MappingWidget(template="metadata"),
            overrides={"name": {
                "widget": metadata_name_widget(model)
            }},
        ),
        name=prop.key,
        title=prop.info["colanderalchemy"]["title"],
        description=prop.info["colanderalchemy"]["description"],
        metadata_definitions=metadata_definitions_dict,
        widget=SequenceWidget(template="metadatas", category="structural"),
    )
Esempio n. 3
0
def dimensions_schema_node(
        prop: InstrumentedAttribute) -> colander.SequenceSchema:
    """Get the scheme of the dimensions."""
    return colander.SequenceSchema(
        GeoFormSchemaNode(Dimension,
                          name="dimension",
                          widget=MappingWidget(template="dimension")),
        name=prop.key,
        title=prop.info["colanderalchemy"]["title"],
        description=prop.info["colanderalchemy"]["description"],
        widget=SequenceWidget(category="structural", template="dimensions"),
    )
Esempio n. 4
0
 def serialize(self, field, cstruct, **kw):
     kw.update({'public_key': self.public_key,
                'locale_name': self.request.locale_name})
     return MappingWidget.serialize(self, field, cstruct, **kw)
Esempio n. 5
0
 def serialize(self, field, cstruct, **kw):
     kw.update({'public_key': self.public_key,
                'locale_name': self.request.locale_name})
     return MappingWidget.serialize(self, field, cstruct, **kw)
Esempio n. 6
0
        dict_['value'] = dict_[self._ui_type(dict_['name'])]
        return super().objectify(dict_, context)

    def dictify(self, obj):
        dict_ = super().dictify(obj)
        value = obj.value or colander.null
        # depending on the type set the value in the right widget
        dict_[self._ui_type(obj.name)] = value
        return dict_

    def _ui_type(self, metadata_name):
        # pylint: disable=unsubscriptable-object
        metadata_type = self.metadata_definitions[metadata_name].get(
            'type', 'string')
        return metadata_type if metadata_type in self.available_types else 'string'


metadatas_schema_node = colander.SequenceSchema(
    MetadataSchemaNode(Metadata,
                       name='metadata',
                       metadata_definitions=metadata_definitions,
                       validator=regex_validator,
                       widget=MappingWidget(template='metadata'),
                       overrides={'name': {
                           'widget': metadata_name_widget
                       }}),
    name='metadatas',
    title=_('Metadatas'),
    metadata_definitions=metadata_definitions,
    widget=SequenceWidget(template='metadatas', category='structural'))
Esempio n. 7
0
    def dictify(self, obj):
        dict_ = super().dictify(obj)
        value = obj.value or colander.null
        # depending on the type set the value in the right widget
        dict_[self._ui_type(obj.name)] = value
        return dict_

    def _ui_type(self, metadata_name):
        # pylint: disable=unsubscriptable-object
        metadata_type = self.metadata_definitions[metadata_name].get(
            "type", "string")
        return metadata_type if metadata_type in self.available_types else "string"


metadatas_schema_node = colander.SequenceSchema(
    MetadataSchemaNode(
        Metadata,
        name="metadata",
        metadata_definitions=metadata_definitions,
        validator=regex_validator,
        widget=MappingWidget(template="metadata"),
        overrides={"name": {
            "widget": metadata_name_widget
        }},
    ),
    name="metadatas",
    title=_("Metadatas"),
    metadata_definitions=metadata_definitions,
    widget=SequenceWidget(template="metadatas", category="structural"),
)
Esempio n. 8
0
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# either expressed or implied, of the FreeBSD Project.

import colander
from c2cgeoform.schema import GeoFormSchemaNode
from deform.widget import MappingWidget, SequenceWidget

from c2cgeoportal_admin import _
from c2cgeoportal_commons.models.main import Dimension

dimensions_schema_node = colander.SequenceSchema(
    GeoFormSchemaNode(Dimension,
                      name="dimension",
                      widget=MappingWidget(template="dimension")),
    name="dimensions",
    title=_("Dimensions"),
    widget=SequenceWidget(category="structural", template="dimensions"),
)
Esempio n. 9
0
import colander
from deform.widget import MappingWidget, SequenceWidget
from c2cgeoform.schema import GeoFormSchemaNode
from c2cgeoportal_commons.models.main import Dimension
from c2cgeoportal_admin import _

dimensions_schema_node = colander.SequenceSchema(GeoFormSchemaNode(
    Dimension,
    name='dimension',
    widget=MappingWidget(template='dimension'),
),
                                                 name='dimensions',
                                                 title=_('Dimensions'),
                                                 widget=SequenceWidget(
                                                     category='structural',
                                                     template='dimensions'))
Esempio n. 10
0
class ClientItemSequenceSchema(colander.SequenceSchema):
    client_item = ClientItemSchema(
        widget=MappingWidget(template='client_items_mapping',
                             item_template='client_items_mapping_item'))