예제 #1
0
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)
예제 #2
0
class PolarizationSchema(MappingSchema):
    """Polarizable sheet data structure.

    `position`: the position in the debate, 'pro' or 'contra'.
    """

    subject = Reference(reftype=PolarizationSubjectReference)
    object = Reference(reftype=PolarizationObjectReference)
    position = Position()
예제 #3
0
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()
예제 #4
0
class BadgeAssignmentSchema(colander.MappingSchema):
    """Badge sheet data structure."""

    subject = Reference(reftype=BadgeSubjectReference)
    badge = Reference(reftype=BadgeReference)
    object = Reference(reftype=BadgeObjectReference)

    @colander.deferred
    def validator(self, kw: dict) -> callable:
        """Validate the :term:`post_pool` for the object reference."""
        object_validator = create_post_pool_validator(self['object'], kw)
        badge_assignment_validator = create_unique_badge_assignment_validator(
            self['badge'], self['object'], kw)
        return colander.All(object_validator, badge_assignment_validator)
예제 #5
0
class BlockExplanationResponseSchema(colander.Schema):

    """Data structure explaining a 410 Gone response."""

    reason = SingleLine()
    modified_by = Reference()
    modification_date = DateTime(default=colander.null)
예제 #6
0
class CanPolarizeSchema(colander.MappingSchema):

    """CanPolarize sheet data structure."""

    polarization = Reference(reftype=PolarizationSubjectReference,
                             backref=True,
                             readonly=True,)
예제 #7
0
class POSTMessageUserViewRequestSchema(colander.Schema):
    """Schema for messages to a user."""

    recipient = Reference(missing=colander.required,
                          reftype=MessageUserReference)
    title = SingleLine(missing=colander.required)
    text = Text(missing=colander.required)
예제 #8
0
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)
예제 #9
0
class CommentSchema(MappingSchema):
    """Comment sheet data structure.

    `content`:  Text
    """

    refers_to = Reference(reftype=CommentRefersToReference)
    content = Text()
예제 #10
0
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,
    ))
예제 #11
0
def _add_reference_node(schema: colander.Schema, target_isheet=None):
    from adhocracy_core.interfaces import ISheet
    from adhocracy_core.interfaces import SheetToSheet
    from adhocracy_core.schema import Reference
    reference_node = Reference(name='reference')
    isheet = target_isheet or ISheet

    class PostPoolReference(SheetToSheet):
        target_isheet = isheet

    schema.add(reference_node)
    schema['reference'].reftype = PostPoolReference
예제 #12
0
    def test_get_reference_without_permission_check(
            self, inst, context, sheet_catalogs, mock_node_single_reference):
        from adhocracy_core.interfaces import ISheet
        from adhocracy_core.interfaces import search_query
        from adhocracy_core.interfaces import Reference
        node = mock_node_single_reference
        inst.schema.children.append(node)

        appstruct = inst.get()

        reference = Reference(context, ISheet, 'reference', None)
        query = search_query._replace(references=[reference],
                                      resolve=True,
                                      allows=(('admin'), 'view')
                                      )
        assert sheet_catalogs.search.call_args[0][0] == query._replace(allows=())
예제 #13
0
    def test_get_back_reference(self, inst, context, sheet_catalogs,
                                mock_node_single_reference):
        from adhocracy_core.interfaces import ISheet
        from adhocracy_core.interfaces import search_result
        from adhocracy_core.interfaces import Reference
        node = mock_node_single_reference
        node.backref = True
        inst.schema.children.append(node)
        source = testing.DummyResource()
        result = search_result._replace(elements=[source])
        sheet_catalogs.search.return_value = result
        appstruct = inst.get()

        reference = Reference(None, ISheet, '', context)
        assert sheet_catalogs.search.call_args[0][0].references == [reference]
        assert appstruct['reference'] == source
예제 #14
0
파일: geo.py 프로젝트: andantic/adhocracy3
class MultiPolygonSchema(colander.MappingSchema):
    """A geographical MultiPolygon object.

    GeoJSON like geometry object fields:

    `type`: 'MultiPolygon' (geometry object type)
    `coordinates`: list of list of list of points with (longitude, latitude).

    Metadata property fields:

    `administrative_level`: administrative division level
    `administrative_division`: administrative division name
    `part_of`: surrounding geographical object
    """

    type = SingleLine(default='MultiPolygon', readonly=True)
    coordinates = MultiPolygon()

    administrative_division = AdministrativeDivisionName()
    part_of = Reference(reftype=PartOfReference)
예제 #15
0
    def test_get_references(self, inst, context, sheet_catalogs,
                            mock_node_unique_references):
        from adhocracy_core.interfaces import ISheet
        from adhocracy_core.interfaces import search_result
        from adhocracy_core.interfaces import search_query
        from adhocracy_core.interfaces import Reference
        node = mock_node_unique_references
        inst.schema.children.append(node)
        target = testing.DummyResource()
        result = search_result._replace(elements=[target])
        sheet_catalogs.search.return_value = result

        appstruct = inst.get()

        reference = Reference(context, ISheet, 'references', None)
        query = search_query._replace(references=[reference],
                                      resolve=True,
                                      sort_by='reference'
                                      )
        assert sheet_catalogs.search.call_args[0][0] == query
예제 #16
0
    def test_get_valid_back_references(self, inst, context, sheet_catalogs,
                                       mock_node_unique_references):
        from adhocracy_core.interfaces import ISheet
        from adhocracy_core.interfaces import search_result
        from adhocracy_core.interfaces import search_query
        from adhocracy_core.interfaces import Reference
        node = mock_node_unique_references
        node.backref = True
        inst.schema.children.append(node)
        source = testing.DummyResource()
        result = search_result._replace(elements=[source])
        sheet_catalogs.search.return_value = result

        appstruct = inst.get()

        reference = Reference(None, ISheet, '', context)
        query = search_query._replace(
            references=[reference],
            resolve=True,
        )
        sheet_catalogs.search.call_args[0] == query
        assert appstruct['references'] == [source]
예제 #17
0
class TagsSchema(MappingSchema):
    """Tags sheet data structure."""

    LAST = Reference(reftype=TagsLastReference)
    FIRST = Reference(reftype=TagsFirstReference)
예제 #18
0
class IntroductionSchema(colander.MappingSchema):
    """Data structure for the proposal introduction."""

    teaser = Text(validator=colander.Length(min=1, max=300))
    picture = Reference(reftype=IntroImageReference)
예제 #19
0
class MercatorSubResourcesSchema(colander.MappingSchema):

    organization_info = Reference(reftype=OrganizationInfoReference)
    introduction = Reference(reftype=IntroductionReference)
    description = Reference(reftype=DescriptionReference)
    location = Reference(reftype=LocationReference)
    story = Reference(reftype=StoryReference)
    outcome = Reference(reftype=OutcomeReference)
    steps = Reference(reftype=StepsReference)
    value = Reference(reftype=ValueReference)
    partners = Reference(reftype=PartnersReference)
    finance = Reference(reftype=FinanceReference)
    experience = Reference(reftype=ExperienceReference)
예제 #20
0
class ImageReferenceSchema(MappingSchema):
    """Data structure for the image reference sheet."""

    picture = Reference(reftype=ImageReference)
예제 #21
0
 def make_one(self, **kwargs):
     from adhocracy_core.schema import Reference
     return Reference(**kwargs)
예제 #22
0
파일: geo.py 프로젝트: andantic/adhocracy3
class LocationReferenceSchema(colander.MappingSchema):
    """Data structure for the location reference sheet."""

    location = Reference(reftype=LocationReference)
예제 #23
0
class MercatorSubResourcesSchema(MappingSchema):
    """Subresources of mercator."""

    pitch = Reference(reftype=PitchReference)
    partners = Reference(reftype=PartnersReference)
    duration = Reference(reftype=DurationReference)
    challenge = Reference(reftype=ChallengeReference)
    goal = Reference(reftype=GoalReference)
    plan = Reference(reftype=PlanReference)
    target = Reference(reftype=TargetReference)
    team = Reference(reftype=TeamReference)
    extrainfo = Reference(reftype=ExtraInfoReference)
    connectioncohesion = Reference(reftype=ConnectionCohesionReference)
    difference = Reference(reftype=DifferenceReference)
    practicalrelevance = Reference(reftype=PracticalRelevanceReference)
예제 #24
0
class LocationReferenceSchema(MappingSchema):
    """Data structure for the location reference sheet."""

    location = Reference(reftype=LocationReference,
                         choices_getter=get_location_choices)