• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 29. Registries with Global Utili... > Step 4: Providing a User-Friendly UI

Step 4: Providing a User-Friendly UI

Although the current API is functional, it is not very practical to the developer because he or she first needs to look up the theme by using the component architecture's utility API, and only then can the developer make use of the smiley theme features. It would be much nicer if you had only a smiley-theme-related API to work with. Thus, you can create some convenience functions in the package's __init__.py file:

01 from zope.app import zapi
02
03 from interfaces import ISmileyTheme
04
05 def getSmiley(text, request, theme='default'):
06     theme = zapi.getUtility(ISmileyTheme, theme)
07     return theme.getSmiley(text, request)
08
09 def querySmiley(text, request, theme='default', default=None):
10     theme = zapi.queryUtility(ISmileyTheme, theme)
11     if theme is None:
12         return default
13     return theme.querySmiley(text, request, default)
14
15 def getSmileyThemes():
16     return [name for name, util in zapi.getUtilitiesFor(ISmileyTheme)
17             if name != 'default']
18
19 def getSmileysMapping(request, theme='default'):
20     theme = zapi.getUtility(ISmileyTheme, theme)
21     return theme.getSmileysMapping(request)


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint