def widget(self, kw: dict): """Customize SequenceWidget to work with readonly fields.""" widget = SequenceWidget() if self.readonly: widget.readonly = True widget.deserialize = lambda x, y: null return widget
def widget(self, kw: dict): """Customize SequenceWidget to work with readonly fields.""" widget = SequenceWidget() if self.readonly: widget.readonly = True widget.deserialize = lambda x, y: null return widget
class PrincipalFull(PrincipalBasic): name = colander.SchemaNode( colander.String(), title=_("Name"), validator=colander.All(name_pattern_validator, name_new_validator), ) password = colander.SchemaNode( colander.String(), title=_("Password"), validator=colander.Length(min=5), missing=None, widget=CheckedPasswordWidget(), ) active = colander.SchemaNode( colander.Boolean(), title=_("Active"), description=_("Untick this to deactivate the account."), ) roles = colander.SchemaNode( colander.Set(), validator=roleset_validator, missing=[], title=_("Global roles"), widget=CheckboxChoiceWidget(), ) groups = Groups( title=_("Groups"), missing=[], # XXX min_len doesn't really do what we want here. We'd like # the close buttons to appear nevertheless (maybe the now # deprecated render_initial_item did exactly that). widget=SequenceWidget(min_len=1), )
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"), )
class CreateAdminGroupSchema(CSRFSchema): group_type = colander.SchemaNode( colander.String(), title=_('Group Type'), widget=SelectWidget(values=(('', _('Select')), ) + VALID_GROUP_TYPES), validator=group_type_validator, ) name = colander.SchemaNode( colander.String(), title=_('Group Name'), validator=validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), ) authority = colander.SchemaNode( colander.String(), title=_('Authority'), description=_("The group's authority"), hint=_('The authority within which this group should be created.' ' Note that only users within the designated authority' ' will be able to be associated with this group (as' ' creator or member).')) creator = colander.SchemaNode( colander.String(), title=_('Creator'), description=_("Username for this group's creator"), hint=_( 'This user will be set as the "creator" of the group. Note that' ' the user must be on the same authority as the group authority'), ) description = colander.SchemaNode( colander.String(), title=_('Description'), description=_('Optional group description'), validator=colander.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), widget=TextAreaWidget(rows=3), missing=None) origins = colander.SequenceSchema( colander.Sequence(), colander.SchemaNode(colander.String(), name='origin', validator=colander.url), title=_('Scope Origins'), hint=_( 'Origins where this group appears (e.g. "https://example.com")'), widget=SequenceWidget(add_subitem_text_template=_('Add origin'), min_len=1), validator=colander.Length( min=1, min_err=_('At least one origin must be specified')))
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"), )
def __init__(self, context, request, **kwargs): super(SlotsEditView, self).__init__(context, request, **kwargs) self.schema = colander.SchemaNode(colander.Mapping(), name="slots") view_name = context.default_view or "view" for name, title in get_registered_slots(view_name): choices = self._available_snippets(self.request.context, name) choices = map(lambda s: ("snippet-%d" % s.id, s.title), choices) snippet = colander.SchemaNode(colander.Mapping(), name="snippet-mapping", title=_(u'Snippet')) snippet.add( colander.SchemaNode(colander.String(), widget=SelectWidget(values=choices), name='snippet')) self.schema.add( colander.SchemaNode(colander.Sequence(), snippet, name=name, title=title, missing=[], widget=SequenceWidget(orderable=True), validator=validate_list))
def __init__(self, **kw): SequenceWidget.__init__(self, orderable=True, **kw)
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'))
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"), )
class Issue(Base): __tablename__ = "issue" __table_args__ = {"schema": schema} __colanderalchemy_config__ = { "title": _("Issue"), "plural": _("Issues"), "widget": FormWidget(fields_template="issue_fields"), } id = Column( Integer, primary_key=True, info={ # the `colanderalchemy` property allows to set a custom title for the # column or to use a specific widget. "colanderalchemy": {"title": _("Identifier"), "widget": HiddenWidget()} }, ) hash = Column( Text, nullable=False, unique=True, default=lambda: str(uuid4()), info={"colanderalchemy": {"exclude": True}, "c2cgeoform": {"duplicate": False}}, ) request_date = Column( Date, nullable=False, server_default=func.now(), info={"colanderalchemy": {"title": _("Request date")}}, ) geometry = Column( geoalchemy2.Geometry("POINT", 4326, management=True), info={ "colanderalchemy": { "title": _("Position"), "typ": colander_ext.Geometry( "POINT", srid=4326, map_srid=_map_config["srid"] ), "widget": deform_ext.MapWidget( map_options=_map_config, item_css_class="item-geometry" ), } }, ) type_id = Column( Integer, ForeignKey("{}.type.id".format(schema)), nullable=False, info={ "colanderalchemy": { "title": _("Type"), "widget": RelationSelectWidget( Type, "id", "label_en", order_by="label_en", default_value=("", _("- Select -")), ), } }, ) type = relationship(Type, info={"colanderalchemy": {"exclude": True}}) status = Column( Enum(*tuple(STATUSES.keys()), native_enum=False, name="status"), nullable=False, default="new", info={ "colanderalchemy": { "title": _("Status"), "widget": SelectWidget( values=list(STATUSES.items()), readonly=True, item_css_class="item-status", ), } }, ) @property def status_de(self): return self.status_i18n("de") @property def status_en(self): return self.status_i18n("en") @property def status_fr(self): return self.status_i18n("fr") def status_i18n(self, locale): localizer = make_localizer(locale, [resource_filename("getitfixed", "locale")]) return localizer.translate(STATUSES[self.status]) description = Column( Text, nullable=False, info={ "colanderalchemy": { "title": _("Description of the problem"), "widget": TextAreaWidget(rows=3), } }, ) localisation = Column( String(254), info={"colanderalchemy": {"title": _("Localisation")}} ) photos = relationship( Photo, cascade="all, delete-orphan", info={"colanderalchemy": {"title": _("Photos")}}, ) firstname = Column(String(100), info={"colanderalchemy": {"title": _("Firstname")}}) lastname = Column(String(100), info={"colanderalchemy": {"title": _("Lastname")}}) phone = Column( String(20), info={"colanderalchemy": {"title": _("Phone"), "widget": TelWidget()}}, ) email = Column( String(254), nullable=False, info={ "colanderalchemy": { "title": _("Email"), "validator": colander.Email(), "description": _( "This field is required to keep you informed about issue events" ), } }, ) private = Column( Boolean, nullable=False, server_default=text("False"), info={"colanderalchemy": {"title": _("Private"), "exclude": True}}, ) events = relationship( "Event", order_by="desc(Event.date)", backref=backref("issue", info={"colanderalchemy": {"exclude": True}}), info={ "colanderalchemy": { "title": _("Events"), "widget": SequenceWidget(readonly=True, item_css_class="item-events"), } }, ) public_events = relationship( "Event", order_by="desc(Event.date)", primaryjoin="and_(Event.issue_id==Issue.id, Event.private==False)", ) category = association_proxy("type", "category") def icon_url(self, request): return self.type.icon_url(request) if self.type else default_icon_url(request) def full_name(self): return "{} {}".format(self.firstname or "", self.lastname or "").strip()
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'))
class ClientItemsSchema(colander.Schema): client_items = ClientItemSequenceSchema( widget=SequenceWidget(template='client_items_sequence', item_template='client_items_sequence_item'))
def __init__(self, **kw): SequenceWidget.__init__(self, orderable=True, **kw)
class CreateAdminGroupSchema(CSRFSchema): def __init__(self, *args): super(CreateAdminGroupSchema, self).__init__(validator=group_creator_validator, *args) group_type = colander.SchemaNode( colander.String(), title=_('Group Type'), widget=SelectWidget(values=(('', _('Select')), ) + VALID_GROUP_TYPES), validator=group_type_validator, ) name = colander.SchemaNode( colander.String(), title=_('Group Name'), validator=validators.Length(min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH), widget=TextInputWidget(max_length=GROUP_NAME_MAX_LENGTH), ) organization = colander.SchemaNode( colander.String(), title=_('Organization'), description=_('Organization which this group belongs to'), widget=group_organization_select_widget, ) creator = colander.SchemaNode( colander.String(), title=_('Creator'), description=_("Username for this group's creator"), hint=_( 'This user will be set as the "creator" of the group. Note that' ' the user must be on the same authority as the group authority'), ) description = colander.SchemaNode( colander.String(), title=_('Description'), description=_('Optional group description'), validator=colander.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), widget=TextAreaWidget(rows=3, max_length=GROUP_DESCRIPTION_MAX_LENGTH), missing=None) origins = colander.SequenceSchema( colander.Sequence(), colander.SchemaNode(colander.String(), name='origin', validator=colander.url), title=_('Scope Origins'), hint=_( 'Origins where this group appears (e.g. "https://example.com")'), widget=SequenceWidget(add_subitem_text_template=_('Add origin'), min_len=1), validator=colander.Length( min=1, min_err=_('At least one origin must be specified'))) members = colander.SequenceSchema( colander.Sequence(), colander.SchemaNode(colander.String(), name='member', validator=member_exists_validator), title=_('Members'), hint=_('Add more members by their username to this group'), widget=SequenceWidget(add_subitem_text_template=_('Add member')), missing=None)
class DemoSchema(Schema): persons = Person(widget=SequenceWidget(min_len=1))
# 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"), )
class CreateAdminGroupSchema(CSRFSchema): def __init__(self, *args): super(CreateAdminGroupSchema, self).__init__( validator=group_creator_validator, *args ) group_type = colander.SchemaNode( colander.String(), title=_("Group Type"), widget=SelectWidget(values=(("", _("Select")),) + VALID_GROUP_TYPES), validator=group_type_validator, ) name = colander.SchemaNode( colander.String(), title=_("Group Name"), validator=validators.Length( min=GROUP_NAME_MIN_LENGTH, max=GROUP_NAME_MAX_LENGTH ), widget=TextInputWidget(max_length=GROUP_NAME_MAX_LENGTH), ) organization = colander.SchemaNode( colander.String(), title=_("Organization"), description=_("Organization which this group belongs to"), widget=group_organization_select_widget, ) creator = colander.SchemaNode( colander.String(), title=_("Creator"), description=_("Username for this group's creator"), hint=_( 'This user will be set as the "creator" of the group. Note that' " the user must be on the same authority as the group authority" ), ) description = colander.SchemaNode( colander.String(), title=_("Description"), description=_("Optional group description"), validator=colander.Length(max=GROUP_DESCRIPTION_MAX_LENGTH), widget=TextAreaWidget(rows=3, max_length=GROUP_DESCRIPTION_MAX_LENGTH), missing=None, ) # Although the default value of the enforce_scope property is True, # we need to allow the unchecking of the checkbox that represents it, # which means that empty values should be treated as False. enforce_scope = colander.SchemaNode( colander.Boolean(), hint=_( "Only allow annotations for documents within this group's defined scopes" ), widget=CheckboxWidget(css_class="form-checkbox--inline"), missing=False, ) scopes = colander.SequenceSchema( colander.Sequence(), colander.SchemaNode( colander.String(), name="scope", validator=url_with_origin_validator ), title=_("Scopes"), hint=_( "Define where this group appears. A document's URL must start with one or more" " of the entered scope strings (e.g. 'http://www.example.com')" ), widget=SequenceWidget(add_subitem_text_template=_("Add scope"), min_len=1), validator=colander.Length( min=1, min_err=_("At least one scope must be specified") ), ) members = colander.SequenceSchema( colander.Sequence(), colander.SchemaNode( colander.String(), name="member", validator=member_exists_validator ), title=_("Members"), hint=_("Add more members by their username to this group"), widget=SequenceWidget(add_subitem_text_template=_("Add member")), missing=None, )
class ReceiptBaseValidator(colander.Schema): number = colander.SchemaNode( colander.String(), title=u'Broj računa', widget=TextInputWidget(), missing_msg=REQUIRED_FIELD, validator=colander.Length( min=1, max=100, min_err=MIN_CHAR_LENGTH_ERROR.format(1), max_err=MAX_CHAR_LENGTH_ERROR.format(100) ) ) issued_date = colander.SchemaNode( colander.String(), title=u'Datum izdavanja', widget=TextInputWidget(), missing_msg=REQUIRED_FIELD, validator=validate_date ) currency_date = colander.SchemaNode( colander.String(), title=u'Datum valute plaćanja', widget=TextInputWidget(), missing_msg=REQUIRED_FIELD, validator=validate_date ) issued_time = colander.SchemaNode( colander.String(), title=u'Vrijeme izdavanja', widget=TextInputWidget(), missing_msg=REQUIRED_FIELD, validator=colander.Length( min=1, max=10, min_err=MIN_CHAR_LENGTH_ERROR.format(1), max_err=MAX_CHAR_LENGTH_ERROR.format(10) ) ) issued_location = colander.SchemaNode( colander.String(), title=u'Mjesto izdavanja', widget=TextInputWidget(), missing_msg=REQUIRED_FIELD, validator=colander.Length( min=1, max=100, min_err=MIN_CHAR_LENGTH_ERROR.format(1), max_err=MAX_CHAR_LENGTH_ERROR.format(100) ) ) base_amount = colander.SchemaNode( colander.Decimal('0.01', ROUND_HALF_EVEN), title=u'Osnovica za {0}%'.format(Receipt.TAX_PERCENT), missing_msg=REQUIRED_FIELD, widget=TextInputWidget( readonly=True, readonly_template=u'readonly/textinput_readonly' ), validator=colander.Range( min=0, max=999999.99, min_err=MIN_NUMBER_RANGE_ERROR.format(0), max_err=MAX_NUMBER_RANGE_ERROR.format(999999.99) ) ) tax_amount = colander.SchemaNode( colander.Decimal('0.01', ROUND_HALF_EVEN), title=u'PDV {0}%'.format(Receipt.TAX_PERCENT), missing_msg=REQUIRED_FIELD, widget=TextInputWidget( readonly=True, readonly_template=u'readonly/textinput_readonly' ), validator=colander.Range( min=0, max=999999.99, min_err=MIN_NUMBER_RANGE_ERROR.format(0), max_err=MAX_NUMBER_RANGE_ERROR.format(999999.99) ) ) return_amount = colander.SchemaNode( colander.Decimal('0.01', ROUND_HALF_EVEN), title=u'Povratna naknada', widget=TextInputWidget( readonly=True, readonly_template=u'readonly/textinput_readonly' ), missing_msg=REQUIRED_FIELD, validator=colander.Range( min=0, max=999999.99, min_err=MIN_NUMBER_RANGE_ERROR.format(0), max_err=MAX_NUMBER_RANGE_ERROR.format(999999.99) ) ) total_amount = colander.SchemaNode( colander.Decimal('0.01', ROUND_HALF_EVEN), title=u'UKUPNO', missing_msg=REQUIRED_FIELD, widget=TextInputWidget( readonly=True, readonly_template=u'readonly/textinput_readonly' ), validator=colander.Range( min=0, max=999999.99, min_err=MIN_NUMBER_RANGE_ERROR.format(0), max_err=MAX_NUMBER_RANGE_ERROR.format(999999.99) ) ) payment_type = colander.SchemaNode( colander.Integer(), title=u'Način plaćanja', default=Receipt.SLIP, missing_msg=REQUIRED_FIELD, widget=payment_type_widget, validator=payment_type_validator ) operator = colander.SchemaNode( colander.String(), title=u'Operater', missing_msg=REQUIRED_FIELD, widget=TextInputWidget( readonly=True, readonly_template=u'readonly/textinput_readonly' ) ) receipt_items = ReceiptItemSequence( widget=SequenceWidget( min_len=1, template='receipt_item_sequence.jinja2', item_template='receipt_item_sequence_item.jinja2' ) )