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