def can_add_anonymized(self, context: object, request: Request) -> bool: """Check if children can be created/added anonymized to `context`.""" if IItem.providedBy(context): # if item was anonymized you can also add versions anonymized is_allowed = is_created_anonymized(context) else: is_allowed = IAllowAddAnonymized.providedBy(context) has_permission = request.has_permission(ANONYMIZE_PERMISSION, context) return is_allowed and has_permission
def _only_version_zero_exists(self, context: object, meta: ResourceMetadata) -> bool: only_first_version = False is_item_version = meta.iresource.isOrExtends(IItemVersion) has_item_parent = IItem.providedBy(context) if has_item_parent and is_item_version: children = context.values() versions = [x for x in children if IItemVersion.providedBy(x)] only_first_version = len(versions) == 1 return only_first_version
def _get_title(context: IResource, registry: Registry) -> str: from adhocracy_core.sheets.comment import IComment if IItem.providedBy(context): context = registry.content.get_sheet_field(context, ITags, 'LAST') if ITitle.providedBy(context): name = registry.content.get_sheet_field(context, ITitle, 'title') elif IComment.providedBy(context): name = registry.content.get_sheet_field(context, IComment, 'content') else: name = '' return name
def build_post_response(self, resource) -> dict: """Build response data structure for a POST request. """ appstruct = {} if IItem.providedBy(resource): appstruct["first_version_path"] = self._get_first_version(resource) schema = ItemResponseSchema().bind(request=self.request, context=resource) else: schema = ResourceResponseSchema().bind(request=self.request, context=resource) if not is_batchmode(self.request): appstruct["updated_resources"] = self._build_updated_resources_dict() return schema.serialize(appstruct)
def build_post_response(self, resource) -> dict: """Build response data structure for a POST request. """ appstruct = {} if IItem.providedBy(resource): appstruct['first_version_path'] = self._get_first_version(resource) schema = ItemResponseSchema().bind(request=self.request, context=resource) else: schema = ResourceResponseSchema().bind(request=self.request, context=resource) if not is_batchmode(self.request): appstruct[ 'updated_resources'] = self._build_updated_resources_dict() return schema.serialize(appstruct)
def build_post_response(self, resource) -> dict: """Build response data structure for a POST request.""" appstruct = {} if IItem.providedBy(resource): first = get_sheet_field(resource, ITags, 'FIRST', registry=self.registry) appstruct['first_version_path'] = first schema = ItemResponseSchema().bind(request=self.request, context=resource) else: schema = ResourceResponseSchema().bind(request=self.request, context=resource) if not is_batchmode(self.request): appstruct[ 'updated_resources'] = self._build_updated_resources_dict() return schema.serialize(appstruct)
def build_post_response(self, resource) -> dict: """Build response data structure for a POST request.""" appstruct = {} if IItem.providedBy(resource): first = self.registry.content.get_sheet_field(resource, ITags, 'FIRST') appstruct['first_version_path'] = first schema = create_schema(ItemResponseSchema, resource, self.request) else: schema = create_schema(ResourceResponseSchema, resource, self.request) if not is_batchmode(self.request): updated = _build_updated_resources_dict(self.registry) appstruct['updated_resources'] = updated return schema.serialize(appstruct)
def _get_first_version(self, item: IItem) -> IItemVersion: for child in item.values(): if IItemVersion.providedBy(child): return child