class MetadataSchema(colander.MappingSchema): """Metadata sheet data structure. `creation_date`: Creation date of this resource. defaults to now. `item_creation_date`: Equals creation date for ISimple/IPool, equals the item creation date for :class:`adhocracy_core.interfaces.IItemVersion`. This exists to ease the frontend end development. This may go away if we have a high level API to make :class:`adhocracy_core.interfaces.Item` / `IItemVersion` one `thing`. Defaults to now. `creator`: creator (user resource) of this resource. `modified_by`: the last person (user resources) who modified a resource, initially the creator `modification_date`: Modification date of this resource. defaults to now. `deleted`: whether the resource is marked as deleted (only shown to those that specifically ask for it) `hidden`: whether the resource is marked as hidden (only shown to those that have special permissions and ask for it) """ creator = Reference(reftype=MetadataCreatorsReference, readonly=True) creation_date = DateTime(missing=colander.drop, readonly=True) item_creation_date = DateTime(missing=colander.drop, readonly=True) modified_by = Reference(reftype=MetadataModifiedByReference, readonly=True) modification_date = DateTime(missing=colander.drop, readonly=True) deleted = Boolean() hidden = Boolean(validator=deferred_validate_hidden)
class ProcessSettingsSchema(colander.MappingSchema): """Settings for the B-Plan process.""" office_worker = Reference(reftype=OfficeWorkerUserReference) plan_number = SingleLine(missing=colander.required) participation_kind = SingleLine(missing=colander.required) participation_start_date = DateTime(default=None) participation_end_date = DateTime(default=None)
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 BlockExplanationResponseSchema(colander.Schema): """Data structure explaining a 410 Gone response.""" reason = SingleLine() modified_by = Reference() modification_date = DateTime(default=colander.null)
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 StateData(MappingSchema): """Resource specific data for a workflow state.""" missing = drop default = None name = StateName() description = Text(missing='', default='') start_date = DateTime(missing=None, default=None)
class ActivitySchema(MappingSchema): """Activity entry.""" subject = Reference(reftype=SubjectReference) type = SingleLine(validator=OneOf( [activity_type.value for activity_type in ActivityType])) object = Reference(reftype=ObjectReference) target = Reference(reftype=TargetReference) name = SingleLine() published = DateTime()
def make_one(self, **kwargs): from adhocracy_core.schema import DateTime return DateTime(**kwargs)
def create_arbitrary_filter_node(index, example_value, query): return DateTime()
class FieldComparableDateTime(FieldComparableBase): """Tuple with values FieldComparable and DateTime.""" value = DateTime()
class KeywordComparableDateTime(KeywordComparableBase): """Tuple with values KeywordComparable and DateTime.""" value = DateTime()