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 UserInfoSchema(colander.MappingSchema): """Data structure for information about the proposal submitter.""" personal_name = SingleLine(missing=colander.required) family_name = SingleLine() country = ISOCountryCode()
def inst(self): from adhocracy_core.schema import ISOCountryCode return ISOCountryCode()