def validate_post(self, x, fieldname, schema, path, post): if post and not x['organization_id'].startswith('party:'): division_id = re.sub(r'\/(?:council|legislature)\Z', '', x['organization_id'].replace('jurisdiction:ocd-jurisdiction', 'ocd-division')) value = x.get(fieldname) if subdivisions.get(division_id): # Not among the known subdivisions for the division. if value not in subdivisions[division_id] and not re.search(r'\AWards \d(?:(?:,| & | and )\d+)+\Z', value): self._error("Post: Value {value!r} for field '{fieldname}' is not " "in the enumeration: {options!r}", value, fieldname, options=subdivisions[division_id]) else: # Not a unique role. if x['role'] not in uniqueRoles: self._error("Post: No known subdivisions for this division for non-unique role {value!r}", x['role'], 'role', options=uniqueRoles) # A unique role that's not among the known roles for the division. if styles.get(division_id) and x['role'] not in styles[division_id]: self._error("Post: Unique role {value!r} is not in the enumeration: {options!r}", x['role'], 'role', options=styles[division_id]) # A unique role that's among the known roles for the division, but where the post doesn't match the name of the division. if names.get(division_id) and value != names[division_id]: self._error("Post: Unique role's post {value!r} is not in the enumeration: {options!r}", value, fieldname, options=[names[division_id]]) else: self._error("Post: Cannot validate unique role's post {value!r} in division {division_id!r}", value, fieldname, division_id=division_id)
def validate_post(self, x, fieldname, schema, path, post): if post and not x['organization_id'].startswith('party:'): division_id = re.sub( r'\/(?:council|legislature)\Z', '', x['organization_id'].replace('jurisdiction:ocd-jurisdiction', 'ocd-division')) value = x.get(fieldname) if subdivisions.get(division_id): # Not among the known subdivisions for the division. if value not in subdivisions[division_id] and not re.search( r'\AWards \d(?:(?:,| & | and )\d+)+\Z', value): self._error( "Post: Value {value!r} for field '{fieldname}' is not " "in the enumeration: {options!r}", value, fieldname, options=subdivisions[division_id]) else: # Not a unique role. if x['role'] not in uniqueRoles: self._error( "Post: No known subdivisions for this division for non-unique role {value!r}", x['role'], 'role', options=uniqueRoles) # A unique role that's not among the known roles for the division. if styles.get( division_id) and x['role'] not in styles[division_id]: self._error( "Post: Unique role {value!r} is not in the enumeration: {options!r}", x['role'], 'role', options=styles[division_id]) # A unique role that's among the known roles for the division, but where the post doesn't match the name of the division. if names.get(division_id) and value != names[division_id]: self._error( "Post: Unique role's post {value!r} is not in the enumeration: {options!r}", value, fieldname, options=[names[division_id]]) else: self._error( "Post: Cannot validate unique role's post {value!r} in division {division_id!r}", value, fieldname, division_id=division_id)
# A person should have, in most cases, at most one non-social media link, and # should have at most one link per social media website. person_links['maxMatchingItems'] = [ (1, lambda x: not social_re.search(x['url']), 'Person has many non-social media links'), (1, lambda x: facebook_re.search(x['url']), 'Person has many facebook.com links'), (1, lambda x: twitter_re.search(x['url']), 'Person has many twitter.com links'), (1, lambda x: youtube_re.search(x['url']), 'Person has many youtube.com links'), ] membership_schema['properties']['role']['blank'] = False membership_schema['properties']['post_id']['post'] = True membership_schema['properties']['role']['enum'] = lambda x: ['candidate'] + styles.get(re.sub(r'\/(?:council|legislature)\Z', '', x['organization_id'].replace('jurisdiction:ocd-jurisdiction', 'ocd-division')), ['member']) membership_schema['properties']['contact_details'] = membership_contact_details membership_schema['properties']['links'] = membership_links membership_schema['matches'] = [( lambda x: next((True for y in x['contact_details'] if y['type'] == 'email'), False), lambda x: ( x['organization_id'].startswith('party:') or x['organization_id'] in ( # Javascript-encoded email 'jurisdiction:ocd-jurisdiction/country:ca/csd:1217030/council', # Cape Breton # Webform email 'jurisdiction:ocd-jurisdiction/country:ca/csd:1310032/council', # Fredericton 'jurisdiction:ocd-jurisdiction/country:ca/csd:2423027/council', # Québec 'jurisdiction:ocd-jurisdiction/country:ca/csd:2464008/council', # Terrebonne 'jurisdiction:ocd-jurisdiction/country:ca/csd:2466097/council', # Pointe-Claire 'jurisdiction:ocd-jurisdiction/country:ca/csd:3530016/council', # Waterloo
person_links['maxMatchingItems'] = [ (1, lambda x: not social_re.search(x['url']), 'Person has many non-social media links'), (1, lambda x: facebook_re.search(x['url']), 'Person has many facebook.com links'), (1, lambda x: twitter_re.search(x['url']), 'Person has many twitter.com links'), (1, lambda x: youtube_re.search(x['url']), 'Person has many youtube.com links'), ] membership_schema['properties']['role']['blank'] = False membership_schema['properties']['post_id']['post'] = True membership_schema['properties']['role'][ 'enum'] = lambda x: ['candidate'] + styles.get( re.sub( r'\/(?:council|legislature)\Z', '', x['organization_id'].replace( 'jurisdiction:ocd-jurisdiction', 'ocd-division')), ['member']) membership_schema['properties']['contact_details'] = membership_contact_details membership_schema['properties']['links'] = membership_links membership_schema['matches'] = [( lambda x: next( (True for y in x['contact_details'] if y['type'] == 'email'), False), lambda x: ( x['organization_id'].startswith('party:') or x['organization_id'] in ( # Javascript-encoded email 'jurisdiction:ocd-jurisdiction/country:ca/csd:1217030/council', # Cape Breton # Webform email 'jurisdiction:ocd-jurisdiction/country:ca/csd:1310032/council', # Fredericton 'jurisdiction:ocd-jurisdiction/country:ca/csd:2423027/council', # Québec 'jurisdiction:ocd-jurisdiction/country:ca/csd:2464008/council', # Terrebonne 'jurisdiction:ocd-jurisdiction/country:ca/csd:2466097/council', # Pointe-Claire