Commit f3189cf8 authored by Valéry Febvre's avatar Valéry Febvre

Code cleanup

parent 463b08aa
......@@ -93,8 +93,8 @@ def main(global_config, **settings):
config.add_route('acces_donnees', '/acces_donnees') #Apache directory listing
config.add_route('organismes', '/organismes/{name}/{id}')
config.add_route('territoires', '/territoires/{territoires_type}/{id}')
config.add_route('organisms', '/organismes/{name}/{id}')
config.add_route('territories', '/territoires/{type}/{name}')
config.scan('passim.views')
return config.make_wsgi_app()
/*
Autocompleur des territoires
Available territories kinds:
Territoires disponible:
// CommuneOfFrance
// ArrondissementOfCommuneOfFrance
// ArrondissementOfFrance
// AssociatedCommuneOfFrance
// CantonOfFrance
// CantonalFractionOfCommuneOfFrance
// CommuneOfFrance
// Country
// DepartmentOfFrance
// IntercommunalityOfFrance
// InternationalOrganization
// MetropoleOfCountry
// Mountain
// OverseasCollectivityOfFrance
// PaysOfFrance
// RegionOfFrance
// RegionalNatureParkOfFrance
// Special
// UrbanAreaOfFrance
// UrbanTransportsPerimeterOfFrance
CommuneOfFrance
ArrondissementOfCommuneOfFrance
ArrondissementOfFrance
AssociatedCommuneOfFrance
CantonOfFrance
CantonalFractionOfCommuneOfFrance
CommuneOfFrance
Country
DepartmentOfFrance
IntercommunalityOfFrance
InternationalOrganization
MetropoleOfCountry
Mountain
OverseasCollectivityOfFrance
PaysOfFrance
RegionOfFrance
RegionalNatureParkOfFrance
Special
UrbanAreaOfFrance
UrbanTransportsPerimeterOfFrance
*/
......@@ -33,10 +32,10 @@ $("#term").select2({
url: territoria_api +
"autocomplete-territory?" +
"kind=CommuneOfFrance&" +
// "kind=ArrondissementOfCommuneOfFrance&" +
// "kind=AssociatedCommuneOfFrance&" +
//"kind=ArrondissementOfCommuneOfFrance&" +
//"kind=AssociatedCommuneOfFrance&" +
"kind=DepartmentOfFrance&" +
// "kind=IntercommunalityOfFrance&" +
//"kind=IntercommunalityOfFrance&" +
"kind=RegionOfFrance&" +
"jsonp=?",
dataType: 'jsonp',
......
## -*- coding: utf-8 -*-
<%!
import markdown
%>
<%inherit file="/site.mako"/>
<%def name="head()">
${parent.head()}
<link rel="stylesheet" href="http://cdn.comarquage.fr/leaflet/latest/leaflet.css">
<link rel="stylesheet" href="${request.static_path('passim:static/css/maps.css')}">
<link rel="stylesheet" href="http://cdn.comarquage.fr/leaflet/latest/leaflet.css">
<link rel="stylesheet" href="${request.static_path('passim:static/css/maps.css')}">
</%def>
${parent.page_header()}
......@@ -52,8 +48,8 @@ $(function () {
var osmUrl="http://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png";
var osmAttrib=[
'Données cartographiques CC-By-SA ',
'<a href="http://openstreetmap.org/" rel="external">OpenStreetMap<\/a>, ',
'Tuiles fournies par <a href="http://www.opencyclemap.org/" rel="external">Andy Allan<\/a>'
'<a href="http://openstreetmap.org/" target="_blank">OpenStreetMap<\/a>, ',
'Tuiles fournies par <a href="http://www.opencyclemap.org/" target="_blank">Andy Allan<\/a>'
].join('');
var osmLayer = new L.TileLayer(osmUrl, {minZoom: 2, maxZoom: 16, attribution: osmAttrib});
......
## -*- coding: utf-8 -*-
<%!
import markdown
%>
<%inherit file="/site.mako"/>
<%def name="head()">
${parent.head()}
<link rel="stylesheet" href="http://cdn.comarquage.fr/leaflet/latest/leaflet.css">
<link rel="stylesheet" href="${request.static_path('passim:static/css/maps.css')}">
<link rel="stylesheet" href="http://cdn.comarquage.fr/leaflet/latest/leaflet.css">
<link rel="stylesheet" href="${request.static_path('passim:static/css/maps.css')}">
</%def>
${parent.page_header()}
......@@ -41,8 +38,8 @@ $(function () {
var osmUrl="http://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png";
var osmAttrib=[
'Données cartographiques CC-By-SA ',
'<a href="http://openstreetmap.org/" rel="external">OpenStreetMap<\/a>, ',
'Tuiles fournies par <a href="http://www.opencyclemap.org/" rel="external">Andy Allan<\/a>'
'<a href="http://openstreetmap.org/" target="_blank">OpenStreetMap<\/a>, ',
'Tuiles fournies par <a href="http://www.opencyclemap.org/" target="_blank">Andy Allan<\/a>'
].join('');
var osmLayer = new L.TileLayer(osmUrl, {minZoom: 2, maxZoom: 16, attribution: osmAttrib});
......
## -*- coding: utf-8 -*-
<%!
import markdown
%>
<%inherit file="/site.mako"/>
<%def name="head()">
${parent.head()}
<link rel="stylesheet" href="http://cdn.comarquage.fr/leaflet/latest/leaflet.css">
<link rel="stylesheet" href="${request.static_path('passim:static/css/maps.css')}">
<link rel="stylesheet" href="http://cdn.comarquage.fr/leaflet/latest/leaflet.css">
<link rel="stylesheet" href="${request.static_path('passim:static/css/maps.css')}">
</%def>
${parent.page_header()}
......@@ -51,8 +47,8 @@ $(function () {
var osmUrl="http://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png";
var osmAttrib=[
'Données cartographiques CC-By-SA ',
'<a href="http://openstreetmap.org/" rel="external">OpenStreetMap<\/a>, ',
'Tuiles fournies par <a href="http://www.opencyclemap.org/" rel="external">Andy Allan<\/a>'
'<a href="http://openstreetmap.org/" target="_blank">OpenStreetMap<\/a>, ',
'Tuiles fournies par <a href="http://www.opencyclemap.org/" target="_blank">Andy Allan<\/a>'
].join('');
var osmLayer = new L.TileLayer(osmUrl, {minZoom: 2, maxZoom: 16, attribution: osmAttrib});
......
## -*- coding: utf-8 -*-
<%!
import markdown
%>
<%inherit file="/site.mako"/>
<%def name="head()">
${parent.head()}
<link rel="stylesheet" href="http://cdn.comarquage.fr/leaflet/latest/leaflet.css">
<link rel="stylesheet" href="${request.static_path('passim:static/css/maps.css')}">
<link rel="stylesheet" href="http://cdn.comarquage.fr/leaflet/latest/leaflet.css">
<link rel="stylesheet" href="${request.static_path('passim:static/css/maps.css')}">
</%def>
${parent.page_header()}
......@@ -38,8 +35,8 @@ $(function () {
var osmUrl="http://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png";
var osmAttrib=[
'Données cartographiques CC-By-SA ',
'<a href="http://openstreetmap.org/" rel="external">OpenStreetMap<\/a>, ',
'Tuiles fournies par <a href="http://www.opencyclemap.org/" rel="external">Andy Allan<\/a>'
'<a href="http://openstreetmap.org/" target="_blank">OpenStreetMap<\/a>, ',
'Tuiles fournies par <a href="http://www.opencyclemap.org/" target="_blank">Andy Allan<\/a>'
].join('');
var osmLayer = new L.TileLayer(osmUrl, {minZoom: 2, maxZoom: 16, attribution: osmAttrib});
......
This diff is collapsed.
This diff is collapsed.
## -*- coding: utf-8 -*-
<%inherit file="/site.mako"/>
<%def name="head()">
${parent.head()}
<link href="${request.static_path('passim:static/lib/select2-4.0.0-rc.1/dist/css/select2.min.css')}" rel="stylesheet" />
<script defer src="${request.static_path('passim:static/lib/select2-4.0.0-rc.1/dist/js/select2.min.js')}"></script>
<script defer src="${request.static_path('passim:static/lib/select2-4.0.0-rc.1/dist/js/i18n/fr.js')}"></script>
<script defer src="${request.static_path('passim:static/js/search.js')}"></script>
</%def>
${parent.page_header()}
${parent.search_bar()}
<div class="search-navbar">
<h3>
% if error:
${error}
% else:
${_(u'Traveler Info Services List For')} « ${full_name} »
% endif
<span class="pull-right">
<a class="btn btn-default btn-sm" href="${request.route_path('territories', type='pays', name='france')}" rel="tooltip" title="${_('Search services for whole France')}">France</a>
</span>
</h3>
</div>
<br>
% if result:
% if len(result["multimodal"]) > 0 and show_multimodals:
<h4>${_("Multimodal Information Services")}</h4>
<table class="table table-bordered table-condensed table-hover table-responsive">
<colgroup>
<col class="col-md-1">
<col class="col-md-8">
<col class="col-md-3">
</colgroup>
<thead>
<tr>
<th>${_("Web Site")}</th>
<th>${_("Name")}</th>
<th>${_("Transport Type")}</th>
</tr>
</thead>
<tbody>
% for multimodal in result["multimodal"]:
<tr>
<td>
<a class="btn btn-primary" rel="tooltip" target="_blank" title="${_(u'Web Site')}" href="${multimodal["url"]}">www</a>
</td>
<td>
<a href="${multimodal["internal"]}">${multimodal["name"]}</a>
</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>
% endfor
</td>
</tr>
% endfor
</tbody>
</table>
% endif
% if len(result["local"]) > 0 and type_name == u"Commune":
<h4>${_("Local Interest Traveler Info Services")}</h4>
<table class="table table-bordered table-condensed table-hover table-responsive">
<colgroup>
<col class="col-md-1">
<col class="col-md-8">
<col class="col-md-3">
</colgroup>
<thead>
<tr>
<th>${_("Web Site")}</th>
<th>${_("Name")}</th>
<th>${_("Transport Type")}</th>
</tr>
</thead>
<tbody>
% for local in result["local"]:
<tr>
% if local["niveau"] == u"Local":
<td>
<a class="btn btn-primary internal" rel="tooltip" target="_blank" title="${_(u'Web Site')}" href="${local["url"]}">www</a>
</td>
<td>
<a href="${local["internal"]}">${local["name"]}</a>
</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>
% endfor
</td>
% endif
</tr>
% endfor
</tbody>
</table>
% endif
% if len(result["departmental"]) > 0 and type_name in (u"Région", u"Département", u"Commune",):
<h4>${_("Departmental Interest Traveler Info Services")}</h4>
<table class="table table-bordered table-condensed table-hover table-responsive">
<colgroup>
<col class="col-md-1">
<col class="col-md-8">
<col class="col-md-3">
</colgroup>
<thead>
<tr>
<th>${_("Web Site")}</th>
<th>${_("Name")}</th>
<th>${_("Transport Type")}</th>
</tr>
</thead>
<tbody>
% for departmental in result["departmental"]:
<tr>
% if departmental["niveau"] == u"Départemental":
<td>
<a class="btn btn-primary internal" rel="tooltip" target="_blank" title="${_(u'Web Site')}" href="${departmental["url"]}">www</a>
</td>
<td>
<a href="${departmental["internal"]}">${departmental["name"]}</a>
</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>
% endfor
</td>
% endif
</tr>
% endfor
</tbody>
</table>
% endif
% if len(result["regional"]) > 0 and type_name in (u"Région", u"Département", u"Commune",):
<h4>${_("Regional Interest Traveler Info Services")}</h4>
<table class="table table-bordered table-condensed table-hover table-responsive">
<colgroup>
<col class="col-md-1">
<col class="col-md-8">
<col class="col-md-3">
</colgroup>
<thead>
<tr>
<th>${_("Web Site")}</th>
<th>${_("Name")}</th>
<th>${_("Transport Type")}</th>
</tr>
</thead>
<tbody>
% for regional in result["regional"]:
<tr>
% if regional["niveau"] == u"Régional":
<td>
<a class="btn btn-primary internal" rel="tooltip" target="_blank" title="${_(u'Web Site')}" href="${regional["url"]}">www</a>
</td>
<td>
<a href="${regional["internal"]}">${regional["name"]}</a>
</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>
% endfor
</td>
% endif
</tr>
% endfor
</tbody>
</table>
% endif
% if len(result["national"]) > 0:
<h4>${_("National Information")}</h4>
<table class="table table-bordered table-condensed table-hover table-responsive">
<colgroup>
<col class="col-md-1">
<col class="col-md-8">
<col class="col-md-3">
</colgroup>
<thead>
<tr>
<th>${_("Web Site")}</th>
<th>${_("Name")}</th>
<th>${_("Transport Type")}</th>
</tr>
</thead>
<tbody>
% for national in result["national"]:
% if national["niveau"] == u"National":
% if len(national["territories"]) > 0 or full_name == "France":
<tr>
<td>
<a class="btn btn-primary internal" rel="tooltip" target="_blank" title="${_(u'Web Site')}" href="${national["url"]}">www</a>
</td>
<td>
<a class="internal" href="${national["internal"]}">${national["name"]}</a>
</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>
% endfor
</td>
</tr>
% endif
% endif
% endfor
</tbody>
</table>
% endif
% endif
......@@ -232,8 +232,8 @@ def index(request):
return HTTPFound(location=request.route_path('accueil'))
@view_config(route_name='organismes', renderer='/organismes.mako')
def organismes(request):
@view_config(route_name='organisms', renderer='/organisms.mako')
def organisms(request):
_ = request.translate
# get the service info data by id
......@@ -287,7 +287,7 @@ def organismes(request):
name=name,
transport_type=transport_type,
transport_id=transport_id,
url=request.route_path('organismes', name=name, id=transport_id),
url=request.route_path('organisms', name=name, id=transport_id),
transport_logo=", ".join(transport_logo)
)
)
......@@ -320,16 +320,16 @@ Thank you advance for any remarks, questions or suggestions about PASSIM !
)
@view_config(route_name='territoires', renderer='/territoires.mako')
def territoires(request):
@view_config(route_name='territories', renderer='/territories.mako')
def territories(request):
_ = request.translate
territoria_api = request.registry.settings['territoria_api']
petitpois_api = request.registry.settings['petitpois_api']
region_name = ""
region_fullname = ""
departement_name = ""
departement_fullname = ""
name = request.matchdict.get('id')
department_name = ""
department_fullname = ""
name = request.matchdict.get('name')
# we can have more than one territory
territories = [name]
......@@ -348,13 +348,13 @@ def territoires(request):
result=None,
country=None,
region=None,
departement=None,
department=None,
full_name=None,
type_name=None,
error=name + " " + _("Not found")
)
if request.matchdict.get('territoires_type') == "pays":
if request.matchdict.get('type') == "pays":
if name == "france":
territories = ["france-metropolitaine", "france"]
else:
......@@ -390,16 +390,16 @@ def territoires(request):
region_name = region_data["full_name"]
region_fullname = region_data['main_postal_distribution'] + ' (' + region_data['type_name'] + ')'
elif el["kind"] == "DepartmentOfFrance":
departement_data = requests.get(url, params=dict(kind="DepartmentOfFrance", code=el["code"])).json()["data"]
departement_name = departement_data["full_name"]
departement_fullname = departement_data['main_postal_distribution'] + ' (' + departement_data['type_name'] + ')'
department_data = requests.get(url, params=dict(kind="DepartmentOfFrance", code=el["code"])).json()["data"]
department_name = department_data["full_name"]
department_fullname = department_data['main_postal_distribution'] + ' (' + department_data['type_name'] + ')'
# Get territory's service infos
url = '{}/poi/search'.format(petitpois_api)
r = requests.get(url, params=dict(k=["service-d-information"], limit=0, w=name))
if r.json().get("errors"):
error["error"] = _("Error : ") + r.json().get("errors").get("where")
error["error"] = _("Error: ") + r.json().get("errors").get("where")
return error
elif r.status_code != 200:
error["error"] = _("API error")
......@@ -407,8 +407,8 @@ def territoires(request):
petitpois_responses.append(r.json())
# If territory is a country, dont show multimodal service infos
show_multimodales = True if request.matchdict.get('territoires_type') != "pays" else False
# If territory is a country, don't show multimodal info services
show_multimodals = True if request.matchdict.get('type') != "pays" else False
# Extract all needed data for each service infos
result = []
......@@ -424,7 +424,7 @@ def territoires(request):
name=[],
url=[],
services=[],
type_transport=[]
transport_type=[]
)
for item in el["fields"]:
obj_response["kind"] = item.get("kind")
......@@ -444,8 +444,8 @@ def territoires(request):
elif element["label"] == "Type de transport":
set_type.add(element["value"])
obj_response["offre"] = list(set_offre)
for type_transport in list(set_type):
obj_response["type_transport"].append(slugify(type_transport))
for transport_type in list(set_type):
obj_response["transport_type"].append(slugify(transport_type))
elif item["label"] == "Nom du service":
obj_response["name"] = item["value"]
elif item["label"] == "Site web - URL":
......@@ -456,7 +456,7 @@ def territoires(request):
for territories in item["value"]:
obj_response["territories"].append(territories)
obj_response["id"] = el["id"]
obj_response["internal"] = request.route_path('organismes', name=slugify(obj_response["name"]), id=el["id"])
obj_response["internal"] = request.route_path('organisms', name=slugify(obj_response["name"]), id=el["id"])
result.append(obj_response)
# arrange final result according to "niveau"
......@@ -464,14 +464,14 @@ def territoires(request):
multimodal=[],
national=[],
regional=[],
departemental=[],
departmental=[],
local=[]
)
for el in result:
territories = el.get('territories', [])
if full_name_and_cp in territories \
or departement_fullname in territories \
or department_fullname in territories \
or region_fullname in territories \
or name == 'france' or name == 'france-metropolitaine':
......@@ -482,17 +482,17 @@ def territoires(request):
elif el.get("niveau") == u"Régional":
parse_result["regional"].append(el)
elif el.get("niveau") == u"Départemental":
parse_result["departemental"].append(el)
parse_result["departmental"].append(el)
elif el.get("niveau") == u"Local":
parse_result["local"].append(el)
return dict(
show_multimodales=show_multimodales,
show_multimodals=show_multimodals,
target=name,
result=parse_result,
country=country,
region=region_name,
departement=departement_name,
department=department_name,
full_name=full_name,
type_name=type_name,
error=None,
......
......@@ -76,7 +76,7 @@ def parse_last_update(json_obj, request):
id = item["id"]
result.append(
dict(
url=request.route_path('organismes', name=slug, id=id),
url=request.route_path('organisms', name=slug, id=id),
slug=slug,
id=id,
name=name,
......
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