def _schema_update(schema, purpose): """ :param schema: schema dict to update :param purpose: 'create', 'update' or 'show' """ assert purpose in ('create', 'update', 'show') if purpose == 'create': schema['id'] = [ ignore_missing, protect_new_dataset_id, unicode, name_validator, package_id_doesnt_exist ] schema['name'] = [ ignore_missing, unicode, name_validator, package_name_validator ] if purpose in ('create', 'update'): schema['title'] = [not_empty_allow_override, unicode] schema['notes'] = [not_empty_allow_override, unicode] schema['owner_org'] = [ not_empty, owner_org_validator_publisher, unicode ] schema['license_id'] = [not_empty_allow_override, unicode] else: schema['author_email'] = [ fixed_value(schema_description.dataset_field_by_id['author_email']) ] schema['license_id'] = [ fixed_value(schema_description.dataset_field_by_id['license_id']) ] schema['department_number'] = [get_department_number] schema['license_title_fra'] = [get_license_field('title_fra')] schema['license_url_fra'] = [get_license_field('url_fra')] resources = schema['resources'] for name, lang, field in schema_description.dataset_field_iter(): if name in schema: continue # don't modify other existing fields v = _schema_field_validators(name, lang, field) if v is not None: schema[name] = v[0] if purpose != 'show' else v[1] if field['type'] == 'choice' and purpose in ('create', 'update'): schema[name].extend([ convert_pilot_uuid(field), OneOf([c['key'] for c in field['choices']]) ]) for name, lang, field in schema_description.resource_field_iter(): if field['mandatory'] and purpose in ('create', 'update'): resources[name] = [not_empty_allow_override, unicode] if field['type'] == 'choice' and purpose in ('create', 'update'): resources[name].extend([ convert_pilot_uuid(field), OneOf([c['key'] for c in field['choices']]) ]) if purpose in ('create', 'update'): schema['validation_override'] = [ignore_missing]
class _DefaultPermissionsForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True overwrite_default = StringBoolean(if_missing=False) anonymous = OneOf(['True', 'False'], if_missing=False) default_perm = OneOf(perms_choices) default_register = OneOf(register_choices) default_create = OneOf(create_choices)
class _ApplicationUiSettingsForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False web_push_ssl = OneOf(['true', 'false'], if_missing='false') paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=1, not_empty=True)) hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False) hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False) hooks_pretxnchangegroup_push_logger = OneOf(['True', 'False'], if_missing=False) hooks_preoutgoing_pull_logger = OneOf(['True', 'False'], if_missing=False)
class LipishaInitiateSchema(LipishaBaseSchema): api_version = OneOf(LIPISHA_API_VERSIONS, not_empty=True) api_type = OneOf([TYPE_INITIATE], not_empty=True) transaction_date = TimestampValidator(not_empty=True) transaction_amount = Number(not_empty=True) transaction_type = OneOf(LIPISHA_TRANSACTION_TYPES, not_empty=True) transaction_method = String(not_empty=True) transaction_name = String(not_empty=True) transaction_mobile = String(not_empty=True) transaction_paybill = String(not_empty=True) transaction_account = String(not_empty=True) transaction_merchant_reference = String()
class _RepoForkForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), SlugifyName()) repo_group = OneOf(repo_groups, hideList=True) repo_type = All(ValidForkType(old_data), OneOf(supported_backends)) description = UnicodeString(strip=True, min=1, not_empty=True) private = StringBoolean(if_missing=False) copy_permissions = StringBoolean(if_missing=False) update_after_clone = StringBoolean(if_missing=False) fork_parent_id = UnicodeString() chained_validators = [ValidForkName(edit, old_data)]
class PackageSchema(Schema): current_location = ResourceURI(model_cls=models.Location) current_path = UnicodeString() description = UnicodeString(max=256) encryption_key_fingerprint = UnicodeString(max=512) misc_attributes = UnicodeString() origin_pipeline = ResourceURI(model_cls=models.Pipeline) package_type = OneOf(_flatten(models.Package.PACKAGE_TYPE_CHOICES)) pointer_file_location = ResourceURI(model_cls=models.Location) pointer_file_path = UnicodeString() related_packages = ForEach(ResourceURI(model_cls=models.Package)) replicated_package = ResourceURI(model_cls=models.Package) size = Int(min=0) status = OneOf(_flatten(models.Package.STATUS_CHOICES))
def getValidator(self, request): return { self.name: OneOf(map(methodcaller('getKey', request), self.optionGetter(request)), hideList=True) }
class GetCharactersForm(Schema): allow_extra_fields = True filter_extra_fields = True field = OneOf([ u'transcription', u'phoneticTranscription', u'narrowPhoneticTranscription', u'morphemeBreak' ])
class RacingTeamApplnResultsValidator(Schema): name = NotEmpty() eventdate = DateConverter(month_style='iso') eventname = NotEmpty() distance = Number(min=0, max=200) units = OneOf(['miles', 'km']) time = TimeOptHoursConverter() agegrade = Number(min=0, max=100)
class PushesSchema(ReportSchema): """Pushes Report Schema.""" int_size = IntervalValidator() branches = BranchListValidator() type = OneOf(list=['int', 'hourly', 'all'], if_empty='all', if_missing='all') chained_validators = ReportSchema.chained_validators + [IntSizeInit()]
class _LdapSettingsForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True #pre_validators = [LdapLibValidator] ldap_active = StringBoolean(if_missing=False) ldap_host = UnicodeString(strip=True,) ldap_port = Number(strip=True,) ldap_tls_kind = OneOf(tls_kind_choices) ldap_tls_reqcert = OneOf(tls_reqcert_choices) ldap_dn_user = UnicodeString(strip=True,) ldap_dn_pass = UnicodeString(strip=True,) ldap_base_dn = UnicodeString(strip=True,) ldap_filter = UnicodeString(strip=True,) ldap_search_scope = OneOf(search_scope_choices) ldap_attr_login = All(AttrLoginValidator, UnicodeString(strip=True,)) ldap_attr_firstname = UnicodeString(strip=True,) ldap_attr_lastname = UnicodeString(strip=True,) ldap_attr_email = UnicodeString(strip=True,)
class LocationSchema(Schema): description = UnicodeString(max=256) purpose = OneOf(_flatten(models.Location.PURPOSE_CHOICES)) relative_path = UnicodeString() quota = Int(min=0) enabled = Bool() space = ResourceURI(model_cls=models.Space) pipeline = ForEach(ResourceURI(model_cls=models.Pipeline)) replicators = ForEach(ResourceURI(model_cls=models.Location))
class SlavesSchema(ReportSchema): """Slaves Report Schema.""" int_size = IntervalValidator() last_int_size = IntervalValidator() type = OneOf(list=['silos', 'all'], if_empty='all', if_missing='all') chained_validators = ReportSchema.chained_validators + [ IntSizeInit(divisions=2000), IntSizeInit(divisions=24, int_size_param='last_int_size') ]
class UserCreateSchema(Schema): """Schema for User create (fields may not be missing).""" email = Email(max=255, not_empty=True) password = UnicodeString(min=6) role = OneOf(('user', 'superuser', 'admin'), if_missing='user', hideList=True) class profile(Schema): first_name = UnicodeString(max=100, not_empty=True) last_name = UnicodeString(max=100, not_empty=True)
class ApplnValidator(Schema): name = ByteString(not_empty=True) email = Email() dob = DateConverter(month_style='iso') gender = OneOf(['M', 'F']) applntype = OneOf(['new', 'renewal']) race1_name = ByteString(not_empty=True) race1_location = ByteString(not_empty=True) race1_date = DateConverter(month_style='iso') race1_distance = Number(min=0, max=200) race1_units = OneOf(['miles', 'km']) race1_time = TimeOptHoursConverter() race1_resultslink = URL() race2_name = ByteString(not_empty=True) race2_location = ByteString(not_empty=True) race2_date = DateConverter(month_style='iso') race2_distance = Number(min=0, max=200) race2_units = OneOf(['miles', 'km']) race2_time = TimeOptHoursConverter() race2_resultslink = URL()
class SlaveDetailsSchema(ReportSchema): """Slave Details Report Schema.""" int_size = IntervalValidator() last_int_size = IntervalValidator() slave_id = Int(min=0) type = OneOf(list=['busy', 'all'], if_empty='all', if_missing='all') chained_validators = ReportSchema.chained_validators + [ IntSizeInit(divisions=24), IntSizeInit(divisions=24, int_size_param='last_int_size') ]
def default_relationship_schema(): schema = { 'id': [ignore_missing, unicode], 'subject': [ignore_missing, unicode], 'object': [ignore_missing, unicode], 'type': [not_empty, OneOf(ckan.model.PackageRelationship.get_all_types())], 'comment': [ignore_missing, unicode], 'state': [ignore], } return schema
class UserUpdateSchema(Schema): """Schema for User update (fields may be missing).""" ignore_key_missing = True email = Email(max=255, not_empty=True) password = UnicodeString(min=6) role = OneOf(('user', 'superuser', 'admin'), hideList=True, not_empty=True) class profile(Schema): first_name = UnicodeString(max=100, not_empty=True) last_name = UnicodeString(max=100, not_empty=True)
class _RepoForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), SlugifyName()) description = UnicodeString(strip=True, min=1, not_empty=True) repo_group = OneOf(repo_groups, hideList=True) private = StringBoolean(if_missing=False) chained_validators = [ValidRepoName(edit, old_data), ValidPerms(), ValidSettings]
class _RepoForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), SlugifyName()) clone_uri = All(UnicodeString(strip=True, min=1, not_empty=False)) repo_group = OneOf(repo_groups, hideList=True) repo_type = OneOf(supported_backends) description = UnicodeString(strip=True, min=1, not_empty=True) private = StringBoolean(if_missing=False) enable_statistics = StringBoolean(if_missing=False) enable_downloads = StringBoolean(if_missing=False) if edit: #this is repo owner user = All(UnicodeString(not_empty=True), ValidRepoUser) chained_validators = [ValidCloneUri()(), ValidRepoName(edit, old_data), ValidPerms()]
class UriData(Schema): """Validate URI data received from CSV or user input. All fields are required, cannot be None and no extra fields are allowed. """ title = String(not_empty=True) URI = URL(not_empty=True) notify = OneOf( ["always", "valid", "invalid"], not_empty=True )
class _UsersGroupForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True users_group_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidUsersGroup(edit, old_data)) users_group_active = StringBoolean(if_missing=False) if edit: users_group_members = OneOf(available_members, hideList=False, testValueList=True, if_missing=None, not_empty=False)
class _ReposGroupForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False group_name = All(UnicodeString(strip=True, min=1, not_empty=True), SlugifyName()) group_description = UnicodeString(strip=True, min=1, not_empty=True) group_parent_id = OneOf(available_groups, hideList=False, testValueList=True, if_missing=None, not_empty=False) chained_validators = [ValidReposGroup(edit, old_data), ValidPerms('group')]
class NewResearcherForm(Schema): """NewResearcherForm is a Schema for validating the data entered at the Add Researcher page. """ allow_extra_fields = True filter_extra_fields = True username = formencode.All(UniqueUsername(), PlainText(not_empty=True)) password = PlainText(not_empty=True) firstName = UnicodeString(not_empty=True) lastName = UnicodeString(not_empty=True) email = Email(not_empty=True) affiliation = UnicodeString() role = OneOf(app_globals.roles) personalPageContent = UnicodeString()
class InfoRaceResultValidator(Schema): common_eventdate = DateConverter(month_style='iso') raceresult_distance = Number(min=0, max=200) raceresult_units = OneOf(['miles', 'km']) raceresult_time = TimeOptHoursConverter()
class LipishaAcknowledgeSchema(LipishaBaseSchema): api_type = OneOf([TYPE_ACKNOWLEDGE], not_empty=True) transaction_status_code = String(not_empty=True) transaction_status = String(not_empty=True) transaction_status_description = String(not_empty=True)
def __init__(self, type_, attribute_schema=None, relationship_schema=None): self.add_field('type', OneOf([type_])) if attribute_schema: self.add_field('attributes', attribute_schema) if relationship_schema: self.add_field('relationships', relationship_schema)
def _schema_update(schema, purpose): """ :param schema: schema dict to update :param purpose: 'create', 'update' or 'show' """ assert purpose in ('create', 'update', 'show') # XXX: remove duplicate_extras_key validation # to work around update failures on packages with # multiple portal_release_date values mistakenly added if '__before' in schema: schema['__before'] = [ v for v in schema['__before'] if v != duplicate_extras_key ] if purpose == 'create': schema['id'] = [ protect_new_dataset_id, if_empty_generate_uuid, unicode, name_validator, package_id_doesnt_exist ] schema['name'] = [ if_empty_same_as('id'), unicode, name_validator, package_name_validator ] if purpose in ('create', 'update'): schema['title'] = [not_empty, unicode] schema['notes'] = [not_empty, unicode] schema['owner_org'] = [ not_empty, owner_org_validator_publisher, unicode ] schema['license_id'] = [not_empty, unicode] else: schema['author_email'] = [ fixed_value(schema_description.dataset_field_by_id['author_email']) ] schema['department_number'] = [get_department_number] schema['license_title_fra'] = [get_license_field('title_fra')] schema['license_url_fra'] = [get_license_field('url_fra')] resources = schema['resources'] for name, lang, field in schema_description.dataset_field_iter(): if name in schema: continue # don't modify other existing fields v = _schema_field_validators(name, lang, field) if v is not None: schema[name] = v[0] if purpose != 'show' else v[1] if field['type'] == 'choice' and purpose in ('create', 'update'): schema[name].extend([ convert_pilot_uuid(field), OneOf([c['key'] for c in field['choices']]) ]) for name, lang, field in schema_description.resource_field_iter(): if field['mandatory'] and purpose in ('create', 'update'): resources[name] = [not_empty, unicode] if field['type'] == 'choice' and purpose in ('create', 'update'): resources[name].extend([ convert_pilot_uuid(field), OneOf([c['key'] for c in field['choices']]) ])
class AlterSettingsForm(Schema): """AlterSettingsForm is a Schema for validating the data entered at the system settings page. """ allow_extra_fields = True filter_extra_fields = True pre_validators = [variabledecode.NestedVariables()] OLName = UnicodeString() OLId = UnicodeString() MLName = UnicodeString() MLId = UnicodeString() MLOrthography = UnicodeString() headerImageName = UnicodeString() colorsCSS = UnicodeString() orthographyOptions = [u'Orthography %s' % unicode(i) for i \ in range(1,6)] storageOrthography = OneOf(orthographyOptions) defaultInputOrthography = UnicodeString() defaultOutputOrthography = UnicodeString() objectLanguageOrthography1Name = UnicodeString() objectLanguageOrthography1 = UnicodeString() OLO1Lowercase = StringBoolean(if_missing=False) OLO1InitialGlottalStops = StringBoolean(if_missing=False) objectLanguageOrthography2Name = UnicodeString() objectLanguageOrthography2 = UnicodeString() OLO2Lowercase = StringBoolean(if_missing=False) OLO2InitialGlottalStops = StringBoolean(if_missing=False) objectLanguageOrthography3Name = UnicodeString() objectLanguageOrthography3 = UnicodeString() OLO3Lowercase = StringBoolean(if_missing=False) OLO3InitialGlottalStops = StringBoolean(if_missing=False) objectLanguageOrthography4Name = UnicodeString() objectLanguageOrthography4 = UnicodeString() OLO4Lowercase = StringBoolean(if_missing=False) OLO4InitialGlottalStops = StringBoolean(if_missing=False) objectLanguageOrthography5Name = UnicodeString() objectLanguageOrthography5 = UnicodeString() OLO5Lowercase = StringBoolean(if_missing=False) OLO5InitialGlottalStops = StringBoolean(if_missing=False) morphemeBreakIsObjectLanguageString = UnicodeString() unrestrictedUsers = ForEach(UnrestrictedUser()) orthographicValidation = OneOf([u'None', u'Warning', u'Error']) narrPhonInventory = UnicodeString() narrPhonValidation = OneOf([u'None', u'Warning', u'Error']) broadPhonInventory = UnicodeString() broadPhonValidation = OneOf([u'None', u'Warning', u'Error']) morphPhonInventory = UnicodeString() morphDelimiters = UnicodeString() morphPhonValidation = OneOf([u'None', u'Warning', u'Error']) punctuation = UnicodeString() grammaticalities = UnicodeString()
class InfoCommonValidator(Schema): common_name = ByteString(not_empty=True) common_eventname = ByteString(not_empty=True) common_eventdate = DateConverter(month_style='iso') common_infotype = OneOf(['raceresult', 'volunteer'])