def hasDependents(self, item): # We cannot adapt security-proxied objects to IDependable. Unwrapping # is safe since we do not modify anything, and the information whether # an object can be deleted or not is not classified. unwrapped_context = removeSecurityProxy(item) dependable = IDependable(unwrapped_context, None) if dependable is None: return False else: return bool(dependable.dependents())
def CheckDependency(event): object = event.object dependency = IDependable(object, None) if dependency is not None: dependents = dependency.dependents() if dependents: mapping = { "object": zapi.getPath(object), "dependents": ", ".join(dependents) } raise DependencyError(Message(exception_msg, mapping=mapping))
def demographics(self): pos = 0 result = [] for demo in self.context.values(): dependable = IDependable(removeSecurityProxy(demo), None) removable = dependable is None or not dependable.dependents() pos += 1 result.append({ 'name': demo.__name__, 'title': demo.title, 'pos': pos, 'removable': removable, }) return result
def has_dependents(self): """Check whether an object has dependents (via IDependable). Objects that have dependents cannot be removed from the system. Sample usage in a page template: <input type="checkbox" name="delete" tal:attributes="disabled obj/schooltool:has_dependents" /> """ # We cannot adapt security-proxied objects to IDependable. Unwrapping # is safe since we do not modify anything, and the information whether # an object can be deleted or not is not classified. unwrapped_context = removeSecurityProxy(self.context) dependable = IDependable(unwrapped_context, None) if dependable is None: return False else: return bool(dependable.dependents())
def render(self, *args, **kw): unwrapped = removeSecurityProxy(self.context) dependable = IDependable(unwrapped, None) if dependable is None or not bool(dependable.dependents()): return super(GroupDeleteLink, self).render(*args, **kw)
def render(self, *args, **kw): dep = IDependable(removeSecurityProxy(self.context), None) if (dep is not None and dep.dependents()): return '' return flourish.page.ModalFormLinkViewlet.render(self, *args, **kw)