Ejemplo n.º 1
0
    def _modify_package_schema(self, schema):

        _ignore_missing = tk.get_validator('ignore_missing')
        _convert_to_extras = tk.get_converter('convert_to_extras')
        _not_empty = tk.get_validator('not_empty')

        # Add custom metadata fields to the schema, this one will use
        # convert_to_extras for all fields.
        schema.update({
            'variable_names': [_ignore_missing, _convert_to_extras],
            'variable_units': [_ignore_missing, _convert_to_extras],
            'north_extent': [_ignore_missing,
                             v.Number(), _convert_to_extras],
            'west_extent': [_ignore_missing,
                            v.Number(), _convert_to_extras],
            'south_extent': [_ignore_missing,
                             v.Number(), _convert_to_extras],
            'east_extent': [_ignore_missing,
                            v.Number(), _convert_to_extras],
            'data_start_day':
            [_ignore_missing,
             v.DateConverter(), _convert_to_extras],
            'data_end_day':
            [_ignore_missing,
             v.DateConverter(), _convert_to_extras],
            'projection': [_ignore_missing, _convert_to_extras],
            'dataset_type': [_not_empty, _convert_to_extras]
        })

        schema = super(MultidimensionalSpaceTimePlugin,
                       self).modify_schema(schema)
        return schema
Ejemplo n.º 2
0
class TimeSlotSchema(BaseSchema):
    start_date = validators.DateConverter(month_style='dd/mm/yyyy')
    start_time = validators.TimeConverter(use_datetime=True)
    end_date = validators.DateConverter(month_style='dd/mm/yyyy')
    end_time = validators.TimeConverter(use_datetime=True)
    primary = validators.Bool()
    heading = validators.Bool()
Ejemplo n.º 3
0
class CeilingSchema(BaseSchema):
    parent = CeilingValidator()
    name = validators.String(not_empty=True)
    max_sold = validators.Int(min=0, max=2000000)
    available_from = validators.DateConverter(month_style='dd/mm/yyyy')
    available_until = validators.DateConverter(month_style='dd/mm/yyyy')
    products = ForEach(ProductValidator())
Ejemplo n.º 4
0
class DbContentSchema(BaseSchema):
    title = validators.String(not_empty=True)
    type = DbContentTypeValidator()
    url = validators.String()
    body = validators.String()
    publish_date = validators.DateConverter(month_style='dd/mm/yyyy')
    publish_time = validators.TimeConverter(use_datetime=True)
Ejemplo n.º 5
0
 def fields(self, context):
     year = datetime.datetime.now().year
     fields = [
         self.Field('nickname',
                    "*Кличка",
                    validators.String(),
                    required=True),
         self.Field('breed', "*Порода", validators.String(), required=True),
         self.Field('year',
                    "*Год рождения",
                    validators.Number(min=1, max=year),
                    required=True,
                    default=0),
         self.Field('price',
                    "*Цена за щенка",
                    validators.Number(min=1),
                    required=True,
                    default=0),
         self.Field('FIO',
                    "*ФИО хозяина",
                    validators.String(),
                    required=True),
         self.Field('date_of_birth', "*Дата рождения",
                    validators.DateConverter()),
         self.Field('address', "*Адрес", validators.String(), required=True)
     ]
     return fields
Ejemplo n.º 6
0
class FileSchema(Schema):
    filter_extra_fields = True
    allow_extra_fields = True
    fileUpload = validators.FieldStorageUploadConverter(not_empty=True)
    title = validators.UnicodeString(not_empty=True, strip=True)
    fileDate = validators.DateConverter(month_style='mm/dd/yyyy', strip=True)
    description = validators.UnicodeString(strip=True)
    _csrf = validators.String(not_empty=True, strip=True)
Ejemplo n.º 7
0
class TransferSchema(AuthFormSchema):
    "Validate a transfer."
    allow_extra_fields = False
    debtor_id = validators.Int(not_empty=True)
    creditor_id = validators.Int(not_empty=True)
    amount = model.types.CurrencyValidator(not_empty=True)
    description = validators.UnicodeString()
    date = validators.DateConverter()
Ejemplo n.º 8
0
class PersonSchema(Schema):
    health_id = validators.String(not_empty=True)
    surname = validators.String(not_empty=True)
    other_names = validators.String(not_empty=True)
    gender = validators.String(not_empty=True)
    dob = validators.DateConverter(month_style='dd/mm/yyyy')
    location = validators.Int()
    allow_extra_fields = True
Ejemplo n.º 9
0
class ExpenditureSchema(AuthFormSchema):
    "Validate an expenditure."
    allow_extra_fields = False
    pre_validators = [NestedVariables()]
    spender_id = validators.Int(not_empty=True)
    amount = model.types.CurrencyValidator(not_empty=True)
    description = validators.UnicodeString(not_empty=True)
    date = validators.DateConverter()
    shares = ForEach(ShareSchema)
    chained_validators = [ValidateNotAllZero]
Ejemplo n.º 10
0
    def _modify_package_schema(self, schema):

        # TODO: need to implement chained validators
        # that allows to validate a group of fields together
        # e.g if start_date is entered then end_date is required

        # Add custom metadata fields to the schema, this one will use
        # convert_to_extras for all fields except for package_type for which convert_to_tags will be used.
        _not_empty = tk.get_validator('not_empty')
        _ignore_missing = tk.get_validator('ignore_missing')
        _convert_to_extras = tk.get_converter('convert_to_extras')

        schema.update({
            'pkg_model_name': [_not_empty, _convert_to_extras],
            'model_version': [_not_empty, _convert_to_extras],
            'north_extent': [_ignore_missing,
                             v.Number(), _convert_to_extras],
            'west_extent': [_ignore_missing,
                            v.Number(), _convert_to_extras],
            'south_extent': [_ignore_missing,
                             v.Number(), _convert_to_extras],
            'east_extent': [_ignore_missing,
                            v.Number(), _convert_to_extras],
            'simulation_start_day':
            [_ignore_missing,
             v.DateConverter(), _convert_to_extras],
            'simulation_end_day':
            [_ignore_missing,
             v.DateConverter(), _convert_to_extras],
            'time_step': [_ignore_missing,
                          v.Number(), _convert_to_extras],
            'package_type': [
                _not_empty,
                tk.get_converter('convert_to_tags')('model_package_types')
            ],
            'package_run_status': [_ignore_missing, _convert_to_extras],
            'package_run_job_id': [_ignore_missing, _convert_to_extras],
            'dataset_type': [_not_empty, _convert_to_extras]
        })

        schema = super(ModelPackagePlugin, self).modify_schema(schema)
        return schema
Ejemplo n.º 11
0
    def fields(self, context):

        fields = [
            self.Field('FIO', "*ФИО", validators.String(), required=True),
            self.Field('date_of_birth', "*Дата рождения",
                       validators.DateConverter()),
            self.Field('position',
                       "*Положение в налоговой",
                       validators.String(),
                       required=True),
            self.Field('salary',
                       "*Стоимость контракта",
                       validators.Number(),
                       units=" " + "UAH")
        ]
        return fields
Ejemplo n.º 12
0
 def fields(self, context):
     year = datetime.datetime.now().year
     fields = [
         self.Field('name',
                    "*Название компании",
                    validators.String(),
                    required=True),
         self.Field('year',
                    "*Год основания",
                    validators.Number(min=1, max=year),
                    required=True),
         self.Field('phone', "*Телефон", PhoneNumber, required=True),
         self.Field('employees_quantity',
                    "*Кол-во работников",
                    validators.Number(),
                    required=True),
         self.Field('date',
                    "*Дата",
                    validators.DateConverter(),
                    required=True),
         self.Field('amount', "*Сумма", validators.Number(), required=True)
     ]
     return fields
Ejemplo n.º 13
0
class EventObjectSchema(sqlobject.SQLSchema):

    wrap = EventObject
    # All other columns are inherited...
    description = validators.String(strip=True, max=1024, if_empty=None)
    date = validators.DateConverter(if_empty=None)
Ejemplo n.º 14
0
class InvoiceSchema(BaseSchema):
    person = ExistingPersonValidator(not_empty=True)
    due_date = validators.DateConverter(month_style='dd/mm/yyyy')
    items = ForEach(InvoiceItemValidator())

    item_count = validators.Int(min=0)  # no max, doesn't hit database
Ejemplo n.º 15
0
 def __init__(self, form, eid, label=NotGiven, vtype=NotGiven, defaultval=NotGiven, strip=True,
              **kwargs):
     vargs = multi_pop(kwargs, 'accept_day', 'month_style', 'datetime_module')
     TextElement.__init__(self, form, eid, label, vtype, defaultval, strip, **kwargs)
     self.add_processor(fev.DateConverter(**vargs))
Ejemplo n.º 16
0
    def _modify_package_schema(self, schema):

        # TODO: need to implement chained validators
        # that allows to validate a group of fields together
        # e.g if start_date is entered then end_date is required

        # Add custom metadata fields to the schema, this one will use
        # convert_to_extras for all fields except for package_type for which convert_to_tags will be used.
        _not_empty = tk.get_validator('not_empty')
        _ignore_missing = tk.get_validator('ignore_missing')
        _convert_to_extras = tk.get_converter('convert_to_extras')

        if dataset_type == 'model-package':
            schema.update({
                'pkg_model_name': [_not_empty, _convert_to_extras],
                'model_version': [_not_empty, _convert_to_extras],
                'north_extent':
                [_ignore_missing,
                 v.Number(), _convert_to_extras],
                'west_extent':
                [_ignore_missing,
                 v.Number(), _convert_to_extras],
                'south_extent':
                [_ignore_missing,
                 v.Number(), _convert_to_extras],
                'east_extent':
                [_ignore_missing,
                 v.Number(), _convert_to_extras],
                'simulation_start_day':
                [_ignore_missing,
                 v.DateConverter(), _convert_to_extras],
                'simulation_end_day':
                [_ignore_missing,
                 v.DateConverter(), _convert_to_extras],
                'time_step': [_ignore_missing,
                              v.Number(), _convert_to_extras],
                'package_type': [
                    _not_empty,
                    tk.get_converter('convert_to_tags')('model_package_types')
                ],
                'dataset_type': [_not_empty, _convert_to_extras]
            })

        elif dataset_type == 'multidimensional-space-time':
            schema.update({
                'variable_names': [_ignore_missing, _convert_to_extras],
                'variable_units': [_ignore_missing, _convert_to_extras],
                'north_extent':
                [_ignore_missing,
                 v.Number(), _convert_to_extras],
                'west_extent':
                [_ignore_missing,
                 v.Number(), _convert_to_extras],
                'south_extent':
                [_ignore_missing,
                 v.Number(), _convert_to_extras],
                'east_extent':
                [_ignore_missing,
                 v.Number(), _convert_to_extras],
                'data_start_day':
                [_ignore_missing,
                 v.DateConverter(), _convert_to_extras],
                'data_end_day':
                [_ignore_missing,
                 v.DateConverter(), _convert_to_extras],
                'projection': [_ignore_missing, _convert_to_extras],
                'dataset_type': [_not_empty, _convert_to_extras]
            })

        return schema