Commit c678e47f authored by Pierre Arnaud's avatar Pierre Arnaud

Change organism route and fix 404 Not Found

parent 4ee3763f
......@@ -76,7 +76,7 @@ def main(global_config, **settings):
config.add_route('open-data', '/open-data') # Apache directory listing
config.add_route('organisms', '/organismes/{name}/{id}')
config.add_route('organisms', '/organismes/{id}')
config.add_route('territories', '/territoires/{type}/{name}')
config.scan('passim.views')
......
......@@ -8,20 +8,7 @@ ${parent.head()}
</%def>
${parent.page_header()}
% if error:
<div class="error-page">
<h3 class="headline text-info">404</h3>
<div class="error-page-content">
<h4><i class="fa fa-warning text-yellow"></i> ${_(u'Oops! Page not found.')}</h4>
<p>
${error}
</p>
<p>
${_(u'We could not find the page you were looking for. Meanwhile, you may <a href="{}">return to Home</a>').format(request.route_path('accueil')) | n}.
</p>
</div><!-- /.error-content -->
</div><!-- /.error-page -->
%else:
<div class="container"><div class="row">
<div class="page-header">
<h4>
......@@ -133,4 +120,3 @@ ${parent.page_header()}
% else:
${_("None")}
% endif
% endif
......@@ -133,11 +133,10 @@ from passim.resources import UsersResource
<div class="container">
${self.body()}
<hr>
<footer class="footer">
<a href="${request.route_path('about')}">${_(u'About')}</a>
% if route_name.startswith('organisms'):
% if route_name.startswith('organisms') and request.response.status_int == 200:
<%include file="contribute-form.mako" args="subject=subject, body=body"/>
<p class="pull-right contribute-text">
<a class="label label-info modal-trigger" href="#contribute-modal">${_(u"Thanks for signalling us any erroneous, missing or incomplete info")}</a>
......
......@@ -12,29 +12,14 @@ ${parent.head()}
${parent.page_header()}
${parent.search_bar()}
% if error:
<div class="error-page">
<h3 class="headline text-info">404</h3>
<div class="error-page-content">
<h4><i class="fa fa-warning text-yellow"></i> ${_(u'Oops! Page not found.')}</h4>
<p>
${_(u'We could not find the page you were looking for. Meanwhile, you may <a href="{}">return to Home</a>').format(request.route_path('accueil')) | n}.
</p>
</div><!-- /.error-content -->
</div><!-- /.error-page -->
% endif
<div class="search-navbar">
<h3>
% if error:
${error}
% else:
% if full_name == "France":
${_(u'Information Services for whole France')}
% else:
${_(u'Traveler Info Services List For')} « ${full_name} »
% endif
% 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>
......
......@@ -34,7 +34,7 @@ from passim.utils import slugify
from pyramid_helpers.forms import validate
from pyramid.httpexceptions import HTTPFound
from pyramid.httpexceptions import HTTPFound, HTTPNotFound
from pyramid.renderers import render
from pyramid.view import forbidden_view_config
......@@ -234,7 +234,6 @@ def open_data(request):
@view_config(route_name='organisms', renderer='/organisms.mako')
def organisms(request):
_ = request.translate
name = request.matchdict.get('name')
body = _(u'''Your are [an end-user, a company...]
Your e-mail address: [xxx@yyy.org]
......@@ -260,20 +259,11 @@ Thank you advance for any remarks, questions or suggestions about PASSIM !
petitpois_api = request.registry.settings['petitpois_api']
url = '{}poi/{}'.format(petitpois_api, id)
resp = requests.get(url)
error = dict(
id=id,
result=None,
success_message=None,
subject=subject.format(name),
body=body.format(name, request.url),
title=name,
error="" + name + " " + _("Not found")
)
petitpois_response = resp.json()
parse_result = dict()
if not petitpois_response.get("data"):
return error
raise HTTPNotFound()
parse_result["updated"] = datetime.datetime.strptime(petitpois_response["data"]["updated"]["date"].split("T")[0], "%Y-%m-%d").strftime('%d/%m/%Y')
......@@ -359,23 +349,12 @@ def territories(request):
'Country',
'MetropoleOfCountry'
]
error = dict(
show_multimodales=None,
target=None,
result=None,
country=None,
region=None,
department=None,
full_name=None,
type_name=None,
error=name + " " + _("Not found")
)
if request.matchdict.get('type') == "pays":
if name == "france":
territories = ["france-metropolitaine", "france"]
else:
return error
raise HTTPNotFound()
petitpois_responses = [] # Stock all services infos
for name in territories:
......@@ -387,7 +366,7 @@ def territories(request):
if items:
territory_id = items[0]['id']
else:
return error
raise HTTPNotFound()
ptu_fullname = ""
# Get infos about territory
......@@ -398,7 +377,7 @@ def territories(request):
type_name = json_get_territoire_info["data"]["type_name"]
full_name_and_cp = json_get_territoire_info['data']['main_postal_distribution'] + ' (' + json_get_territoire_info['data']['type_name'] + ')'
else:
return error
raise HTTPNotFound()
for el in json_get_territoire_info["data"]["ancestors_kind_code"]:
if el["kind"] == "Country":
......@@ -419,12 +398,8 @@ def territories(request):
url = '{}/poi/search'.format(petitpois_api)
r = requests.get(url, params=dict(k=["service-d-information"], limit=0, w=name))
if r.status_code != 200:
error["error"] = _("API error")
return error
elif r.json().get("errors"):
error["error"] = _("Error: ") + r.json().get("errors").get("where")
return error
if r.status_code != 200 or r.json().get("errors"):
raise HTTPNotFound()
petitpois_responses.append(r.json())
# If territory is a country, don't show multimodal info services
......@@ -529,7 +504,6 @@ def territories(request):
department=department_name,
full_name=full_name,
type_name=type_name,
error=None,
title=full_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