PublicaMundi / ckanext-publicamundi

PublicaMundi main CKAN extension
http://publicamundi.eu
Other
13 stars 12 forks source link

Maybe hide field-level tagged values with patched Field methods #200

Open drmalex07 opened 8 years ago

drmalex07 commented 8 years ago

We support several field-level tags (at schema definition), but is both error-prone and difficult to document all these options as tags. Maybe hide them under patched Field methods, so that they are documented as "extended" Field methods.

E.g:

class TagDefinition(object):

    class Tag(object):

        def __init__(self, field):
            self.field = field

        # Provide methods for actual configuration         

        def link_to(self, name):
            self.field.setTaggedValue('links-to', name)

        def format(self, name, opts):
             self.field.setTaggedValue('format:%s' % name, opts) 

    def __init__(self): pass

    def __get__(self, field, fieldtype=None):
        return self.Tag(field)

    def __set__(self, field, value):
        raise AttributeError('Not meant to be set')

# Patch with a config descriptor: Let the monkeys go wild
Field.config = TagDefinition()
class IFoo(Interface):
    # Tag actual fields
    abstract = zope.schema.Text(title=u'Abstract')
    abstract.config.link_to("notes")
    abstract.config.format("markup", {'descend': False})