"""Resource base implementation with zodb persistence."""
from persistent import Persistent
from zope.interface import implementer
from BTrees.Length import Length
from adhocracy_core.interfaces import IResource
from adhocracy_core.utils import get_iresource
from adhocracy_core.utils import to_dotted_name
@implementer(IResource)
[docs]class Base(Persistent):
"""Persistent and location aware class."""
__parent__ = None
__name__ = None
def __init__(self):
"""Initialize self."""
self.__changed_backrefs_counter__ = Length()
"""Counter that should increment if backreferences are changed."""
def __repr__(self):
"""Return representation of self."""
iface = get_iresource(self) or self.__class__
iface_dotted = to_dotted_name(iface)
oid = getattr(self, '__oid__', None)
name = getattr(self, '__name__', None)
identifier = str(oid)
return '{0} oid: {1} name: {2}'.format(iface_dotted, identifier, name)