Esempio n. 1
0
class BaseOutputterSchema(base_schema.ObjTypeSchema):
    'Base schema for all outputters - they all contain the following'
    on = SchemaNode(Bool(), missing=drop, save=True, update=True)
    output_zero_step = SchemaNode(Bool(), save=True, update=True)
    output_last_step = SchemaNode(Bool(), save=True, update=True)
    output_timestep = SchemaNode(extend_colander.TimeDelta(),
                                 missing=drop,
                                 save=True,
                                 update=True)
    output_start_time = SchemaNode(extend_colander.LocalDateTime(),
                                   validator=validators.convertible_to_seconds,
                                   missing=drop,
                                   save=True,
                                   update=True)
    surface_conc = SchemaNode(String(allow_empty=True), save=True, update=True)
Esempio n. 2
0
class IceMoverSchema(CurrentMoversBaseSchema):
    filename = SchemaNode(String(), missing=drop)
    topology_file = SchemaNode(String(), missing=drop)
    current_scale = SchemaNode(Float(), missing=drop)
    uncertain_along = SchemaNode(Float(), missing=drop)
    uncertain_cross = SchemaNode(Float(), missing=drop)
    extrapolate = SchemaNode(Bool(), missing=drop)
Esempio n. 3
0
class SpillSchema(ObjTypeSchema):
    'Spill class schema'
    on = SchemaNode(Bool(),
                    default=True,
                    missing=True,
                    description='on/off status of spill',
                    save=True,
                    update=True)
    release = GeneralGnomeObjectSchema(acceptable_schemas=[
        BaseReleaseSchema, PointLineReleaseSchema, ContinuousReleaseSchema,
        SpatialReleaseSchema
    ],
                                       save=True,
                                       update=True,
                                       save_reference=True)
    amount = SchemaNode(Float(), missing=drop, save=True, update=True)
    units = SchemaNode(String(), missing=drop, save=True, update=True)
    amount_uncertainty_scale = SchemaNode(Float(),
                                          missing=drop,
                                          save=True,
                                          update=True)
    #     frac_coverage = SchemaNode(
    #         Float(), missing=drop, save=True, update=True
    #     )
    element_type = ElementTypeSchema(save=True,
                                     update=True,
                                     save_reference=True)
    water = WaterSchema(missing=drop,
                        save=True,
                        update=True,
                        save_reference=True)
Esempio n. 4
0
class ProcessSchema(ObjTypeSchema):
    '''
    base Process schema - attributes common to all movers/weatherers
    defined at one place
    '''
    on = SchemaNode(Bool(), missing=drop, save=True, update=True)
    active_range = TimeRangeSchema()
Esempio n. 5
0
class TrajectoryGeoJsonSchema(BaseOutputterSchema):
    '''
    Nothing is required for initialization
    '''
    round_data = SchemaNode(Bool(), missing=drop, save=True, update=True)
    round_to = SchemaNode(Int(), missing=drop, save=True, update=True)
    output_dir = SchemaNode(String(), missing=drop, save=True, update=True)
Esempio n. 6
0
class SpillSchema(ObjType):
    'Spill class schema'
    on = SchemaNode(Bool(), default=True, missing=True,
                    description='on/off status of spill')
    amount = SchemaNode(Float(), missing=drop)
    units = SchemaNode(String(), missing=drop)
    amount_uncertainty_scale = SchemaNode(Float(), missing=drop)
Esempio n. 7
0
class NetCDFOutputSchema(BaseOutputterSchema):
    'colander schema for serialize/deserialize object'
    netcdf_filename = FilenameSchema(
        missing=drop, save=True, update=False, test_equal=False
    )
    which_data = SchemaNode(
        String(), default='standard', missing=drop, save=True, update=True
    )
    compress = SchemaNode(
        Bool(), missing=drop, save=True, update=True
    )
    _start_idx = SchemaNode(
        Int(), missing=drop, save=True, read_only=True, test_equal=False
    )
    _middle_of_run = SchemaNode(
        Bool(), missing=drop, save=True, read_only=True, test_equal=False
    )
Esempio n. 8
0
class GridWindMoverSchema(WindMoversBaseSchema):
    """
        Similar to WindMover except it doesn't have wind_id
    """
    filename = SchemaNode(String(), missing=drop)
    topology_file = SchemaNode(String(), missing=drop)
    wind_scale = SchemaNode(Float(), missing=drop)
    extrapolate = SchemaNode(Bool(), missing=drop)
Esempio n. 9
0
class PyWindMoverSchema(base_schema.ObjType):
    filename = SchemaNode(typ=Sequence(accept_scalar=True),
                          children=[SchemaNode(String())],
                          missing=drop)
    current_scale = SchemaNode(Float(), missing=drop)
    extrapolate = SchemaNode(Bool(), missing=drop)
    time_offset = SchemaNode(Float(), missing=drop)
    wind = GridVectorPropSchema(missing=drop)
Esempio n. 10
0
class WindMoverSchema(WindMoversBaseSchema):
    """
    Contains properties required by UpdateWindMover and CreateWindMover
    """
    # 'wind' schema node added dynamically
    name = 'WindMover'
    description = 'wind mover properties'
    extrapolate = SchemaNode(Bool(), missing=drop)
Esempio n. 11
0
class ProcessSchema(MappingSchema):
    '''
    base Process schema - attributes common to all movers/weatherers
    defined at one place
    '''
    on = SchemaNode(Bool(), missing=drop)
    active_start = SchemaNode(LocalDateTime(),
                              missing=drop,
                              validator=convertible_to_seconds)
    active_stop = SchemaNode(LocalDateTime(),
                             missing=drop,
                             validator=convertible_to_seconds)
Esempio n. 12
0
class BaseReleaseSchema(ObjType):
    'Base Class for Release Schemas'
    release_time = SchemaNode(LocalDateTime(),
                              validator=convertible_to_seconds)
    name = 'release'
    start_time_invalid = SchemaNode(Bool(), missing=drop)

    def __init__(self, json_='webapi', **kwargs):
        if json_ == 'save':
            # used to create a new Release object if model is persisted mid-run
            self.add(SchemaNode(Int(), name='num_released'))

        super(BaseReleaseSchema, self).__init__(**kwargs)
Esempio n. 13
0
class PyCurrentMoverSchema(ObjTypeSchema):
    current = GeneralGnomeObjectSchema(
        save=True,
        update=True,
        save_reference=True,
        acceptable_schemas=[VectorVariableSchema, GridCurrent._schema])
    filename = FilenameSchema(save=True,
                              update=False,
                              isdatafile=True,
                              missing=drop)
    current_scale = SchemaNode(Float(), save=True, update=True, missing=drop)
    extrapolation_is_allowed = SchemaNode(Bool(),
                                          save=True,
                                          update=True,
                                          missing=drop)
    on = SchemaNode(Bool(), missing=drop, save=True, update=True)
    active_range = TimeRangeSchema()
    data_start = SchemaNode(LocalDateTime(),
                            read_only=True,
                            validator=convertible_to_seconds)
    data_stop = SchemaNode(LocalDateTime(),
                           read_only=True,
                           validator=convertible_to_seconds)
Esempio n. 14
0
class GridCurrentMoverSchema(CurrentMoversBaseSchema):
    filename = FilenameSchema(missing=drop,
                              save=True,
                              update=False,
                              isdatafile=True,
                              test_equal=False)
    topology_file = FilenameSchema(missing=drop,
                                   save=True,
                                   update=False,
                                   isdatafile=True,
                                   test_equal=False)
    current_scale = SchemaNode(Float(), missing=drop, save=True, update=True)
    uncertain_along = SchemaNode(Float(), missing=drop, save=True, update=True)
    uncertain_cross = SchemaNode(Float(), missing=drop, save=True, update=True)
    extrapolate = SchemaNode(Bool(), missing=drop, save=True, update=True)
    time_offset = SchemaNode(Float(), missing=drop, save=True, update=True)
    is_data_on_cells = SchemaNode(Bool(), missing=drop, read_only=True)
    data_start = SchemaNode(LocalDateTime(),
                            read_only=True,
                            validator=convertible_to_seconds)
    data_stop = SchemaNode(LocalDateTime(),
                           read_only=True,
                           validator=convertible_to_seconds)
Esempio n. 15
0
class CustomMapSchema(MappingSchema):
    default_name = 'Map'
    name = SchemaNode(String(), default=default_name, missing=default_name)
    map_bounds = LongLatBounds(missing=drop)
    north_lat = SchemaNode(Float())
    west_lon = SchemaNode(Float())
    east_lon = SchemaNode(Float())
    south_lat = SchemaNode(Float())
    cross_dateline = SchemaNode(Bool(), missing=False, default=False)
    resolution = SchemaNode(String(),
                            validator=OneOf(custom_map_resolutions),
                            default='i',
                            missing='i')
    refloat_halflife = SchemaNode(Float(), default=1)
Esempio n. 16
0
class CatsMoverSchema(CurrentMoversBaseSchema):
    '''static schema for CatsMover'''
    filename = SchemaNode(String(), missing=drop)
    scale = SchemaNode(Bool(), missing=drop)
    scale_refpoint = WorldPoint(missing=drop)
    scale_value = SchemaNode(Float(), missing=drop)

    # the following six could be shared with grid_current
    # in a currents base class
    down_cur_uncertain = SchemaNode(Float(), missing=drop)
    up_cur_uncertain = SchemaNode(Float(), missing=drop)
    right_cur_uncertain = SchemaNode(Float(), missing=drop)
    left_cur_uncertain = SchemaNode(Float(), missing=drop)
    uncertain_eddy_diffusion = SchemaNode(Float(), missing=drop)
    uncertain_eddy_v0 = SchemaNode(Float(), missing=drop)
Esempio n. 17
0
class IceMoverSchema(CurrentMoversBaseSchema):
    filename = FilenameSchema(missing=drop,
                              save=True,
                              isdatafile=True,
                              test_equal=False,
                              update=False)
    topology_file = FilenameSchema(missing=drop,
                                   save=True,
                                   isdatafile=True,
                                   test_equal=False,
                                   update=False)
    current_scale = SchemaNode(Float(), missing=drop, save=True, update=True)
    uncertain_along = SchemaNode(Float(), missing=drop, save=True, update=True)
    uncertain_cross = SchemaNode(Float(), missing=drop, save=True, update=True)
    extrapolate = SchemaNode(Bool(), missing=drop, save=True, update=True)
Esempio n. 18
0
class PyWindMoverSchema(ObjTypeSchema):
    wind = GeneralGnomeObjectSchema(
        acceptable_schemas=[VectorVariableSchema, GridWind._schema],
        save=True, update=True, save_reference=True
    )
    filename = FilenameSchema(
        missing=drop, save=True, update=False, isdatafile=True
    )
    wind_scale = SchemaNode(
        Float(), missing=drop, save=True, update=True
    )
    extrapolation_is_allowed = SchemaNode(
        Bool(), missing=drop, save=True, update=True
    )
    time_offset = SchemaNode(
        Float(), missing=drop, save=True, update=True
    )
    on = SchemaNode(
        Bool(), missing=drop, save=True, update=True
    )
    active_start = SchemaNode(
        LocalDateTime(), missing=drop,
        validator=convertible_to_seconds,
        save=True, update=True
    )
    active_stop = SchemaNode(
        LocalDateTime(), missing=drop,
        validator=convertible_to_seconds,
        save=True, update=True
    )
    data_start = SchemaNode(
        LocalDateTime(), validator=convertible_to_seconds, read_only=True
    )
    data_stop = SchemaNode(
        LocalDateTime(), validator=convertible_to_seconds, read_only=True
    )
Esempio n. 19
0
class GridWindMoverSchema(WindMoversBaseSchema):
    """
        Similar to WindMover except it doesn't have wind_id
    """
    filename = FilenameSchema(missing=drop,
                              save=True,
                              update=True,
                              isdatafile=True,
                              test_equal=False)
    topology_file = FilenameSchema(missing=drop,
                                   save=True,
                                   update=True,
                                   isdatafile=True,
                                   test_equal=False)
    wind_scale = SchemaNode(Float(), missing=drop, save=True, update=True)
    extrapolate = SchemaNode(Bool(), missing=drop, save=True, update=True)
Esempio n. 20
0
class ModelSchema(MappingSchema):
    id = SchemaNode(String(), missing=drop)
    start_time = SchemaNode(LocalDateTime(),
                            default=now,
                            validator=validators.convertible_to_seconds)
    duration_days = SchemaNode(Int(), default=1, validator=Range(min=0))
    duration_hours = SchemaNode(Int(), default=0, validator=Range(min=0))
    uncertain = SchemaNode(Bool(), default=False)
    time_step = SchemaNode(Float(), default=0.1)
    surface_release_spills = PointSourceReleasesSchema(default=[],
                                                       missing=drop)
    wind_movers = WindMoversSchema(default=[], missing=drop)
    random_movers = RandomMoversSchema(default=[], missing=drop)
    cats_movers = CatsMoversSchema(default=[], missing=drop)
    grid_current_movers = GridCurrentMoversSchema(default=[], missing=drop)
    winds = WindsSchema(default=[], missing=drop)
    map = MapSchema(missing=drop)
Esempio n. 21
0
class CatsMoverSchema(CurrentMoversBaseSchema):
    '''static schema for CatsMover'''
    filename = FilenameSchema(save=True,
                              isdatafile=True,
                              test_equal=False,
                              update=False)
    scale = SchemaNode(Bool(), missing=drop, save=True, update=True)
    scale_refpoint = WorldPoint(missing=drop, save=True, update=True)
    scale_value = SchemaNode(Float(), missing=drop, save=True, update=True)

    # the following six could be shared with grid_current
    # in a currents base class
    down_cur_uncertain = SchemaNode(Float(),
                                    missing=drop,
                                    save=True,
                                    update=True)
    up_cur_uncertain = SchemaNode(Float(),
                                  missing=drop,
                                  save=True,
                                  update=True)
    right_cur_uncertain = SchemaNode(Float(),
                                     missing=drop,
                                     save=True,
                                     update=True)
    left_cur_uncertain = SchemaNode(Float(),
                                    missing=drop,
                                    save=True,
                                    update=True)
    uncertain_eddy_diffusion = SchemaNode(Float(),
                                          missing=drop,
                                          save=True,
                                          update=True)
    uncertain_eddy_v0 = SchemaNode(Float(),
                                   missing=drop,
                                   save=True,
                                   update=True)
    tide = TideSchema(missing=drop,
                      save=True,
                      update=True,
                      save_reference=True)
    data_start = SchemaNode(LocalDateTime(),
                            read_only=True,
                            validator=convertible_to_seconds)
    data_stop = SchemaNode(LocalDateTime(),
                           read_only=True,
                           validator=convertible_to_seconds)
Esempio n. 22
0
class Login(CSRFSchema):
    login = SchemaNode(
        String(),
        title='Username or Email',
    )
    password = SchemaNode(
        String(),
        widget=PasswordWidget(),
    )
    remember_me = SchemaNode(
        Bool(),
        title="Remember me?",
        missing=False,
    )
    came_from = SchemaNode(
        String(),
        widget=HiddenWidget(),
        default='.',
        title=u'came_from',
    )
Esempio n. 23
0
class PyWindMoverSchema(ObjTypeSchema):
    wind = GeneralGnomeObjectSchema(
        save=True,
        update=True,
        save_reference=True,
        acceptable_schemas=[VectorVariableSchema, GridWind._schema])
    filename = FilenameSchema(save=True,
                              update=False,
                              isdatafile=True,
                              missing=drop)
    scale_value = SchemaNode(Float(), save=True, update=True, missing=drop)
    time_offset = SchemaNode(Float(), save=True, update=True, missing=drop)
    on = SchemaNode(Bool(), save=True, update=True, missing=drop)
    active_range = TimeRangeSchema()
    data_start = SchemaNode(LocalDateTime(),
                            read_only=True,
                            validator=convertible_to_seconds)
    data_stop = SchemaNode(LocalDateTime(),
                           read_only=True,
                           validator=convertible_to_seconds)
Esempio n. 24
0
class BaseSchema(base_schema.ObjType, MappingSchema):
    'Base schema for all outputters - they all contain the following'
    on = SchemaNode(Bool(), missing=drop)
    output_zero_step = SchemaNode(Bool())
    output_last_step = SchemaNode(Bool())
    output_timestep = SchemaNode(extend_colander.TimeDelta(), missing=drop)
Esempio n. 25
0
class TextacyPreprocess(Schema):
    """ Schema for textacy preprocessing pipeline component
    """

    fix_unicode = SchemaNode(
        Bool(),
        default=True,
        title="Fix Unicode",
        label='Fix broken unicode such as mojibake and garbled HTML entities.',
    )
    lowercase = SchemaNode(
        Bool(),
        default=False,
        missing=False,
        label="All text is lower-cased",
        title='Lowercase',
    )
    transliterate = SchemaNode(
        Bool(),
        default=True,
        missing=False,
        title='Transliterate',
        label="Convert non-ASCII characters to their closest ASCII equivalent."
    )
    no_urls = SchemaNode(Bool(),
                         default=True,
                         missing=False,
                         title='No URLs',
                         label="Replace all URL strings with ‘URL‘.")
    no_emails = SchemaNode(Bool(),
                           default=True,
                           missing=False,
                           title='No emails',
                           label="Replace all email strings with ‘EMAIL‘.")
    no_phone_numbers = SchemaNode(
        Bool(),
        default=True,
        missing=False,
        title='No phone numbers',
        label="Replace all phone number strings with ‘PHONE‘.")
    no_numbers = SchemaNode(
        Bool(),
        default=True,
        missing=False,
        title="No numbers",
        label="Replace all number-like strings with ‘NUMBER‘.")
    no_currency_symbols = SchemaNode(
        Bool(),
        default=True,
        missing=False,
        title="No currency symbols",
        label="Replace all currency symbols with their standard 3-letter "
        "abbreviations.")
    no_punct = SchemaNode(
        Bool(),
        default=True,
        missing=False,
        title="No punctuation",
        label="Remove all punctuation (replace with empty string).")
    no_contractions = SchemaNode(
        Bool(),
        default=True,
        missing=False,
        title="No contractions",
        label="Replace English contractions with their unshortened forms.")
    no_accents = SchemaNode(
        Bool(),
        default=True,
        missing=False,
        title="No accents",
        label="Replace all accented characters with unaccented versions; "
        "NB: if transliterate is True, this option is redundant.")
Esempio n. 26
0
class BaseSchema(MappingSchema):
    filter_extra_fields = SchemaNode(Bool())
    allow_extra_fields = SchemaNode(Bool())
Esempio n. 27
0
def make_profile_form(request, edit=False):
    target_user = getattr(request, 'target_user', None)
    user = target_user or request.user
    email_validator = dict(should_exist=False,
                           msg="Email address already in use.",
                           db_session=request.db_session)
    username_validator = dict(should_exist=False,
                              db_session=request.db_session)
    if edit:
        email_validator['for_edit'] = True
        # We need to attach the current value of the user's email
        # so we know if they're trying to change it during validation
        schema = EditProfileSchema()
        for fld in schema:
            if fld.name == 'email':
                fld.current_value = user.email
        if request.user.is_superuser:
            is_superuser = SchemaNode(
                Bool(),
                title='Is this user an admin?',
            )
            user_disabled = SchemaNode(
                Bool(),
                title='User disabled?',
            )
            schema['user_disabled'] = user_disabled
            schema['is_superuser'] = is_superuser

        # Can't compare SQLA objects here, so use the usernames.
        # Admin users editing their own profile still need a password.
        username = request.user.username
        target_username = target_user.username
        if username == target_username or not request.user.is_superuser:
            password = SchemaNode(
                String(),
                required=False,
                missing=null,
                description=u"Password only required if changing email.",
                widget=PasswordWidget(),
                title='Password',
                name='password',
            )
            schema['password'] = password
    else:
        schema = Profile()
        if not request.user:
            # Only include these if the user isn't logged in
            agree_to_policy = SchemaNode(
                Bool(),
                title='I agree to the site policy.',
                validator=Function(
                    usage_policy_validator,
                    message='Agreement with the site policy is required.'),
            )
            captcha = SchemaNode(
                String(),
                widget=deferred_recaptcha_widget,
            )
            schema['agree_to_policy'] = agree_to_policy
            schema['captcha'] = captcha
        elif request.user.is_superuser:
            is_superuser = SchemaNode(
                Bool(),
                title='Is this user an admin?',
            )
            schema['is_superuser'] = is_superuser

    form = Form(
        buttons=('submit', ),
        resource_registry=password_registry,
        renderer=renderer,
        schema=schema.bind(request=request,
                           email_validator=email_validator,
                           username_validator=username_validator),
        bootstrap_form_style='form-vertical',
    )
    return form