Changeset 5968 for main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py
- Timestamp:
- 23 Apr 2011, 01:46:57 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py
r5967 r5968 14 14 from waeup.sirp.permissions import RoleSource 15 15 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 (aka21 skins) we cannot follow that path because we need a theme as an22 attribute of each `University` instance.23 24 Therefore we must tell the browser subpackage how we expect themes25 to be announced code-wise.26 27 What we tell here is that we might ask for a utility providing28 IThemeProvider and that this component then should be callable to29 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 where35 ``<NAME>`` is the internal name under which a theme was36 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.description57 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 ``source64 = ThemeSource()``. With `ThemeSource` we cannot do this, because65 the set of available themes is not available before the whole66 `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 are70 really needed and after the process of grokking and parsing71 everything on startup.72 73 So, although this binder binds to some context (`IUniversity` is74 currently the only interface making use of this source, so75 `University` instances are the only context used), the context76 does not really matter.77 """78 implements(schema.interfaces.IContextSourceBinder)79 80 def __call__(self, context):81 return ThemesSource()82 16 83 17 class FatalCSVError(Exception): … … 92 26 return SimpleVocabulary([ 93 27 SimpleTerm(value, value, title) for title, value in terms]) 94 95 28 96 29 class IWAeUPObject(Interface): … … 113 46 title = u'Skin', 114 47 default = u'waeuptheme-gray1.css', 115 source = ThemesSourceBinder(),48 vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary', 116 49 required = True, 117 50 )
Note: See TracChangeset for help on using the changeset viewer.