Package Camelot :: Package camelot :: Package admin :: Module section
[frames] | no frames]

Source Code for Module Camelot.camelot.admin.section

 1  from camelot.view.model_thread import model_function 
 2  from camelot.core.utils import ugettext_lazy as _ 
3 4 -class Section(object):
5 """A Section as displayed in the left pane of the application. Each Section 6 contains a list of SectionItems the user can click on. Sections should be used 7 in the definition of the ApplicationAdmin. 8 9 class MyApplicationAdmin(ApplicationAdmin): 10 sections = [Section('configuration')] 11 12 .. image:: ../_static/configuration_section.png 13 14 """ 15
16 - def __init__(self, name, icon=None, items=[], verbose_name=None):
17 self.name = name 18 self.verbose_name = verbose_name 19 self.icon = icon 20 self.items = structure_to_section_items(items)
21
22 - def get_name(self):
23 return self.name
24
25 - def get_verbose_name(self):
26 return self.verbose_name or _(self.name.capitalize())
27
28 - def get_icon(self):
29 from camelot.view.art import Icon 30 return self.icon or Icon('tango/32x32/apps/system-users.png')
31 32 @model_function
33 - def get_items(self):
34 return self.items
35
36 -def structure_to_sections(structure):
37 """Convert a list of python objects to a list of sections, using 38 applying these rules on each of the elements in the list : 39 40 - if the element is a instance of Section, leave it as it is 41 - if the element is an instance of a basestr, construct a Section 42 for it""" 43 44 def rule(element): 45 if isinstance(element, (Section,)): 46 return element 47 else: 48 return Section(element)
49 50 return [rule(section) for section in structure] 51
52 -class SectionItem(object):
53 """An item inside a section, the user can click on and trigger an action 54 """ 55
56 - def __init__(self, action, verbose_name=None):
60
61 - def get_verbose_name(self):
62 return self.verbose_name or self.action.get_verbose_name()
63
64 - def get_action(self):
65 return self.action
66
67 -def structure_to_section_items(structure):
68 69 def rule(element): 70 if isinstance(element, (SectionItem,)): 71 return element 72 return SectionItem(element)
73 74 return [rule(item) for item in structure] 75