Refactor the accesors to behave like methods instead of properties. This means all accesors will be prepended with the string "get_" and will include a set of parenthesis. Improve the ModeAttribute class to use the method's short_description. This commit also adds support for a new method .help_text attribute has been added. Move accessors to their own module, named "methods.py". Remove the PropertyHelper class as the accessors no longer need it. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
33 lines
809 B
Python
33 lines
809 B
Python
from __future__ import unicode_literals
|
|
|
|
|
|
class MetadataLookup(object):
|
|
_registry = []
|
|
|
|
@classmethod
|
|
def get_as_context(cls):
|
|
result = {}
|
|
for entry in cls._registry:
|
|
try:
|
|
result[entry.name] = entry.value()
|
|
except TypeError:
|
|
result[entry.name] = entry.value
|
|
|
|
return result
|
|
|
|
@classmethod
|
|
def get_as_help_text(cls):
|
|
result = []
|
|
for entry in cls._registry:
|
|
result.append(
|
|
'{{{{ {0} }}}} = "{1}"'.format(entry.name, entry.description)
|
|
)
|
|
|
|
return ' '.join(result)
|
|
|
|
def __init__(self, description, name, value):
|
|
self.description = description
|
|
self.name = name
|
|
self.value = value
|
|
self.__class__._registry.append(self)
|