Example #1
0
    def map_column(
            self, mode: EditMode, request: Request, node: colander.SchemaNode,
            model: type, name: str, column: Column,
            column_type: TypeEngine) -> Tuple[colander.SchemaType, dict]:
        """Map non-relationship SQLAlchemy column to Colander SchemaNode.

        :return: Tuple(constructed colander.SchemaType, dict of addtional colander.SchemaNode construction arguments)
        """
        logger.debug(
            "Mapping field %s, mode %s, node %s, column %s, column type %s",
            name, mode, node, column, column_type)

        # Check for autogenerated columns (updated_at)
        if column.onupdate:
            if mode in (EditMode.edit, EditMode.add):
                return TypeOverridesHandling.drop, {}

        # Don't fill default values when added, as they are automatically populated
        if column.default:
            if mode == EditMode.add:
                return TypeOverridesHandling.drop, {}

        # Never add primary keys
        # NOTE: TODO: We need to preserve ids because of nesting mechanism and groupedit widget wants it id
        if column.primary_key:
            # TODO: Looks like column.autoincrement is set True by default, so we cannot use it here
            if mode in (EditMode.edit, EditMode.add):
                return TypeOverridesHandling.drop, {}

        if column.foreign_keys:

            # Handled by relationship mapper
            return TypeOverridesHandling.drop, {}

        elif isinstance(column_type, (PostgreSQLUUID, columns.UUID)):

            # UUID's cannot be22 edited
            if mode in (EditMode.add, EditMode.edit):
                return TypeOverridesHandling.drop, {}

            # But let's show them
            return fields.UUID(), dict(
                missing=colander.drop,
                widget=FriendlyUUIDWidget(readonly=True))

        elif isinstance(column_type, Text):
            return colander.String(), dict(
                widget=deform.widget.TextAreaWidget())
        elif isinstance(column_type, JSONB):
            return JSONValue(), dict(widget=JSONWidget())
        elif isinstance(column_type, (JSONB, columns.JSONB)):
            # Can't edit JSON
            if mode in (EditMode.add, EditMode.edit):
                return TypeOverridesHandling.drop, {}
            return colander.String(), {}
        elif isinstance(column_type, LargeBinary):
            # Can't edit binary
            return TypeOverridesHandling.drop, {}
        elif isinstance(column_type, Geometry):
            # Can't edit geometry
            return TypeOverridesHandling.drop, {}
        elif isinstance(column_type, (INET, columns.INET)):
            return colander.String(), {}
        else:
            # Default mapping / unknown, let the parent handle
            return TypeOverridesHandling.unknown, {}
Example #2
0
class QuestionSchema(VisualisableElementSchema, SearchableEntitySchema):
    """Schema for question"""

    name = NameSchemaNode(
        editing=context_is_a_question,
    )

    challenge = colander.SchemaNode(
        ObjectType(),
        widget=challenge_choice,
        missing=None,
        title=_("Challenge (optional)"),
        description=_("You can select and/or modify the challenge associated to this question. "
                      "For an open question, do not select anything in the « Challenge » field.")
    )

    title = colander.SchemaNode(
        colander.String(),
        title=_("Question")
    )

    options = colander.SchemaNode(
        colander.Sequence(),
        colander.SchemaNode(
            colander.String(),
            name=_("Option")
        ),
        widget=SequenceWidget(
            add_subitem_text_template='',
            orderable=True),
        title=_('Options'),
        description=_("You can add options to your question. "
                      "Users can only answer questions with options once. "
                      "Statistics will be provided indicating the percentage "
                      "of each option."),
        missing=[]
    )

    text = colander.SchemaNode(
        colander.String(),
        widget=LimitedTextAreaWidget(
            rows=5,
            cols=30,
            limit=2000,
            alert_values={'limit': 2000},
            item_css_class='content-preview-form',
            placeholder=_('I have a question!')),
        title=_("Details"),
        missing=''
    )

    attached_files = colander.SchemaNode(
        colander.Sequence(),
        colander.SchemaNode(
            ObjectData(File),
            name=_("File"),
            widget=get_file_widget()
        ),
        widget=FilesWidget(
            add_subitem_text_template='',
            item_css_class='files-block'),
        missing=[],
        title=_('Attached files'),
    )

    anonymous = colander.SchemaNode(
        colander.Boolean(),
        widget=anonymous_widget,
        label=_('Remain anonymous'),
        description=_('Check this box if you want to remain anonymous.'),
        title='',
        missing=False,
        default=False
    )
class Business(AddressSchema):
    business_name = colander.SchemaNode(colander.String(),
                                        title='Business Name',
                                        insert_before='line1')
Example #4
0
class Tags(colander.SequenceSchema):
    """:class:`colander.SequenceSchema` for tags."""

    tag = colander.SchemaNode(colander.String())
Example #5
0
class Login(colander.Schema):
    username = colander.SchemaNode(colander.String(),
                                   title="Nama Pengguna")
    password = colander.SchemaNode(colander.String(),
                                   title="Kata Sandi",
                                   widget=widget.PasswordWidget())
Example #6
0
class BaseReviewSchema(VisualisableElementSchema, SearchableEntitySchema):
    """Schema for base review"""

    title = colander.SchemaNode(colander.String(),
                                widget=TextInputWidget(),
                                title=_('Title'))

    surtitle = colander.SchemaNode(colander.String(),
                                   widget=TextInputWidget(),
                                   title=_("Surtitle"),
                                   missing="")

    article = colander.SchemaNode(colander.String(),
                                  widget=article_widget,
                                  title=_("Article"))

    description = colander.SchemaNode(colander.String(),
                                      widget=deform.widget.TextAreaWidget(
                                          rows=4, cols=60),
                                      title=_("Description"))

    picture = colander.SchemaNode(
        ObjectData(Image),
        widget=picture_widget,
        title=_('Picture'),
    )

    artists_ids = colander.SchemaNode(colander.Set(),
                                      widget=artists_choice,
                                      title=_('Artists'),
                                      missing=[])

    artists = colander.SchemaNode(
        colander.Sequence(),
        omit(
            select(
                ArtistInformationSheetSchema(
                    editable=True,
                    factory=ArtistInformationSheet,
                    omit=('id', ),
                    widget=SimpleMappingWidget(
                        css_class='artist-data object-well'
                        ' default-well'),
                    name=_('artist')), [
                        'id', 'origin_oid', 'title', 'description', 'picture',
                        'biography', 'is_director'
                    ]), ['_csrf_token_', '__objectoid__']),
        widget=SequenceWidget(css_class='artists-values',
                              template='lac:views/'
                              'templates/sequence_modal.pt',
                              item_template='lac:views/'
                              'templates/sequence_modal_item.pt'),
        title=_('Artists'),
    )

    signature = colander.SchemaNode(colander.String(),
                                    widget=TextInputWidget(),
                                    title=_("Signature"),
                                    default=default_signature)

    informations = colander.SchemaNode(colander.String(),
                                       widget=RichTextWidget(),
                                       missing="",
                                       title=_("Informations"))

    showcase_review = colander.SchemaNode(
        colander.Boolean(),
        widget=deform.widget.CheckboxWidget(),
        label=_('Add to the carousel of the home page'),
        title='',
        default=False,
        missing=False)
Example #7
0
class WikiPage(colander.MappingSchema):
    title = colander.SchemaNode(colander.String())
    body = colander.SchemaNode(colander.String(),
                               widget=deform.widget.RichTextWidget())
Example #8
0
    def get_schema_from_column(self, prop, overrides):
        """ Build and return a :class:`colander.SchemaNode` for a given Column.

        This method uses information stored in the column within the ``info``
        that was passed to the Column on creation.  This means that
        ``Colander`` options can be specified declaratively in
        ``SQLAlchemy`` models using the ``info`` argument that you can
        pass to :class:`sqlalchemy.Column`.

        Arguments/Keywords

        prop
            A given :class:`sqlalchemy.orm.properties.ColumnProperty`
            instance that represents the column being mapped.
        overrides
            A dict-like structure that consists of schema attributes to
            override imperatively. Values provides as part of :attr:`overrides`
            will take precendence over all others.
        """

        # The name of the SchemaNode is the ColumnProperty key.
        name = prop.key
        kwargs = dict(name=name)
        column = prop.columns[0]
        declarative_overrides = column.info.get(self.sqla_info_key, {}).copy()
        self.declarative_overrides[name] = declarative_overrides.copy()

        key = 'exclude'

        if key not in overrides and declarative_overrides.pop(key, False):
            log.debug('Column %s skipped due to declarative overrides', name)
            return None

        if overrides.pop(key, False):
            log.debug('Column %s skipped due to imperative overrides', name)
            return None

        self.check_overrides(name, 'name', declarative_overrides, overrides)

        # The SchemaNode built using the ColumnProperty has no children.
        children = []

        # The type of the SchemaNode will be evaluated using the Column type.
        # User can overridden the default type via Column.info or
        # imperatively using overrides arg in SQLAlchemySchemaNode.__init__

        # Support sqlalchemy.types.TypeDecorator
        column_type = getattr(column.type, 'impl', column.type)

        imperative_type = overrides.pop('typ', None)
        declarative_type = declarative_overrides.pop('typ', None)

        if imperative_type is not None:
            if hasattr(imperative_type, '__call__'):
                type_ = imperative_type()
            else:
                type_ = imperative_type
            log.debug('Column %s: type overridden imperatively: %s.', name,
                      type_)

        elif declarative_type is not None:
            if hasattr(declarative_type, '__call__'):
                type_ = declarative_type()
            else:
                type_ = declarative_type
            log.debug('Column %s: type overridden via declarative: %s.', name,
                      type_)

        elif isinstance(column_type, Boolean):
            type_ = colander.Boolean()

        elif isinstance(column_type, Date):
            type_ = colander.Date()

        elif isinstance(column_type, DateTime):
            type_ = colander.DateTime(default_tzinfo=None)

        elif isinstance(column_type, Enum):
            type_ = colander.String()
            kwargs["validator"] = colander.OneOf(column.type.enums)

        elif isinstance(column_type, Float):
            type_ = colander.Float()

        elif isinstance(column_type, Integer):
            type_ = colander.Integer()

        elif isinstance(column_type, String):
            type_ = colander.String()
            kwargs["validator"] = colander.Length(0, column.type.length)

        elif isinstance(column_type, Numeric):
            type_ = colander.Decimal()

        elif isinstance(column_type, Time):
            type_ = colander.Time()

        else:
            raise NotImplementedError('Unknown type: %s' % column_type)
        """
        Add default values
        
        possible values for default in SQLA:
         1. plain non-callable Python value
              - give to Colander as a default
         2. SQL expression (derived from ColumnElement)
              - leave default blank and allow SQLA to fill
         3. Python callable with 0 or 1 args
            1 arg version takes ExecutionContext
              - leave default blank and allow SQLA to fill
              
        all values for server_default should be ignored for 
        Colander default
        """
        if isinstance(column.default,
                      ColumnDefault) and column.default.is_scalar:
            kwargs["default"] = column.default.arg
        """
        Add missing values
        
        possible values for default in SQLA:
         1. plain non-callable Python value
              - give to Colander as a missing unless nullable
         2. SQL expression (derived from ColumnElement)
              - set missing to 'drop' to allow SQLA to fill this in
                and make it an unrequired field
         3. Python callable with 0 or 1 args
            1 arg version takes ExecutionContext
              - call function to get value for missing [ <- should this be changed to missing = drop ]
        
        if nullable, then allowing missing = drop
        
        all values for server_default should result in 'drop' 
        for Colander missing
        
        autoincrement results in drop
        """
        if isinstance(column.default, ColumnDefault):
            if column.default.is_callable:
                kwargs["missing"] = drop
            elif column.default.is_clause_element:  # SQL expression
                kwargs["missing"] = drop
            elif column.default.is_scalar:
                kwargs["missing"] = column.default.arg
        elif column.nullable:
            kwargs["missing"] = drop
        elif isinstance(column.server_default, FetchedValue):
            kwargs["missing"] = drop  # value generated by SQLA backend
        elif hasattr(column.table, "_autoincrement_column") and id(
                column.table._autoincrement_column) == id(column):
            # this column is the autoincrement column, so we can drop
            # it if it's missing and let the database generate it
            kwargs["missing"] = drop

        kwargs.update(declarative_overrides)
        kwargs.update(overrides)

        return colander.SchemaNode(type_, *children, **kwargs)
Example #9
0
class ModuleFunctionArg(colander.MappingSchema):
    name = colander.SchemaNode(colander.String(), validator=PythonIdentifier)
    default = colander.SchemaNode(Raw(), missing=None, default=None)
Example #10
0
class GroupSchema(resource.ResourceSchema):
    members = colander.SchemaNode(colander.Sequence(),
                                  colander.SchemaNode(colander.String()))

    class Options:
        preserve_unknown = True
Example #11
0
class OrderSchema(VisualisableElementSchema):
    """Schema for order"""

    name = NameSchemaNode(editing=context_is_a_order, )

    title = colander.SchemaNode(colander.String(), title=_('Title'))
class ToDoSchema(colander.MappingSchema):
    title = colander.SchemaNode(colander.String())
Example #13
0
def get_list_schema(is_admin=False):
    schema = lists.BaseListsSchema().clone()

    schema.insert(
        0,
        forms.today_node(
            name="date_range_end",
            default=colander.null,
            missing=colander.drop,
            description=u"Et le",
            widget_options={'css_class': 'input-medium search-query'},
        )
    )

    schema.insert(
        0,
        forms.today_node(
            name="date_range_start",
            default=colander.null,
            missing=colander.drop,
            description=u"Entre le",
            widget_options={'css_class': 'input-medium search-query'},
        )
    )

    schema.insert(0, colander.SchemaNode(
        colander.Integer(),
        name='type_id',
        widget=get_deferred_select_type(True),
        validator=deferred_type_validator,
        missing=colander.drop))

    schema.insert(0, colander.SchemaNode(
        colander.String(),
        name='status',
        widget=deform.widget.SelectWidget(values=STATUS_SEARCH),
        validator=colander.OneOf([s[0] for s in STATUS_SEARCH]),
        missing=colander.drop))

    schema.insert(0, colander.SchemaNode(
        colander.String(),
        name='user_status',
        widget=deform.widget.SelectWidget(values=ATTENDANCE_STATUS_SEARCH),
        validator=colander.OneOf([s[0] for s in ATTENDANCE_STATUS_SEARCH]),
        missing=colander.drop))

    if is_admin:
        schema.insert(0, participant_filter_node_factory(name='participant_id'))
        schema.insert(0, conseiller_filter_node_factory(name='conseiller_id'))

    year = forms.year_select_node(
        name='year',
        query_func=get_invoice_years,
        widget_options={'default_val': (-1, u"Toutes les années")},
        missing=colander.null,
        description=u"Année"
    )
    schema.insert(0, year)

    del schema['search']
    return schema
Example #14
0
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,
    )

    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,
    )
Example #15
0
class AddAccountSchema(colander.Schema):
    """

    """
    # couTimestamp
    cou = colander.SchemaNode(
        colander.Boolean(),
        title='Security and Acceptable Use Policy Acceptance',
        description='Terms and Conditions Agreement - Check this if '
        'you have read and agree to abide by the Center\'s '
        'Security and Acceptable Use Policies.',
        widget=widget.CheckboxWidget(),
        validator=cou_validator,
        oid='cou')

    #   storTimestamp
    stor = colander.SchemaNode(
        colander.Boolean(),
        title='Data Security Policy Acceptance',
        description='Check this if you have read and agree '
        'to the Center\'s storage policies.',
        widget=deform.widget.CheckboxWidget(),
        validator=stor_validator,
        oid='stor')
    #   cybeTimestamp
    # cyber = colander.SchemaNode(
    #     colander.Boolean(),
    #     title='Cyber Security Policy Acceptance',
    #     description='Check this if you have read and agree to abide by '
    #                 'the Center\'s Cyber Security policies.',
    #     widget=deform.widget.CheckboxWidget(),
    #     validator=cyber_validator,
    #     oid='cyber'
    # )

    # titlePrefix = colander.SchemaNode(
    #     colander.String(),
    #     title='Honorary',
    #     description='If you prefer to use n honorary, enter it here.',
    #     # validator=colander.ContainsOnly([x[0] for x in title_prefixes]),
    #     #validator=colander.Length(min=1, max=64),
    #     widget=widget.TextInputWidget(placeholder="Dr., Mr., Ms., etc."),
    #     missing=unicode(''),
    #     oid='titlePrefix'
    # )

    givenName = colander.SchemaNode(
        colander.String(),
        title='Given/First name',
        description='Your given or first name',
        validator=colander.Length(min=1, max=64),
        widget=widget.TextInputWidget(placeholder=''),
        oid='givenName')

    middleName = colander.SchemaNode(
        colander.String(),
        title='Middle name/initial',
        description='Middle name or initial',
        validator=colander.Length(min=0, max=64),
        widget=widget.TextInputWidget(placeholder=''),
        missing=unicode(''),
        oid='middleName')

    sn = colander.SchemaNode(colander.String(),
                             title='Family/Last Name',
                             description='family Name / Last Name',
                             validator=colander.Length(min=1, max=64),
                             widget=widget.TextInputWidget(placeholder=''),
                             oid='sn')

    suffix = colander.SchemaNode(
        colander.String(),
        title='Suffix',
        description='(Sr. Jr. IV, etc.)',
        validator=colander.Length(min=0, max=32),
        widget=widget.TextInputWidget(placeholder='example: III, PhD, etc.'),
        missing=unicode(''),
        oid='suffix')

    cn = colander.SchemaNode(
        colander.String(),
        title='Common or Nick Name',
        description='Your full name. How you want to be addressed.',
        validator=colander.Length(min=3, max=64),
        widget=widget.TextInputWidget(
            placeholder='(Optional) How you want to be addressed '
            'if different from: FirstName LastName'),
        missing=unicode(''),
        oid='cn')

    street = colander.SchemaNode(
        colander.String(),
        title='Street Address',
        description='',
        validator=colander.Length(min=0, max=200),
        widget=widget.TextInputWidget(
            placeholder='business/institution address'),
        oid='street')

    lcity = colander.SchemaNode(colander.String(),
                                title='City',
                                description='',
                                validator=colander.Length(min=1, max=128),
                                widget=widget.TextInputWidget(),
                                oid='lcity')

    st = colander.SchemaNode(colander.String(),
                             title='State/Province',
                             description='',
                             validator=colander.Length(min=1, max=128),
                             widget=widget.TextInputWidget(),
                             oid='l')

    postalCode = colander.SchemaNode(colander.String(),
                                     title='Post/ZIP Code',
                                     description='',
                                     validator=colander.Length(min=2, max=64),
                                     widget=widget.TextInputWidget(),
                                     oid='postalCode')

    country = colander.SchemaNode(
        colander.String(),
        title='Country',
        description='',
        widget=widget.SelectWidget(values=country_codes),
        #validator=colander.OneOf([x[0] for x in country_codes]),
        validator=valid_country,
        oid='country')

    mail = colander.SchemaNode(
        colander.String(),
        title='EMail',
        description='Your primary email account',
        # validator=colander.Email(msg="Please provide your work Email address. This will be the primary account we use to contact you."),
        widget=email_confirm_widget,
        oid='mail')

    # mailPreferred = colander.SchemaNode(
    #     colander.String(),
    #     title='Preferred EMail',
    #     description='optional preferred email account',
    #     missing=unicode(''),
    #     widget=pref_email_confirm_widget,
    #     oid='mail'
    # )

    phone = colander.SchemaNode(
        colander.String(),
        title='Phone number',
        description='Please provide your primary telephone number',
        validator=phone_validator,
        widget=widget.TextInputWidget(),
        oid='phone')

    cell = colander.SchemaNode(
        colander.String(),
        title='Cell phone number',
        description='For contact and verification',
        validator=phone_validator,
        missing=unicode(''),
        widget=widget.TextInputWidget(
            placeholder='(Optional) example: +1-000-000-0000'),
        oid='cell')

    employerType = colander.SchemaNode(
        colander.String(),
        validator=colander.OneOf([x[0] for x in employer_types]),
        widget=deform.widget.RadioChoiceWidget(values=employer_types),
        title='Employer Type',
        description='Select the employer type from the list below that '
        'is most appropriate to your request',
        oid="employerType")

    employerName = colander.SchemaNode(
        colander.String(),
        title='Employer, Institution, or Sponsor Name',
        description='Please provide the name of your employer or '
        'the institution you represent',
        validator=colander.Length(min=3, max=128),
        widget=widget.TextInputWidget(placeholder='employer name here'),
        oid='employerName')

    citizenStatus = colander.SchemaNode(
        colander.String(),
        title='Citizenship Status',
        description='Select one of the following options '
        'that best describes your U.S. citizenship status',
        validator=colander.OneOf([x[0] for x in citizen_types]),
        widget=widget.RadioChoiceWidget(values=citizen_types),
        oid='citizenStatus')

    citizenships = colander.SchemaNode(
        colander.Set(),
        title='Citizenships',
        description='Please select your country or countries of citizenship',
        validator=valid_countries,
        widget=widget.Select2Widget(values=country_codes, multiple=True),
        oid='citizenships',
    )

    #   birthCountry
    birthCountry = colander.SchemaNode(
        colander.String(),
        title='Country of birth',
        description='Please enter/select your country of birth',
        validator=valid_country,
        widget=widget.Select2Widget(values=country_codes),
        oid='birthCountry',
    )

    isnreluser = colander.SchemaNode(
        colander.String(),
        title='Existing NREL Account?',
        description="Select the option that is most true for you.",
        widget=deform.widget.RadioChoiceWidget(values=has_account),
        missing=unicode(''),
        label='Existing or Previous ESIF HPC UserID',
        oid='isnreluser')

    nrelUserID = colander.SchemaNode(
        colander.String(),
        title='Your Existing NREL HPC UserID',
        description='If you have --or previously had-- an NREL UserID, '
        'enter it here.',
        validator=colander.Length(min=1, max=16),
        widget=widget.TextInputWidget(placeholder='example: jsmythe'),
        missing=unicode(''),
        oid='nrelUserID')

    justification = colander.SchemaNode(
        colander.String(),
        title='NREL HPC User Credential Information',
        widget=widget.TextAreaWidget(rows=6, columns=60),
        missing=unicode(''),
        validator=colander.Length(max=1000),
        description="If you don't have an account on NREL HPC systems, "
        "we need some additional information. Please provide "
        "the project handles or titles of the project allocations "
        "you are associated with. "
        "If you don't have an allocation, please tell us "
        "why you are requesting NREL HPC login credentials.",
        oid='comments')

    preferredUID = colander.SchemaNode(
        colander.String(),
        title='*New* ESIF HPC UserID',
        description="Please provide your desired User ID here.<sup>1</sup>"
        "(3 to 16 characters, all lower case.)",
        validator=colander.Length(min=3, max=16),
        widget=widget.TextInputWidget(placeholder="example: jsmythe"),
        missing=unicode(''),
        oid='preferredUID')

    comments = colander.SchemaNode(
        colander.String(),
        title='Additional Notes or Comments',
        widget=deform.widget.TextAreaWidget(
            rows=6,
            columns=60,
            placeholder='If you think we need any additional '
            'information to process or approve your request, '
            'please let us know (project name, PI, NREL contact, etc.).'),
        missing=unicode(''),
        validator=colander.Length(max=1000),
        description='If you think we need any additional '
        'information to process or approve your request, '
        'please let us know.',
        oid='comments')
Example #16
0
class ModuleFunction(colander.MappingSchema):
    name = colander.SchemaNode(colander.String(), validator=PythonIdentifier)
    args = ModuleFunctionArgs()
Example #17
0
class SpeechToText(colander.MappingSchema):
    name = colander.SchemaNode(colander.String())
    time = colander.SchemaNode(colander.Float())
    duration = colander.SchemaNode(colander.Float())
    confidence = colander.SchemaNode(colander.Float())
Example #18
0
class ModuleLabel(colander.MappingSchema):
    language = colander.SchemaNode(colander.String())
    name = colander.SchemaNode(colander.String())
Example #19
0
class ContactSchema(Schema):

    email = colander.SchemaNode(
        colander.String(),
        widget=EmailInputWidget(),
        missing="",
        validator=colander.All(colander.Email(), colander.Length(max=100)),
    )

    phone = colander.SchemaNode(
        DictSchemaType(),
        missing="",
        validator=colander.All(PhoneValidator()),
        widget=PhoneWidget(css_class="contact-phone"),
        title=_('Phone'),
        description=
        _("Indicate the phone number. Only spaces are allowed as separator for phone numbers."
          ))

    surtax = colander.SchemaNode(
        colander.String(),
        missing="0",
        widget=TextInputWidget(item_css_class="hide-bloc"),
        default="0",
        title=_('Surtax'),
        description=
        _('Indicate the amount of the surcharge (for the premium-rate number).'
          ),
    )

    fax = colander.SchemaNode(
        DictSchemaType(),
        validator=colander.All(
            PhoneValidator(
                _('${phone} fax number not valid for the selected country (${country})'
                  ))),
        missing="",
        widget=PhoneWidget(css_class="contact-fax"),
        title=_('Fax'),
        description=
        _("Indicate the fax number. Only spaces are allowed as separator for fax numbers."
          ))

    website = colander.SchemaNode(
        colander.String(),
        missing="",
        title=_('Website'),
    )

    @invariant
    def contact_invariant(self, appstruct):
        appstruct_copy = appstruct.copy()
        appstruct_copy.pop('surtax')
        if 'title' in appstruct_copy:
            appstruct_copy.pop('title')

        if not any(v != "" and v != colander.null
                   for v in list(appstruct_copy.values())):
            raise colander.Invalid(self, _('One value must be entered.'))

        if 'phone' in appstruct and appstruct['phone'] and \
            ('surtax' not in appstruct or \
             'surtax' in appstruct and not appstruct['surtax']):
            raise colander.Invalid(self, _('Surtax field must be filled in.'))
Example #20
0
class AddSchema(colander.Schema):
    tahun = colander.SchemaNode(colander.String())
    uraian = colander.SchemaNode(colander.String(), missing=colander.drop)
    tahun_tetap = colander.SchemaNode(colander.String(),
                                      title="Tahun Ketetapan")
    nilai = colander.SchemaNode(colander.String())
Example #21
0
class ValidMacStationSchema(ValidStationSchema):
    """A schema which validates the fields in a mac address based shard."""

    mac = MacNode(colander.String())
Example #22
0
class ForgotPasswordSchema(CSRFSchema):
    email = colander.SchemaNode(colander.String(),
                                validator=colander.All(colander.Email(),
                                                       email_exists))
Example #23
0
class UserAvatar(colander.MappingSchema):
    """:class:`colander.MappingScheme` for user Avatars."""

    b = colander.SchemaNode(colander.String(), missing=colander.drop)
    i = colander.SchemaNode(colander.String(), missing=colander.drop)
Example #24
0
class ActivateSchema(CSRFSchema):
    code = colander.SchemaNode(colander.String(), title=_("Security Code"))
    password = colander.SchemaNode(colander.String(),
                                   title=_('New Password'),
                                   validator=colander.Length(min=2),
                                   widget=deform.widget.PasswordWidget())
Example #25
0
class Options(colander.SequenceSchema):
    option = colander.SchemaNode(
        colander.String()
    )
Example #26
0
class OAuthRequest(colander.MappingSchema):
    code = colander.SchemaNode(colander.String(), location="querystring")
    state = colander.SchemaNode(colander.String(), location="querystring")
Example #27
0
 class BaseMapping(colander.MappingSchema):
     name = colander.SchemaNode(colander.String())
     number = colander.SchemaNode(colander.Integer())
Example #28
0
class MetaKeySchema(colander.MappingSchema):
    key = colander.SchemaNode(colander.String())
    type = colander.SchemaNode(colander.String(), missing='string')
    description = colander.SchemaNode(colander.String(), missing='')
    mandatory = colander.SchemaNode(colander.String(), missing='')
Example #29
0
def password_node(**kwargs):
    """Return a Colander schema node for an existing user password."""
    kwargs.setdefault("widget", deform.widget.PasswordWidget())
    return colander.SchemaNode(colander.String(), **kwargs)
Example #30
0
class ResponseHeaderSchema(colander.MappingSchema):
    """Kinto API custom response headers."""

    etag = HeaderQuotedInteger(name='Etag')
    last_modified = colander.SchemaNode(colander.String(),
                                        name='Last-Modified')