class ValidWifiSchema(ValidMeasureSchema): """ A Schema which validates the fields present in a a wifi measurement. """ channel = SchemaNode(Integer(), missing=0, validator=Range( constants.MIN_WIFI_CHANNEL, constants.MAX_WIFI_CHANNEL)) key = WifiKeyNode(String()) signal = DefaultNode(Integer(), missing=0, validator=Range( constants.MIN_WIFI_SIGNAL, constants.MAX_WIFI_SIGNAL)) signalToNoiseRatio = DefaultNode( Integer(), missing=0, validator=Range(0, 100)) def deserialize(self, data): if data: channel = int(data.get('channel', 0)) if not (constants.MIN_WIFI_CHANNEL < channel < constants.MAX_WIFI_CHANNEL): # if no explicit channel was given, calculate freq = data.get('frequency', 0) if 2411 < freq < 2473: # 2.4 GHz band data['channel'] = (freq - 2407) // 5 elif 5169 < freq < 5826: # 5 GHz band data['channel'] = (freq - 5000) // 5 else: data['channel'] = self.fields['channel'].missing return super(ValidWifiSchema, self).deserialize(data)
class WifiAccessPointSchema(MappingSchema): # required macAddress = SchemaNode(String()) # optional signalStrength = SchemaNode(Integer(), missing=0) age = SchemaNode(Integer(), missing=0) channel = SchemaNode(Integer(), missing=0) signalToNoiseRatio = SchemaNode(Integer(), missing=0)
class GeoLocateSchema(MappingSchema): homeMobileCountryCode = SchemaNode(Integer(), missing=None) homeMobileNetworkCode = SchemaNode(Integer(), missing=None) radioType = SchemaNode(String(), validator=OneOf(RADIO_STRINGS), missing=None) carrier = SchemaNode(String(), missing='') cellTowers = CellTowersSchema(missing=()) wifiAccessPoints = WifiAccessPointsSchema(missing=())
class EvaluationQuerySchema(StrictMappingSchema): contribution_id = SchemaNode(Integer(), location='querystring', type='int', missing=None) evaluator_id = SchemaNode(Integer(), location='querystring', type='int', missing=None)
class HomerSchema(MappingSchema): q = SchemaNode(String(), location='querystring') lang = SchemaNode(String(), location='querystring') wt = SchemaNode(String(), location='querystring', missing='json', validator=OneOf(['json'])) start = SchemaNode(Integer(), location='querystring') rows = SchemaNode(Integer(), location='querystring')
class TaskSchema(BaseModelSchema): """ Schema definition for Task model. """ name = SchemaNode(String(), validator=Length(min=3)) parent_id = SchemaNode(Integer(), missing=drop) project_id = SchemaNode(Integer(), missing=drop) user_id = SchemaNode(Integer())
class WifiSchema(MappingSchema): key = SchemaNode(String()) frequency = SchemaNode(Integer(), missing=0) channel = SchemaNode(Integer(), missing=0) signal = SchemaNode(Integer(), missing=0) signalToNoiseRatio = SchemaNode(Integer(), missing=0) radio = SchemaNode(String(), missing=None) age = SchemaNode(Integer(), missing=None)
class ValidCellSchema(ValidCellBaseSchema): """ A Schema which validates the fields present in all Cells. """ created = SchemaNode(DateTimeFromString(), missing=None) modified = SchemaNode(DateTimeFromString(), missing=None) changeable = SchemaNode(Boolean(), missing=True) total_measures = SchemaNode(Integer(), missing=0) range = SchemaNode(Integer(), missing=0)
class CellTowerSchema(MappingSchema): # mapped to 'radio' for submit radioType = SchemaNode(String(), validator=OneOf(RADIO_STRINGS), missing=None) # mapped to 'cid' for submit cellId = SchemaNode(Integer(), missing=None) # mapped to 'lac' for submit locationAreaCode = SchemaNode(Integer(), missing=None) # mapped to 'mcc' for submit mobileCountryCode = SchemaNode(Integer()) # mapped to 'mnc' for submit mobileNetworkCode = SchemaNode(Integer()) # optional age = SchemaNode(Integer(), missing=0) # mapped to 'signal' for submit signalStrength = SchemaNode(Integer(), missing=0) # mapped to 'ta' for submit timingAdvance = SchemaNode(Integer(), missing=0) # The fields below are extra fields which are not part of the # geolocate API, but assist with data submission psc = SchemaNode(Integer(), missing=-1) asu = SchemaNode(Integer(), missing=-1)
class BaseReportSchema(MappingSchema): lat = SchemaNode(Float(), missing=None) lon = SchemaNode(Float(), missing=None) time = SchemaNode(String(), missing='') accuracy = SchemaNode(Integer(), missing=0) altitude = SchemaNode(Integer(), missing=0) altitude_accuracy = SchemaNode(Integer(), missing=0) radio = SchemaNode(String(), validator=OneOf(RADIO_STRINGS), missing=None) heading = SchemaNode(Float(), missing=-1.0) speed = SchemaNode(Float(), missing=-1.0)
class CellSchema(MappingSchema): radio = SchemaNode(String(), missing=None) mcc = SchemaNode(Integer(), missing=-1) mnc = SchemaNode(Integer(), missing=-1) lac = SchemaNode(Integer(), missing=-1) cid = SchemaNode(Integer(), missing=-1) psc = SchemaNode(Integer(), missing=-1) asu = SchemaNode(Integer(), missing=-1) signal = SchemaNode(Integer(), missing=0) ta = SchemaNode(Integer(), missing=0) age = SchemaNode(Integer(), missing=None) serving = SchemaNode(Integer(), missing=None)
class WifiAccessPointSchema(MappingSchema): # mapped to 'key' for submit macAddress = SchemaNode(String()) # mapped to 'signal' for submit signalStrength = SchemaNode(Integer(), missing=0) age = SchemaNode(Integer(), missing=0) channel = SchemaNode(Integer(), missing=0) signalToNoiseRatio = SchemaNode(Integer(), missing=0) # The fields below are extra fields which are not part of the # geolocate API, but assist with data submission frequency = SchemaNode(Integer(), missing=0)
class Authentication(Schema): token_duration = SchemaNode( Integer(), default=TOKEN_DURATION, description=u'Duration (in minutes) password reset tokens are valid for.' ) max_attempts = SchemaNode( Integer(), default=MAX_DOMAIN_ATTEMPTS, title="Maximum login attempts", description="Indicate the system default number of times a user may " "fail a login attempt before being disabled (must be >= 1)", validator=Range(min=1), )
class QueryStringSchema(MappingSchema): limit = SchemaNode(Integer(), missing=drop, validator=colander.Range(0, COLLECTION_MAX_LENGTH)) offset = SchemaNode(Integer(), missing=drop) sort_by = SchemaNode(String(), missing=drop) sort_direction = SchemaNode(String(), missing='asc', validator=OneOf(['asc', 'desc'])) provider_id = SchemaNode(String(), missing=drop, validator=Length(1, SAFE_MAX_LENGTH)) start_time = SchemaNode(DateTime(default_tzinfo=None), missing=drop) end_time = SchemaNode(DateTime(default_tzinfo=None), missing=drop)
class BaseReportSchema(MappingSchema): # lat/lon being set to -255 indicates that this report should be # skipped. Other fields can be filled in with defaults lat = SchemaNode(Float(), missing=-255) lon = SchemaNode(Float(), missing=-255) time = SchemaNode(String(), missing='') accuracy = SchemaNode(Integer(), missing=0) altitude = SchemaNode(Integer(), missing=0) altitude_accuracy = SchemaNode(Integer(), missing=0) radio = SchemaNode(String(), validator=OneOf(RADIO_TYPE_KEYS), missing='') heading = SchemaNode(Float(), missing=-1.0) speed = SchemaNode(Float(), missing=-1.0)
class ProjectSchema(BaseModelSchema): """ Schema definition for Project model. """ name = SchemaNode(String(), validator=Length(min=3)) parent_id = SchemaNode(Integer(), missing=drop) client_id = SchemaNode(Integer(), missing=drop) user_id = SchemaNode(Integer()) is_public = SchemaNode(Boolean(), validator=RequirePermissions( PERMISSION.get('project', 'set_is_public', context=__name__)), missing=drop)
class ActivitySchema(BaseModelSchema): """ Schema definition for activity model. """ description = SchemaNode(String()) start = SchemaNode(DateTime(), missing=drop) end = SchemaNode(DateTime(), missing=drop) activity_type = SchemaNode(String(), missing=drop, validator=OneOf(ACTIVITY_TYPES.keys()), default=ACTIVITY_UNASSIGNED) project_id = SchemaNode(Integer(), missing=drop) task_id = SchemaNode(Integer(), missing=drop) user_id = SchemaNode(Integer())
class ContributionSchema(StrictMappingSchema): contributor_id = SchemaNode(Integer(), location='body', type='int') contribution_type = SchemaNode(String(), name='type', location='body', type='str', missing=None)
class BaseReportSchema(MappingSchema): lat = SchemaNode(BoundedFloat(), missing=None) lon = SchemaNode(BoundedFloat(), missing=None) time = SchemaNode(String(), missing='') accuracy = SchemaNode(Integer(), missing=0) altitude = SchemaNode(Integer(), missing=0) altitude_accuracy = SchemaNode(Integer(), missing=0) radio = SchemaNode(String(), missing=None) heading = SchemaNode(BoundedFloat(), missing=-1.0) speed = SchemaNode(BoundedFloat(), missing=-1.0) age = SchemaNode(Integer(), missing=None) source = SchemaNode(String(), missing='gps') pressure = SchemaNode(Integer(), missing=None)
class BodySchema(MappingSchema): # foo and bar are required, baz is optional foo = SchemaNode(String()) bar = SchemaNode(String(), validator=validate_bar) baz = SchemaNode(String(), missing=None) ipsum = SchemaNode(Integer(), missing=1, validator=Range(0, 3)) integers = Integers(missing=())
class AddEntrySchema(MappingSchema): project_id = SchemaNode(Integer()) ticket_id = SchemaNode(TicketObject()) time = SchemaNode(TimeObject(), validator=Range(0.0, 24.00)) description = SchemaNode(String()) timer = SchemaNode(Boolean()) add_to_harvest = SchemaNode(Boolean())
class InitSchema(MappingSchema): """ Base schema used for constructor """ retries = SchemaNode(Integer(), validator=colander.Range(0, float('inf')))
class GeoLocateSchema(MappingSchema): homeMobileCountryCode = SchemaNode(Integer(), location="body", type='int', missing=0) homeMobileNetworkCode = SchemaNode(Integer(), location="body", type='int', missing=0) radioType = SchemaNode(String(), location="body", type='str', validator=OneOf(RADIO_TYPE_KEYS), missing='') carrier = SchemaNode(String(), location="body", missing='') cellTowers = CellTowersSchema(missing=()) wifiAccessPoints = WifiAccessPointsSchema(missing=())
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())
class MeasureSchema(MappingSchema): lat = SchemaNode(Decimal(quant=EXPONENT_STR), location="body") lon = SchemaNode(Decimal(quant=EXPONENT_STR), location="body") time = SchemaNode(String(), location="body", missing='') accuracy = SchemaNode(Integer(), location="body", type='int', missing=0) altitude = SchemaNode(Integer(), location="body", type='int', missing=0) altitude_accuracy = SchemaNode(Integer(), location="body", type='int', missing=0) radio = SchemaNode(String(), location="body", type='str', validator=OneOf(RADIO_TYPE_KEYS), missing='') cell = CellsSchema(missing=()) wifi = WifisSchema(missing=())
class CellSchema(MappingSchema): radio = SchemaNode(String(), validator=OneOf(RADIO_TYPE_KEYS), missing='') mcc = SchemaNode(Integer(), missing=-1) mnc = SchemaNode(Integer(), missing=-1) lac = SchemaNode(Integer(), missing=-1) cid = SchemaNode(Integer(), missing=-1) psc = SchemaNode(Integer(), missing=-1) asu = SchemaNode(Integer(), missing=-1) signal = SchemaNode(Integer(), missing=0) ta = SchemaNode(Integer(), missing=0)
class DomainDefaults(Schema): password_valid = SchemaNode( Integer(), default=MAX_PASSWORD_VALID, title="Password valid", description="Indicate the system default time in minutes that a " "password should be valid (must be >= 0)", validator=Range(min=0), )
def __init__(self, title, name, round=1, missing=-1, widget=None, l_choices=None, desc=None, table_reduce=False, rank=0, required=False, missing_msg='champ requis', primary_key=False): # Form display & param self.title = title self.round = round self.name = name self.type = int self.desc = desc self.required = required self.missing_msg = missing_msg self.mapinit = None # Db column self.dbcol_ = (name, Colsql(Intsql, primary_key=primary_key)) # Table display & param self.table_reduce, self.rank, = table_reduce, rank if widget is not None: self.widget = widget else: if l_choices: self.widget = Select2Widget(values=l_choices) else: self.widget = None self.processing_form = { 'form': lambda x: int(x) if x else missing, 'db': lambda x: int(x) } self.processing_db = { 'upload': lambda x: int(x), 'download': lambda x: int(x) } self.sn = sn(Integer(), title=self.title, name=name, widget=self.widget, description=desc, required=self.required, missing_msg=self.missing_msg) if not required: self.sn.missing = missing
class TagSchema(BaseModelSchema): """ Schema definition for Tag model. """ name = SchemaNode( String(), validator=Length(min=3)) description = SchemaNode( String(), missing=drop) tag_type = SchemaNode( String()) original_id = SchemaNode( Integer(), missing=drop) user_id = SchemaNode( Integer())
class GeoSubmitSchema(MappingSchema): # The first portion of the GeoSubmitSchema is identical to the # Gelocate schema with the exception that the radioType validator # can accept one more radioType (lte) homeMobileCountryCode = SchemaNode( Integer(), missing=-1) homeMobileNetworkCode = SchemaNode( Integer(), missing=-1) # mapped to 'radio' for submit radioType = SchemaNode(String(), validator=OneOf(GEOSUBMIT_RADIO_TYPE_KEYS), missing='') carrier = SchemaNode(String(), missing='') cellTowers = CellTowersSchema(missing=()) wifiAccessPoints = WifiAccessPointsSchema(missing=()) # The fields below are extra fields which are not part of the # geolocate API, but are part of the submit schema # mapped to 'lat' for submit latitude = SchemaNode(Float(), missing=-255) # mapped to 'lon' for submit longitude = SchemaNode(Float(), missing=-255) # parsed and mapped to 'time' for submit timestamp = SchemaNode(Integer(), missing=0) # mapped to 'accuracy' for submit accuracy = SchemaNode(Float(), missing=0) # mapped to 'altitude' for submit altitude = SchemaNode(Float(), missing=0) # mapped to 'altitude_accuracy' for submit altitudeAccuracy = SchemaNode(Float(), missing=0) # radio is taken from radioType # cell is taken from cellTowers # wifi is taken from wifiAccessPoints heading = SchemaNode(Float(), missing=-1.0) speed = SchemaNode(Float(), missing=-1.0)