Add a new workflow field called internal_name for easier workflow reference in document index templates. Generalize the PropertyHelper class. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from common.classes import PropertyHelper
|
|
|
|
|
|
class DocumentMetadataHelper(PropertyHelper):
|
|
@staticmethod
|
|
@property
|
|
def constructor(*args, **kwargs):
|
|
return DocumentMetadataHelper(*args, **kwargs)
|
|
|
|
def get_result(self, name):
|
|
return self.instance.metadata.get(metadata_type__name=name).value
|
|
|
|
|
|
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)
|