Ignore:
Timestamp:
23 Apr 2011, 01:46:57 (14 years ago)
Author:
uli
Message:

Replace themes source by themes vocabulary. It looks like this is much easier to handle in the long run.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r5967 r5968  
    1414from waeup.sirp.permissions import RoleSource
    1515
    16 class IThemesProvider(Interface):
    17     """A component that delivers all themes defined.
    18 
    19     We normally do not deal with browser-related stuff in `waeup.sirp`
    20     but leave that to the `browser` subpackage. With themes (aka
    21     skins) we cannot follow that path because we need a theme as an
    22     attribute of each `University` instance.
    23 
    24     Therefore we must tell the browser subpackage how we expect themes
    25     to be announced code-wise.
    26 
    27     What we tell here is that we might ask for a utility providing
    28     IThemeProvider and that this component then should be callable to
    29     give us a list of themes and their respective internal names.
    30     """
    31     def __call__():
    32         """Get a list of all themes available.
    33 
    34         Returns a list of ``(<NAME>, <THEME>)`` tuples where
    35         ``<NAME>`` is the internal name under which a theme was
    36         registered and ``<THEME>`` is the real theme.
    37 
    38         Each <THEME> must have a `description` attribute.
    39         """
    40 
    41 class ThemesSource(BasicSourceFactory):
    42     """A source for themes.
    43     """
    44     def getValues(self):
    45         """Get names of themes.
    46         """
    47         themes_provider = getUtility(IThemesProvider, name="default")
    48         return [x for x, y in themes_provider()]
    49    
    50     def getTitle(self, value):
    51         """Get a user-presentable description for a theme.
    52         """
    53         themes_provider = getUtility(IThemesProvider, name="default")
    54         for name, theme in themes_provider():
    55             if name == value:
    56                 return theme.description
    57         return u'unnamed'
    58 
    59 class ThemesSourceBinder(object):
    60     """A source binder for the `ThemeSource`.
    61 
    62     Normally, we can pass instances of a source (like `ThemeSource`)
    63     directly to fields in interfaces (writing something like ``source
    64     = ThemeSource()``. With `ThemeSource` we cannot do this, because
    65     the set of available themes is not available before the whole
    66     `waeup.sirp` package was grokked (and parsed).
    67 
    68     We bypass that problem by defining this trivial source-binder,
    69     which is asked for themes only when the values of the source are
    70     really needed and after the process of grokking and parsing
    71     everything on startup.
    72 
    73     So, although this binder binds to some context (`IUniversity` is
    74     currently the only interface making use of this source, so
    75     `University` instances are the only context used), the context
    76     does not really matter.
    77     """
    78     implements(schema.interfaces.IContextSourceBinder)
    79 
    80     def __call__(self, context):
    81         return ThemesSource()
    8216
    8317class FatalCSVError(Exception):
     
    9226    return SimpleVocabulary([
    9327            SimpleTerm(value, value, title) for title, value in terms])
    94 
    9528
    9629class IWAeUPObject(Interface):
     
    11346        title = u'Skin',
    11447        default = u'waeuptheme-gray1.css',
    115         source = ThemesSourceBinder(),
     48        vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary',
    11649        required = True,
    11750        )
Note: See TracChangeset for help on using the changeset viewer.