1 .. -*- coding: utf-8 -*- |
|
2 |
|
3 Views & Templates |
|
4 ================= |
|
5 |
|
6 |
|
7 Look at ``lax/skel/ginco/web/views/basetemplates.py`` and you will |
|
8 find the base templates used to generate HTML for your application. |
|
9 |
|
10 A page is composed as indicated on the schema below: |
|
11 |
|
12 .. image:: images/lax-book.06-main-template-layout.en.png |
|
13 |
|
14 In this section we will go through a couple of the primary templates |
|
15 you must be interested in, that is to say, the HTMLPageHeader, |
|
16 the HTMLPageFooter and the TheMainTemplate. |
|
17 |
|
18 |
|
19 HTMLPageHeader |
|
20 -------------- |
|
21 |
|
22 Let's use a different logo than the default one provided with LAX |
|
23 and customize our header. |
|
24 |
|
25 Change logo |
|
26 ~~~~~~~~~~~ |
|
27 |
|
28 The easiest way to use a different logo is to replace the existing |
|
29 ``logo.png`` in ``myapp/data`` by your prefered icon and refresh. |
|
30 By default all application will look for a ``logo.png`` to be |
|
31 rendered in the logo section. |
|
32 |
|
33 .. image:: images/lax-book.06-main-template-logo.en.png |
|
34 |
|
35 [ADD] |
|
36 customized external_resources in myapp/data cd crih for reference |
|
37 |
|
38 [WRITE ME] |
|
39 ADD how to use external_resources variables used in ginco/web/webconfig.py |
|
40 |
|
41 Customize header |
|
42 ~~~~~~~~~~~~~~~~ |
|
43 |
|
44 Let's now move the search box in the header and remove the login form |
|
45 from the header. We'll show how to move it to the left column of the application. |
|
46 |
|
47 Let's sat we do not want anymore the login menu to be in the header, but we |
|
48 prefer it to be in the left column just below the logo. As the left column is |
|
49 rendered by ``TheMainTemplate``, we will show how to do it in TheMainTemplate_. |
|
50 |
|
51 First, to remove the login menu, we just need to comment out the display of the |
|
52 login component such as follows: :: |
|
53 |
|
54 class MyHTMLPageHeader(HTMLPageHeader): |
|
55 |
|
56 def main_header(self, view): |
|
57 """build the top menu with authentification info and the rql box""" |
|
58 self.w(u'<table id="header"><tr>\n') |
|
59 self.w(u'<td id="firstcolumn">') |
|
60 self.vreg.select_component('logo', self.req, self.rset).dispatch(w=self.w) |
|
61 self.w(u'</td>\n') |
|
62 # appliname and breadcrumbs |
|
63 self.w(u'<td id="headtext">') |
|
64 comp = self.vreg.select_component('appliname', self.req, self.rset) |
|
65 if comp and comp.propval('visible'): |
|
66 comp.dispatch(w=self.w) |
|
67 comp = self.vreg.select_component('breadcrumbs', self.req, self.rset, view=view) |
|
68 if comp and comp.propval('visible'): |
|
69 comp.dispatch(w=self.w, view=view) |
|
70 self.w(u'</td>') |
|
71 # logged user and help |
|
72 #self.w(u'<td>\n') |
|
73 #comp = self.vreg.select_component('loggeduserlink', self.req, self.rset) |
|
74 #comp.dispatch(w=self.w) |
|
75 #self.w(u'</td><td>') |
|
76 |
|
77 self.w(u'<td>') |
|
78 helpcomp = self.vreg.select_component('help', self.req, self.rset) |
|
79 if helpcomp: # may not be available if Card is not defined in the schema |
|
80 helpcomp.dispatch(w=self.w) |
|
81 self.w(u'</td>') |
|
82 # lastcolumn |
|
83 self.w(u'<td id="lastcolumn">') |
|
84 self.w(u'</td>\n') |
|
85 self.w(u'</tr></table>\n') |
|
86 self.template('logform', rset=self.rset, id='popupLoginBox', klass='hidden', |
|
87 title=False, message=False) |
|
88 |
|
89 |
|
90 |
|
91 .. image:: images/lax-book.06-header-no-login.en.png |
|
92 |
|
93 Let's now move the search box in the top-right header area. To do so, we will |
|
94 first create a method to get the search box display and insert it in the header |
|
95 table. |
|
96 |
|
97 :: |
|
98 |
|
99 from ginco.web.views.basetemplates import HTMLPageHeader |
|
100 class MyHTMLPageHeader(HTMLPageHeader): |
|
101 def main_header(self, view): |
|
102 """build the top menu with authentification info and the rql box""" |
|
103 self.w(u'<table id="header"><tr>\n') |
|
104 self.w(u'<td id="firstcolumn">') |
|
105 self.vreg.select_component('logo', self.req, self.rset).dispatch(w=self.w) |
|
106 self.w(u'</td>\n') |
|
107 # appliname and breadcrumbs |
|
108 self.w(u'<td id="headtext">') |
|
109 comp = self.vreg.select_component('appliname', self.req, self.rset) |
|
110 if comp and comp.propval('visible'): |
|
111 comp.dispatch(w=self.w) |
|
112 comp = self.vreg.select_component('breadcrumbs', self.req, self.rset, view=view) |
|
113 if comp and comp.propval('visible'): |
|
114 comp.dispatch(w=self.w, view=view) |
|
115 self.w(u'</td>') |
|
116 |
|
117 # logged user and help |
|
118 #self.w(u'<td>\n') |
|
119 #comp = self.vreg.select_component('loggeduserlink', self.req, self.rset) |
|
120 #comp.dispatch(w=self.w) |
|
121 #self.w(u'</td><td>') |
|
122 |
|
123 # search box |
|
124 self.w(u'<td>') |
|
125 self.get_searchbox(view, 'left') |
|
126 self.w(u'</td>') |
|
127 |
|
128 self.w(u'<td>') |
|
129 helpcomp = self.vreg.select_component('help', self.req, self.rset) |
|
130 if helpcomp: # may not be available if Card is not defined in the schema |
|
131 helpcomp.dispatch(w=self.w) |
|
132 self.w(u'</td>') |
|
133 # lastcolumn |
|
134 self.w(u'<td id="lastcolumn">') |
|
135 self.w(u'</td>\n') |
|
136 self.w(u'</tr></table>\n') |
|
137 self.template('logform', rset=self.rset, id='popupLoginBox', klass='hidden', |
|
138 title=False, message=False) |
|
139 |
|
140 def get_searchbox(self, view, context): |
|
141 boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset, |
|
142 view=view, context=context)) |
|
143 if boxes: |
|
144 for box in boxes: |
|
145 if box.id == 'search_box': |
|
146 box.dispatch(w=self.w, view=view) |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 HTMLPageFooter |
|
152 -------------- |
|
153 |
|
154 If you want to change the footer for example, look |
|
155 for HTMLPageFooter and override it in your views file as in: |
|
156 :: |
|
157 |
|
158 form ginco.web.views.basetemplates import HTMLPageFooter |
|
159 class MyHTMLPageFooter(HTMLPageFooter): |
|
160 def call(self, **kwargs): |
|
161 self.w(u'<div class="footer">') |
|
162 self.w(u'This website has been created with <a href="http://lax.logilab.org">LAX</a>.') |
|
163 self.w(u'</div>') |
|
164 |
|
165 Updating a view does not require any restart of the server. By reloading |
|
166 the page you can see your new page footer. |
|
167 |
|
168 |
|
169 TheMainTemplate |
|
170 --------------- |
|
171 .. _TheMainTemplate: |
|
172 |
|
173 The MainTemplate is a bit complex as it tries to accomodate many |
|
174 different cases. We are now about to go through it and cutomize entirely |
|
175 our application. |
|
176 |
|
177 TheMainTemplate is responsible for the general layout of the entire application. |
|
178 It defines the template of ``id = main`` that is used by the application. Is |
|
179 also defined in ``ginco/web/views/basetemplates.py`` another template that can |
|
180 be used based on TheMainTemplate called SimpleMainTemplate which does not have |
|
181 a top section. |
|
182 |
|
183 .. image:: images/lax-book.06-simple-main-template.en.png |
|
184 |
|
185 CSS changes |
|
186 ----------- |
|
187 |
|
188 We cannot modify the order in which the application is reading the CSS. In |
|
189 the case we want to create new CSS style, the best is to define it a in a new |
|
190 CSS located under ``myapp/data/``. |
|
191 |
|
192 If you want to modify an existing CSS styling property, you will have to use |
|
193 ``!important`` declaration to override the existing property. The application |
|
194 apply a higher priority on the default CSS and you can not change that. |
|
195 Customized CSS will not be read first. |
|
196 |
|
197 1 |
|
198 [TODO] |
|
199 Add login menu in left column |
|
200 |
|
201 |
|
202 [WRITE ME] |
|
203 |
|
204 * customize MainTemplate and show that everything in the user |
|
205 interface can be changed |
|
206 |
|
207 [TODO] |
|
208 Rajouter une section pour definir la terminologie utilisee. |
|
209 Dans ginco-doc rajouter une section pour erudi-ctl shell ou |
|
210 on liste les commandes dispos. |
|