1 from camelot.view.model_thread import model_function
2 from camelot.core.utils import ugettext_lazy as _
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):
21
24
27
31
32 @model_function
35
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
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
63
66
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