Add configuration for ignored fields.
[infos-pratiques:etalage.git] / etalage / templates / poi.mako
1 ## -*- coding: utf-8 -*-
2
3
4 ## Etalage -- Open Data POIs portal
5 ## By: Emmanuel Raviart <eraviart@easter-eggs.com>
6 ##
7 ## Copyright (C) 2011, 2012 Easter-eggs
8 ## http://gitorious.org/infos-pratiques/etalage
9 ##
10 ## This file is part of Etalage.
11 ##
12 ## Etalage is free software; you can redistribute it and/or modify
13 ## it under the terms of the GNU Affero General Public License as
14 ## published by the Free Software Foundation, either version 3 of the
15 ## License, or (at your option) any later version.
16 ##
17 ## Etalage is distributed in the hope that it will be useful,
18 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ## GNU Affero General Public License for more details.
21 ##
22 ## You should have received a copy of the GNU Affero General Public License
23 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
25
26 <%!
27 import urlparse
28
29 import markupsafe
30 from biryani import strings
31
32 from etalage import conf, model, ramdb, urls
33 %>\
34
35
36 <%inherit file="/site.mako"/>
37
38
39 <%def name="container_content()" filter="trim">
40         <h2>${poi.name}</h2>
41     % for field in (poi.fields or []):
42 <%
43         if conf['ignored_fields'] is not None and field.id in conf['ignored_fields']:
44             ignored_field = conf['ignored_fields'][field.id]
45             if ignored_field is None:
46                 # Always ignore a field with this ID>
47                 continue
48             if strings.slugify(field.label) in ignored_field:
49                 # Ignore a field with this ID and this label
50                 continue
51 %>\
52         <%self:field field="${field}"/>
53     % endfor
54 <%
55     services = sorted(
56         (
57             service
58             for service in ramdb.pois_by_id.itervalues()
59             if service.parent_id == poi._id
60             ),
61         key = lambda service: service.name,
62         )
63 %>\
64     % if services:
65         <h3>Services</h3>
66         <ul>
67         % for service in services:
68             <li>
69                 <a class="field-value internal" href="${urls.get_url(ctx, 'organismes', service.slug, service._id
70                         )}">${service.name}</a>
71             </li>
72         % endfor
73         </ul>
74     %endif
75 <%
76     field = model.Field(id = 'text-inline', label = u"Dernière mise à jour", value = u' par '.join(
77         unicode(fragment)
78         for fragment in (
79             poi.last_update_datetime.strftime('%Y-%m-%d %H:%M') if poi.last_update_datetime is not None else None,
80             poi.last_update_organization,
81             )
82         if fragment
83         ))
84 %>\
85         <%self:field field="${field}"/>
86 </%def>
87
88
89 <%def name="css()" filter="trim">
90     <%parent:css/>
91     <link rel="stylesheet" href="${conf['leaflet.css']}">
92 <!--[if lte IE 8]>
93     <link rel="stylesheet" href="${conf['leaflet.ie.css']}">
94 <![endif]-->
95 </%def>
96
97
98 <%def name="field(field)" filter="trim">
99 <%
100     if field.value is None:
101         return ''
102 %>\
103         <div class="field">
104             <b class="field-label">${field.label} :</b>
105             <%self:field_value field="${field}"/>
106         </div>
107 </%def>
108
109
110 <%def name="field_value(field)" filter="trim">
111 <%
112     if field.value is None:
113         return ''
114 %>\
115     % if field.id == 'adr':
116             <address class="field-value offset1">
117         % for subfield in field.value:
118 <%
119             if subfield.value is None:
120                 continue
121 %>\
122             % if subfield.id == 'street-address':
123                 % for line in subfield.value.split('\n'):
124                 ${line}<br>
125                 % endfor
126             % elif subfield.id == 'commune':
127 <%
128                 continue
129 %>\
130             % elif subfield.id == 'postal-distribution':
131                 ${subfield.value}
132             % endif
133         % endfor
134             </address>
135     % elif field.id in ('autocompleter', 'select'):
136 <%
137         slug_and_name_couples = []
138         name = field.value
139         slug = strings.slugify(name)
140         category = ramdb.categories_by_slug.get(slug)
141         if category is not None:
142             name = category.name
143 %>\
144             <span class="field-value">${name}</span>
145     % elif field.id in ('autocompleters', 'checkboxes'):
146 <%
147         slug_and_name_couples = []
148         for name in field.value:
149             slug = strings.slugify(name)
150             category = ramdb.categories_by_slug.get(slug)
151             if category is not None:
152                 name = category.name
153             slug_and_name_couples.append((slug, name))
154         slug_and_name_couples.sort()
155         names = [
156             name
157             for slug, name in slug_and_name_couples
158             ]
159 %>\
160             <span class="field-value">${u', '.join(names)}</span>
161     % elif field.id == 'boolean':
162             <span class="field-value">${u'Oui' if field.value and field.value != '0' else u'Non'}</span>
163     % elif field.id == 'date-range':
164 <%
165         begin_field = field.get_first_field('date-range-begin')
166         begin = begin_field.value if field is not None else None
167         end_field = field.get_first_field('date-range-end')
168         end = end_field.value if field is not None else None
169 %>\
170         % if begin is None:
171             <span class="field-value">Jusqu'au ${end.strftime('%d/%m/%Y')}</span>
172         % elif end is None:
173             <span class="field-value">À partir du ${begin.strftime('%d/%m/%Y')}</span>
174         % elif begin == end:
175             <span class="field-value">Le ${begin.strftime('%d/%m/%Y')}</span>
176         % else:
177             <span class="field-value">Du ${begin.strftime('%d/%m/%Y')} au ${end.strftime('%d/%m/%Y')}</span>
178         % endif
179     % elif field.id == 'email':
180             <span class="field-value"><a href="mailto:${field.value}">${field.value}</a></span>
181     % elif field.id == 'feed':
182             <div class="field-value offset1">
183 <%
184         import feedparser
185         d = feedparser.parse(field.value)
186 %>\
187         % if d is None or 'status' not in d \
188             or not d.version and d.status != 304 and d.status != 401 \
189             or d.status >= 400:
190                 <em class="error">Erreur dans le flux d'actualité <a href="${field.value}" rel="external">${field.value}</a></em>
191         % else:
192                 <strong>${d.feed.title}</strong>
193                 <a href="${field.value}" rel="external"><img alt="" src="http://cdn.comarquage.fr/images/misc/feed.png"></a>
194         % endif
195                 <ul>
196         % for entry in d.entries[:10]:
197                     <li class="feed-entry">${entry.title | n}
198             % for content in entry.content:
199                         <div>${content.value | n}</div>
200             % endfor
201                     </li>
202         % endfor
203         % if len(d.entries) > 10:
204                     <li>...</li>
205         % endif
206                 </ul>
207             </div>
208     % elif field.id == 'geo':
209             <div class="field-value offset1">
210         % if field.value[2] <= 6:
211                 <div class="alert alert-error">
212                     Cet organisme est positionné <strong>très approximativement</strong>.
213                 </div>
214         % elif field.value[2] <= 6:
215                 <div class="alert alert-warning">
216                     Cet organisme est positionné <strong>approximativement dans la rue</strong>.
217                 </div>
218         % endif
219                 <div class="single-marker-map" id="map-poi" style="height: 500px;"></div>
220                 <script>
221 etalage.map.singleMarkerMap("map-poi", ${field.value[0]}, ${field.value[1]});
222                 </script>
223                 <div class="bigger-map-link">
224                     Voir sur une carte plus grande avec
225                     <a href="${u'http://www.openstreetmap.org/?mlat={0}&mlon={1}&zoom=15&layers=M'.format(
226                             field.value[0], field.value[1])}" rel="external">OpenStreetMap</a>
227                     ou
228                     <a href="${u'http://maps.google.com/maps?q={0},{1}'.format(field.value[0], field.value[1]
229                             )}" rel="external">Google Maps</a>
230                 </div>
231             </div>
232     % elif field.id == 'image':
233             <div class="field-value offset1"><img alt="" src="${field.value}"></div>
234     % elif field.id == 'link':
235 <%
236         target = ramdb.pois_by_id.get(field.value)
237 %>\
238         % if target is None:
239             <em class="field-value">Lien manquant</em>
240         % else:
241             <a class="field-value internal" href="${urls.get_url(ctx, 'organismes', target.slug, target._id
242                     )}">${target.name}</a>
243         % endif
244     % elif field.id == 'links':
245         % if len(field.value) == 1:
246 <%
247             single_field = model.Field(id = 'link', value = field.value[0])
248 %>\
249 <%self:field_value field="${single_field}"/>
250         % else:
251             <ul class="field-value">
252             % for target_id in field.value:
253 <%
254                 target = ramdb.pois_by_id.get(target_id)
255                 if target is None:
256                     continue
257 %>\
258                 <li><a class="internal" href="${urls.get_url(ctx, 'organismes', target.slug, target._id
259                         )}">${target.name}</a></li>
260             % endfor
261             </ul>
262         % endif
263     % elif field.id == 'organism-type':
264 <%
265     category_slug = ramdb.categories_slug_by_pivot_code.get(field.value)
266     category = ramdb.categories_by_slug.get(category_slug) if category_slug is not None else None
267     category_name = category.name if category is not None else field.value
268 %>\
269             <span class="field-value">${category_name}</span>
270     % elif field.id == 'source':
271             <div class="field-value offset1">
272         % for subfield in field.value:
273         <%self:field field="${subfield}"/>
274         % endfor
275             </div>
276     % elif field.id == 'tags':
277 <%
278     tags_name = [
279         tag.name
280         for tag in (
281             ramdb.categories_by_slug.get(tag_slug)
282             for tag_slug in sorted(field.value)
283             )
284         if tag is not None
285         ]
286 %>\
287             <span class="field-value">${u', '.join(tags_name)}</span>
288     % elif field.id == 'territories':
289 <%
290         territories_title_markup = [
291             territory.main_postal_distribution_str
292                 if territory.__class__.__name__ in model.communes_kinds
293                 else markupsafe.Markup(u'{0} <em>({1})</em>').format(
294                     territory.main_postal_distribution_str, territory.type_short_name_fr)
295             for territory in (
296                 ramdb.territories_by_id[territory_id]
297                 for territory_id in field.value
298                 )
299             if territory is not None
300             ]
301 %>\
302         % if territories_title_markup:
303             % if len(territories_title_markup) == 1:
304             <span class="field-value">${territories_title_markup[0] | n}</span>
305             % else:
306             <ul class="field-value">
307                 % for territory_title_markup in territories_title_markup:
308                 <li>${territory_title_markup | n}</li>
309                 % endfor
310             </ul>
311             % endif
312         % endif
313     % elif field.id == 'text-block':
314             <div class="field-value offset1">${markupsafe.Markup('<br>').join(field.value.split('\n'))}</div>
315     % elif field.id == 'text-rich':
316             <div class="field-value offset1">${field.value | n}</div>
317     % elif field.id in ('source-url', 'url'):
318             <a class="field-value" href="${field.value}" rel="external">${field.value}</a>
319     % else:
320 <%
321         if field.id not in ('fax', 'name', 'org', 'source-organization', 'tel', 'text-inline'):
322             print 'Unknown ID for field {0}'.format(field)
323 %>\
324             <span class="field-value">${field.value}</span>
325     % endif
326 </%def>
327
328
329 <%def name="footer_data_p_content()" filter="trim">
330 ${parent.footer_data_p_content()}\
331     % if conf.get('petitpois_url'):
332  &mdash; <a class="label notice" href="${urlparse.urljoin(conf['petitpois_url'], '/poi/view/{0}'.format(poi._id)
333         )}" rel="external">Modifier la fiche</a>\
334     % endif
335  &mdash; <a class="internal" href="${urls.get_url(
336         ctx, 'minisite', 'organismes', poi.slug, poi._id)}" rel="nofollow">Minisite</a>
337 </%def>
338
339
340 <%def name="scripts()" filter="trim">
341     <%parent:scripts/>
342     <script src="${conf['leaflet.js']}"></script>
343 <!--[if lt IE 10]>
344     <script src="${conf['pie.js']}"></script>
345 <![endif]-->
346     <script src="/js/map.js"></script>
347     <script>
348 var etalage = etalage || {};
349 etalage.map.markersUrl = ${conf['markers_url'].rstrip('/') | n, js};
350 etalage.map.tileUrlTemplate = ${conf['tile_url_template'] | n, js};
351     </script>
352 </%def>
353
354
355 <%def name="title_content()" filter="trim">
356 ${poi.name} - ${parent.title_content()}
357 </%def>
358