class SetPasswordSchema(colander.MappingSchema): """ Schema for the set password form """ #: colander.String password = colander.SchemaNode( colander.String(), title=_('Password'), validator=colander.Length(min=5), widget=CheckedPasswordWidget(), ) #: colander.String token = colander.SchemaNode( colander.String(), widget=HiddenWidget(), ) #: colander.String email = colander.SchemaNode( colander.String(), title=_('Email'), widget=HiddenWidget(), ) #: colander.String continue_to = colander.SchemaNode( colander.String(), widget=HiddenWidget(), missing=colander.null, )
class Theme(TreeGroup): __tablename__ = 'theme' __table_args__ = {'schema': _schema} __colanderalchemy_config__ = {'title': _('Theme'), 'plural': _('Themes')} __mapper_args__ = {'polymorphic_identity': 'theme'} __c2cgeoform_config__ = {'duplicate': True} id = Column(Integer, ForeignKey(_schema + '.treegroup.id'), primary_key=True, info={ 'colanderalchemy': { 'missing': colander.drop, 'widget': HiddenWidget() } }) ordering = Column(Integer, nullable=False, info={ 'colanderalchemy': { 'title': _('Order'), 'widget': HiddenWidget() } }) public = Column(Boolean, default=True, nullable=False, info={'colanderalchemy': { 'title': _('Public') }}) icon = Column(Unicode, info={'colanderalchemy': {'title': _('Icon')}}) # functionality functionalities = relationship('Functionality', secondary=theme_functionality, cascade='save-update,merge,refresh-expire', info={ 'colanderalchemy': { 'exclude': True, 'title': _('Functionalities') } }) # restricted to role restricted_roles = relationship( 'Role', secondary=restricted_role_theme, cascade='save-update,merge,refresh-expire', info={'colanderalchemy': { 'exclude': True, 'title': _('Roles') }}) def __init__(self, name: str = '', ordering: int = 100, icon: str = '') -> None: TreeGroup.__init__(self, name=name) self.ordering = ordering self.icon = icon
def l_fields(widget=False, **kwlist): if widget: l_fields = \ [StringFields(title=u"Numéro de devis", name='devis_id', l_choices=Affaire.list('devis'), table_reduce=True, rank=2, required=True), StringFields(title=u'Responsable affaire', name='responsable', l_choices=Affaire.list('responsable'), table_reduce=True, rank=3, required=True), StringFields(title=u'Chantier', name='chantier_id', l_choices=Affaire.list('chantier', **kwlist), round=2, required=True), StringFields(title=u'Contact client - chantier', name='contact_chantier_client', l_choices=Affaire.list('contact_chantier_client', **kwlist), round=2, required=True), StringFields(title=u'Contact client - facturation', name='contact_facturation_client', l_choices=Affaire.list('contact_facturation_client', **kwlist), round=2, required=True), StringFields(title=u'Contact interne - chantier', name='contact_chantier_interne', l_choices=Affaire.list('contact_chantier_interne', **kwlist), round=2, required=True), MoneyFields(title=u'FAE', name='fae', missing=0.0, widget=HiddenWidget())] else: l_fields = \ [StringFields(title=u"Numéro de devis", name='devis_id', table_reduce=True, rank=2, required=True), StringFields(title=u'Responsable Affaire', name='responsable', table_reduce=True, rank=3, required=True), StringFields(title=u'Chantier', name='chantier_id', round=2, required=True), StringFields(title=u'Contact client - chantier', name='contact_chantier_client', round=2, required=True), StringFields(title=u'Contact client - facturation', name='contact_facturation_client', round=2, required=True), StringFields(title=u'Contact interne - chantier', name='contact_chantier_interne', round=2, required=True), MoneyFields(title=u'FAE', name='fae', missing=0.0, widget=HiddenWidget())] return l_fields
class ContactPerson(Base): __tablename__ = 'contact_person' __table_args__ = ( {"schema": schema} ) __colanderalchemy_config__ = { 'title': _('Contact Person') } id = Column(Integer, primary_key=True, info={ 'colanderalchemy': { 'widget': HiddenWidget() }}) first_name = Column(Text, nullable=False, info={ 'colanderalchemy': { 'title': _('First name') }}) last_name = Column(Text, nullable=False, info={ 'colanderalchemy': { 'title': _('Last name') }}) permission_id = Column(Integer, ForeignKey(EXCAV_ID), info={'colanderalchemy': {'widget': HiddenWidget()}, 'c2cgeoform': {'duplicate': False}}) verified = Column(Boolean)
class Comment(Base): __tablename__ = 'comments' __table_args__ = ( {"schema": schema} ) __colanderalchemy_config__ = { 'title': _('A very simple form'), 'plural': _('Comments') } id = Column(Integer, primary_key=True, info={ 'colanderalchemy': { 'widget': HiddenWidget() }}) hash = Column(Text, unique=True, default=lambda: str(uuid4()), info={ 'colanderalchemy': { 'widget': HiddenWidget() }}) name = Column(Text, nullable=False, info={ 'colanderalchemy': { 'title': 'Name' }}) comment = Column(Text, nullable=True, info={ 'colanderalchemy': { 'title': 'Comment', 'widget': deform.widget.TextAreaWidget(rows=3), }}) bus_stop_id = Column(BigInteger, ForeignKey('c2cgeoform_demo.bus_stops.id'), info={'colanderalchemy': { 'title': 'Bus stop', 'widget': RelationSelectMapWidget( label_field='name', url=lambda request: request.route_url('bus_stops'))}})
class UserSearch(CSRFSchema): query = SchemaNode( String(), missing='', description= "Enter all or the start of a user's first name, last name, email " "address or username") column = SchemaNode(String(), default='username', widget=HiddenWidget()) order = SchemaNode(String(), default='asc', widget=HiddenWidget())
def __init__(self, request, action): super().__init__(ArgumentForPropositionSchema(), request, action, buttons=("submit", )) self.set_widgets({ 'proposition_id': HiddenWidget(), 'relation_type': HiddenWidget(), **argument_widgets })
def prepare_for_render(self, items_for_selects): self.set_widgets({ 'proposition_id': HiddenWidget(), 'user_id': HiddenWidget(), 'notes': TextAreaWidget(rows=8, missing=None), 'vote': Select2Widget(values=items_for_selects['vote']) })
def prepare_for_render(self, items_for_selects): common = common_widgets(items_for_selects) self.set_widgets({ 'document_id': HiddenWidget(), 'section': HiddenWidget(), 'editing_remarks': TextAreaWidget(rows=4), 'title': common['title'], 'abstract': common['abstract'], 'content': common['content'], 'motivation': common['motivation'], 'tags': common['tags'] })
class Event(Base): __tablename__ = "event" __table_args__ = {"schema": schema} __colanderalchemy_config__ = {"title": _("Event"), "plural": _("Events")} id = Column( Integer, primary_key=True, info={"colanderalchemy": {"title": _("Identifier"), "widget": HiddenWidget()}}, ) issue_id = Column( Integer, ForeignKey("{}.issue.id".format(schema)), nullable=False, info={"colanderalchemy": {"title": _("Type"), "widget": HiddenWidget()}}, ) status = Column( Enum(*tuple(STATUSES.keys()), native_enum=False, name="status"), nullable=False, info={ "colanderalchemy": { "title": _("Status"), "widget": SelectWidget( values=list(STATUSES.items()), item_css_class="item-status" ), } }, ) date = Column( DateTime(timezone=True), nullable=False, server_default=func.now(), info={"colanderalchemy": {"title": _("Date"), "widget": HiddenWidget()}}, ) comment = Column( Text, info={"colanderalchemy": {"title": _("Comment"), "missing": ""}} ) private = Column( Boolean, info={ "colanderalchemy": { "title": _("Private"), "widget": CheckboxWidget(item_css_class="item-private"), } }, ) author = Column( Enum(*tuple(USER_AUTHORS.keys()), native_enum=False, name="author"), nullable=False, default="new", info={"colanderalchemy": {"title": _("Author"), "widget": HiddenWidget()}}, )
class LuxLayerExternalWMS(LayerWMS): __tablename__ = 'lux_layer_external_wms' __table_args__ = {'schema': _schema} __mapper_args__ = {'polymorphic_identity': 'lu_ext_wms'} __colanderalchemy_config__ = { 'title': _('External WMS layer'), 'plural': _('External WMS layers') } id = Column(Integer, ForeignKey(_schema + ".layer_wms.id", ondelete='CASCADE'), primary_key=True, info={ 'colanderalchemy': { 'missing': None, 'widget': HiddenWidget() }}) category_id = Column(Integer, info={ 'colanderalchemy': {'title': _('Category ID')} }) def __init__( self, name='', layer='', public=True, time_mode='disabled', time_widget='slider', category_id=0 ): LayerWMS.__init__(self, name=name, layer=layer, public=public, time_mode=time_mode, time_widget=time_widget) self.category_id = category_id def get_default(dbsession): return dbsession.query(LuxLayerExternalWMS).filter( LuxLayerExternalWMS.name == 'lux_layer_external_wms-defaults' ).one_or_none()
class CaptionSchema(colander.MappingSchema): """This is the form schema to add and edit form for job captions. """ identifier = colander.SchemaNode(colander.String(), missing=None, widget=HiddenWidget()) caption = colander.SchemaNode(colander.String(), missing="???")
class LuxMeasurementDirectory(Base): __tablename__ = 'lux_measurement_directory' __table_args__ = {'schema': _schema} __colanderalchemy_config__ = { 'title': _('Surveying file config'), 'plural': _('Surveying file configs') } id = Column(Integer, primary_key=True, info={ 'colanderalchemy': {'widget': HiddenWidget()} }) name = Column(Unicode, nullable=False, info={ 'colanderalchemy': {'title': _('Name')} }) town_code = Column(Integer, nullable=False, info={ 'colanderalchemy': {'title': _('Town code')} }) path = Column(String, nullable=False, info={ 'colanderalchemy': {'title': _('Path')} }) path_dwg = Column(String, info={ 'colanderalchemy': {'title': _('Path (dwg)')} }) path_star = Column(String, info={ 'colanderalchemy': {'title': _('Path (star)')} })
class Layer(TreeItem): __tablename__ = "layer" __table_args__ = {"schema": _schema} __mapper_args__ = { "polymorphic_identity": "layer" } # needed for _identity_class id = Column( Integer, ForeignKey(_schema + ".treeitem.id"), primary_key=True, info={"colanderalchemy": { "widget": HiddenWidget() }}, ) public = Column(Boolean, default=True, info={"colanderalchemy": { "title": _("Public") }}) geo_table = Column(Unicode, info={"colanderalchemy": { "title": _("Geo table") }}) exclude_properties = Column( Unicode, info={"colanderalchemy": { "title": _("Exclude properties") }}) def __init__(self, name: str = "", public: bool = True) -> None: TreeItem.__init__(self, name=name) self.public = public
class Metadata(Base): __tablename__ = 'metadata' __table_args__ = {'schema': _schema} id = Column(Integer, primary_key=True, info={'colanderalchemy': { 'widget': HiddenWidget() }}) name = Column(Unicode, info={'colanderalchemy': { 'title': _('Name'), }}) value = Column(Unicode, info={'colanderalchemy': {'exclude': True}}) description = Column(Unicode, info={ 'colanderalchemy': { 'title': _('Description'), 'widget': TextAreaWidget() } }) item_id = Column('item_id', Integer, ForeignKey(_schema + '.treeitem.id'), nullable=False, info={ 'colanderalchemy': { 'exclude': True }, 'c2cgeoform': { 'duplicate': False } }) item = relationship( 'TreeItem', info={ 'c2cgeoform': { 'duplicate': False }, 'colanderalchemy': { 'exclude': True } }, backref=backref( 'metadatas', cascade='save-update,merge,delete,delete-orphan,expunge', order_by='Metadata.name', info={ 'colanderalchemy': { 'title': _('Metadatas'), 'exclude': True } })) def __init__(self, name: str = '', value: str = '') -> None: self.name = name self.value = value def __unicode__(self) -> str: # pragma: no cover return '{0!s}: {1!s}'.format(self.name or '', self.value or '')
class Functionality(Base): __tablename__ = 'functionality' __table_args__ = {'schema': _schema} __colanderalchemy_config__ = { 'title': _('Functionality'), 'plural': _('Functionalities') } __c2cgeoform_config__ = { 'duplicate': True } id = Column(Integer, primary_key=True, info={ 'colanderalchemy': { 'widget': HiddenWidget() } }) name = Column(Unicode, nullable=False, info={ 'colanderalchemy': {'title': _('Name')} }) description = Column(Unicode, info={ 'colanderalchemy': {'title': _('Description')} }) value = Column(Unicode, nullable=False, info={ 'colanderalchemy': {'title': _('Value')} }) def __init__(self, name: str='', value: str='', description: str='') -> None: self.name = name self.value = value self.description = description def __unicode__(self) -> str: return '{0!s} - {1!s}'.format(self.name or '', self.value or '') # pragma: no cover
def hidden_mode(self): return MappingFields(self.title, self.name, self.prefix, self.l_fields, self.round, widget=HiddenWidget())
class CreateSecret(CSRFSchema): domain = SchemaNode( String(), widget=HiddenWidget(), default='', title=u'domain', )
class LayerWMTS(DimensionLayer): __tablename__ = 'layer_wmts' __table_args__ = {'schema': _schema} __colanderalchemy_config__ = { 'title': _('WMTS Layer'), 'plural': _('WMTS Layers') } __c2cgeoform_config__ = { 'duplicate': True } __mapper_args__ = {'polymorphic_identity': 'l_wmts'} id = Column(Integer, ForeignKey(_schema + '.layer.id'), primary_key=True, info={ 'colanderalchemy': { 'missing': None, 'widget': HiddenWidget() }}) url = Column(Unicode, nullable=False, info={ 'colanderalchemy': { 'title': _('GetCapabilities URL'), 'column': 2 }}) layer = Column(Unicode, nullable=False, info={ 'colanderalchemy': { 'title': _('WMTS layer name'), 'column': 2 }}) style = Column(Unicode, info={ 'colanderalchemy': { 'title': _('Style'), 'column': 2 }}) matrix_set = Column(Unicode, info={ 'colanderalchemy': { 'title': _('Matrix set'), 'column': 2 }}) image_type = Column( Enum( 'image/jpeg', 'image/png', native_enum=False ), nullable=False, info={ 'colanderalchemy': { 'title': _('Image type'), 'column': 2, 'widget': SelectWidget(values=( ('image/jpeg', 'image/jpeg'), ('image/png', 'image/png'))) }}) def __init__(self, name: str='', public: bool=True, image_type: str='image/png') -> None: DimensionLayer.__init__(self, name=name, public=public) self.image_type = image_type @staticmethod def get_default(dbsession: Session) -> DimensionLayer: return dbsession.query(LayerWMTS).filter(LayerWMTS.name == 'wmts-defaults').one_or_none()
class Profile(CSRFSchema): username = SchemaNode( String(), validator=create_username_validator, description= '* We suggest using your first and last name separated by an underscore (ex: first_last)', ) first_name = SchemaNode(String()) last_name = SchemaNode(String()) email = SchemaNode( String(), title=u'Email Address', validator=create_user_email_validator, widget=CheckedInputWidget(subject=u'Email Address', confirm_subject=u'Confirm Email Address'), ) password = SchemaNode( String(), widget=StrengthValidatingPasswordWidget(), description= '* Minimum of 8 characters and must include one non-alpha character.', validator=create_password_validator, ) came_from = SchemaNode( String(), widget=HiddenWidget(), default='.', title=u'came_from', )
class LayerGroup(TreeGroup): __tablename__ = "layergroup" __table_args__ = {"schema": _schema} __colanderalchemy_config__ = { "title": _("Layers group"), "plural": _("Layers groups") } __mapper_args__ = {"polymorphic_identity": "group"} __c2cgeoform_config__ = {"duplicate": True} id = Column( Integer, ForeignKey(_schema + ".treegroup.id"), primary_key=True, info={"colanderalchemy": { "missing": drop, "widget": HiddenWidget() }}, ) is_expanded = Column( Boolean, info={"colanderalchemy": { "title": _("Expanded"), "column": 2 }}) # shouldn't be used in V3 def __init__(self, name: str = "", is_expanded: bool = False) -> None: TreeGroup.__init__(self, name=name) self.is_expanded = is_expanded
def hidden_mode(self): return DateTimeFields(self.title, self.name, self.round, widget=HiddenWidget(), mapinit=None, processing_form=lambda x: pd.Timestamp(x))
class LayerGroup(TreeGroup): __tablename__ = 'layergroup' __table_args__ = {'schema': _schema} __colanderalchemy_config__ = { 'title': _('Layers group'), 'plural': _('Layers groups') } __mapper_args__ = {'polymorphic_identity': 'group'} __c2cgeoform_config__ = {'duplicate': True} id = Column(Integer, ForeignKey(_schema + '.treegroup.id'), primary_key=True, info={ 'colanderalchemy': { 'missing': colander.drop, 'widget': HiddenWidget() } }) is_expanded = Column( Boolean, info={'colanderalchemy': { 'title': _('Expanded'), 'column': 2 }}) # shouldn't be used in V3 def __init__(self, name: str = '', is_expanded: bool = False) -> None: TreeGroup.__init__(self, name=name) self.is_expanded = is_expanded
def select2_widget_or_hidden(values): """ Render a select2 widget or a hidden field if no values were given. XXX: Is there a better way to hide unwanted fields? """ if values is None: return HiddenWidget(hidden=True) else: return Select2Widget(values=values)
class QuickReplySchema(MappingSchema): title = SchemaNode(String(), default=deferred_default_title, widget=HiddenWidget()) body = SchemaNode(String(), title='', default='', widget=TextAreaWidget(rows=5, cols=80))
def prepare_for_render(self, items_for_selects): self.set_widgets({ 'area_id': HiddenWidget(), 'status': SelectWidget(values=items_for_selects['status']), **common_widgets(items_for_selects) })
class UserLoginSchema(MappingSchema): email = SchemaNode(String(), description='Enter your email address', validator=Email()) password = SchemaNode(String(), description='Enter your password', widget=PasswordWidget()) tzoffset = SchemaNode(Integer(), widget=HiddenWidget())
def hidden_mode(self): return FileFields( self.title, self.name, self.round, widget=HiddenWidget(), mapinit=None, )
class Dimension(Base): __tablename__ = 'dimension' __table_args__ = {'schema': _schema} id = Column(Integer, primary_key=True, info={'colanderalchemy': {'widget': HiddenWidget()}}) name = Column(Unicode, info={ 'colanderalchemy': { 'title': _('Name') } }) value = Column(Unicode, info={ 'colanderalchemy': { 'title': _('Value') } }) description = Column(Unicode, info={ 'colanderalchemy': { 'title': _('Description'), 'widget': TextAreaWidget() } }) layer_id = Column('layer_id', Integer, ForeignKey(_schema + '.layer.id'), nullable=False, info={ 'colanderalchemy': { 'exclude': True }, 'c2cgeoform': { 'duplicate': False }}) layer = relationship( 'DimensionLayer', info={'c2cgeoform': {'duplicate': False}, 'colanderalchemy': {'exclude': True} }, backref=backref( 'dimensions', cascade='save-update,merge,delete,delete-orphan,expunge', info={ 'colanderalchemy': { 'title': _('Dimensions'), 'exclude': True } } ) ) def __init__(self, name: str='', value: str='', layer: str=None) -> None: self.name = name self.value = value if layer is not None: self.layer = layer def __unicode__(self) -> str: # pragma: no cover return self.name or ''
def l_fields(widget=False, restricted=True): if widget: l_fields = \ [StringFields(title=u"Numéro d'affaire", name='affaire_id', l_choices=Facture.list('affaire'), table_reduce=True, rank=1, required=True), StringFields(title=u'Type', name='type', l_choices=Facture.list('type'), table_reduce=True, required=True), StringFields(title=u'Objet', name='objet'), MoneyFields(title=u'Montant facture HT', name='montant_ht', required=True), FloatFields(title=u'Taux TVA', name='taux_tva', l_choices=Facture.list('tva'), required=True), MoneyFields(title=u'Montant TVA', name='montant_tva', widget=HiddenWidget()), MoneyFields(title=u'Montant TTC', name='montant_ttc', widget=HiddenWidget(), table_reduce=True, rank=3), IntegerFields(title=u'Numéro de situation', name='situation', l_choices=Facture.list('situation'), required=True), DateFields(title=u'Visa', name='date_visa', missing='1970-01-01'), DateFields(title=u'Encaissement', name='date_payed', missing='1970-01-01') ] if restricted: l_fields[-2] = DateFields( title=u'Visa', name='date_visa', missing='1970-01-01', widget=HiddenWidget(), processing_form=lambda x: pd.Timestamp(x)) l_fields[-1] = DateFields( title=u'Encaissement', name='date_payed', missing='1970-01-01', widget=HiddenWidget(), processing_form=lambda x: pd.Timestamp(x)) else: l_fields = \ [StringFields(title=u"Numéro d'affaire", name='affaire_id', table_reduce=True, rank=1, required=True), StringFields(title=u'Type', name='type', table_reduce=True, required=True), StringFields(title=u'Objet', name='objet', required=True), MoneyFields(title=u'Montant facture HT', name='montant_ht', required=True), FloatFields(title=u'Taux TVA', name='taux_tva', required=True), MoneyFields(title=u'Montant TVA', name='montant_tva'), MoneyFields(title=u'Montant TTC', name='montant_ttc', table_reduce=True, rank=3), IntegerFields(title=u'Numero de situation', name='situation', required=True), DateFields(title=u'Visa', name='date_visa', required=True), DateFields(title=u'Encaissement', name='date_payed', required=True)] return l_fields