Commit ae13572f authored by Pierre Arnaud's avatar Pierre Arnaud

Sort transport_type

parent e81847ab
......@@ -117,4 +117,6 @@ ${parent.page_header()}
</table>
</div>
</div>
% else:
${_("None")}
% endif
......@@ -57,7 +57,9 @@ ${parent.search_bar()}
</td>
<td>
% for offre in multimodal["transport_type"]:
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% if offre != _("None"):
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% endif
% endfor
</td>
</tr>
......@@ -93,7 +95,9 @@ ${parent.search_bar()}
</td>
<td>
% for offre in local["transport_type"]:
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% if offre != _("None"):
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% endif
% endfor
</td>
% endif
......@@ -130,7 +134,9 @@ ${parent.search_bar()}
</td>
<td>
% for offre in departmental["transport_type"]:
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% if offre != _("None"):
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% endif
% endfor
</td>
% endif
......@@ -167,7 +173,9 @@ ${parent.search_bar()}
</td>
<td>
% for offre in regional["transport_type"]:
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% if offre != _("None"):
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% endif
% endfor
</td>
% endif
......@@ -207,7 +215,9 @@ ${parent.search_bar()}
</td>
<td>
% for offre in national["transport_type"]:
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% if offre != _("None"):
<a href="#" rel="tooltip" title="${offre}"><img alt="${offre}" src="${request.static_path('passim:static/img/types-de-transports/' + offre + '.png')}"></a>
% endif
% endfor
</td>
</tr>
......
......@@ -46,6 +46,32 @@ from passim.views.common import parse_last_update
log = logging.getLogger(__name__)
TRANSPORT_MODES = [
u'Transport collectif urbain',
u'Transport collectif départemental',
u'Transport collectif régional',
u'Transport longue distance',
u'Transport à la demande',
u'Transport personnes à mobilité réduite',
u'Transport Scolaire',
u'Navette',
u'Port',
u'Aéroport',
u'Touristique',
u'Transport d''altitude',
u'Réseau fluvial',
u'Vélo-Libre Service',
u'Covoiturage',
u'Autopartage',
u'Réseau routier',
u'Location de Véhicule',
u'Vélo Taxi',
u'Taxi',
u'Stationnement',
u'Circuit touristique',
]
ORDER_TRANSPORT_MODES = dict((slugify(value), index) for index, value in enumerate(TRANSPORT_MODES))
@forbidden_view_config(renderer='/error-403.mako')
def error_403(request):
......@@ -264,8 +290,11 @@ def organisms(request):
transport_logo=", ".join(transport_logo)
)
)
if parse_result.get("transport"):
parse_result["transport"] = sorted(parse_result["transport"], key=lambda k: k['name'])
parse_result["transport"] = sorted(parse_result["transport"], key=lambda v: ORDER_TRANSPORT_MODES.get(slugify(v['transport_type']), 1000))
return dict(
id=id,
result=parse_result,
......@@ -423,6 +452,11 @@ def territories(request):
obj_response["offre"] = list(set_offre)
for transport_type in list(set_type):
obj_response["transport_type"].append(slugify(transport_type))
# Sort by ORDER_TRANSPORT_MODES
obj_response["transport_type"] = sorted(
obj_response["transport_type"],
key=lambda v: ORDER_TRANSPORT_MODES.get(slugify(v), 1000)
)
elif item["label"] == "Nom du service":
obj_response["name"] = item["value"]
elif item["label"] == "Site web - URL":
......@@ -432,6 +466,11 @@ def territories(request):
elif item["label"] == "Territoire couvert":
for territories in item["value"]:
obj_response["territories"].append(territories)
# Use to sort by transport_type to avoid empty obj_response["transport_type"]
if not obj_response["transport_type"]:
obj_response["transport_type"] = [_("None")]
obj_response["id"] = el["id"]
obj_response["internal"] = request.route_path('organisms', name=slugify(obj_response["name"]), id=el["id"])
result.append(obj_response)
......@@ -446,6 +485,8 @@ def territories(request):
)
result = sorted(result, key=lambda k: k['name'])
result = sorted(result, key=lambda v: ORDER_TRANSPORT_MODES.get(v['transport_type'][0], 1000))
for el in result:
territories = el.get('territories', [])
if full_name_and_cp in territories \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment