class PartnersSchema(MappingSchema): has_partners = Boolean() partner1_name = SingleLine() partner1_website = URL() partner1_country = ISOCountryCode() partner2_name = SingleLine() partner2_website = URL() partner2_country = ISOCountryCode() partner3_name = SingleLine() partner3_website = URL() partner3_country = ISOCountryCode() other_partners = Text()
class OrganizationInfoSchema(colander.MappingSchema): """Data structure for organizational information.""" name = SingleLine() country = ISOCountryCode() status = StatusEnum() status_other = Text(validator=colander.Length(max=500)) """Custom description for status == other.""" website = URL() planned_date = DateTime(missing=colander.drop, default=None) help_request = Text(validator=colander.Length(max=500)) def validator(self, node, value): """Make `status_other` required if `status` == `other`.""" status = value.get('status', None) if status == 'other': if not value.get('status_other', None): status_other = node['status_other'] raise colander.Invalid(status_other, msg='Required iff status == other') else: # TODO: Allow multiple errors at the same time name = node['name'] if not value.get('name', None): raise colander.Invalid(name, msg='Required iff status != other') country = node['country'] if not value.get('country', None): raise colander.Invalid(country, msg='Required iff status != other')
class OrganizationInfoSchema(MappingSchema): """Data structure for organizational information.""" name = SingleLine(missing=drop) validator = OneOf([ 'registered_nonprofit', 'planned_nonprofit', 'support_needed', 'other', ]) city = SingleLine(missing=drop) country = ISOCountryCode(missing=drop) help_request = Text(validator=Length(max=300)) registration_date = DateTime(missing=drop, default=None) website = URL(missing=drop) status = OrganizationStatusEnum(missing=required) status_other = Text(validator=Length(max=300)) def validator(self, node, value): """Extra validation depending on the status of the organisation. Make `status_other` required if `status` == `other` and `help_request` required if `status` == `support_needed`. """ status = value.get('status', None) if status == 'support_needed': if not value.get('help_request', None): help_request = node['help_request'] raise Invalid(help_request, msg='Required iff status == support_needed') elif status == 'other': if not value.get('status_other', None): status_other = node['status_other'] raise Invalid(status_other, msg='Required iff status == other')
class ImageReferenceSchema(MappingSchema): """Data structure for the image reference sheet.""" picture = Reference(reftype=ImageReference, choices_getter=get_asset_choices) picture_description = SingleLine() external_picture_url = URL(validator=All( URL.validator, picture_url_validator, ))
class EmbedSchema(MappingSchema): """Embed sheet data structure. `embed_code`: html code to embed the `context` resource in web pages. `external_url`: canonical URL that embeds the `context` resource. """ embed_code = Text( default=deferred_default_embed_code, widget=TextAreaWidget(rows=10), ) external_url = URL()
def make_one(self): from adhocracy_core.schema import URL return URL()
class POSTReportAbuseViewRequestSchema(MappingSchema): """Schema for abuse reports.""" url = URL(missing=required) remark = Text(missing='')
class POSTReportAbuseViewRequestSchema(colander.Schema): """Schema for abuse reports.""" url = URL(missing=colander.required) remark = Text(missing='')