summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Kersten <jke@odoo.com>2016-01-08 23:16:25 +0100
committerJeremy Kersten <jke@odoo.com>2016-01-08 23:19:29 +0100
commitce3f7970686c5658c3fd72a67d5ee06ce61849d1 (patch)
tree489725d52bed27e8acc21f1693c5ff8543d4e8c5
parent2afadfe444ec52acec5d7890cda5ae6817604999 (diff)
[FIX] website_event: avoid traceback when page doesn't exists
The controller /event/<event_id>/page/<page> raise exception if page is not existing. Allow to pass the template reference when user are creating a new page. Without it, it is impossible for the end user to create a website_event page without change manually the xml id because the xml id is based on the module from the template. This fix is retro compatible, because from_template will be ignored until next update of website. And during update from website, website_event will be updated because it's a dependance and so the default_page template created.
-rw-r--r--addons/website/controllers/main.py7
-rw-r--r--addons/website/models/ir_ui_view.py1
-rw-r--r--addons/website/views/website_templates.xml2
-rw-r--r--addons/website_event/controllers/main.py9
-rw-r--r--addons/website_event/views/website_event.xml7
5 files changed, 23 insertions, 3 deletions
diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py
index 182d05c3c51..c44ae20e117 100644
--- a/addons/website/controllers/main.py
+++ b/addons/website/controllers/main.py
@@ -180,8 +180,11 @@ class Website(openerp.addons.web.controllers.main.Home):
# Edit
#------------------------------------------------------
@http.route('/website/add/<path:path>', type='http', auth="user", website=True)
- def pagenew(self, path, noredirect=False, add_menu=None):
- xml_id = request.registry['website'].new_page(request.cr, request.uid, path, context=request.context)
+ def pagenew(self, path, noredirect=False, add_menu=None, template=False):
+ if template:
+ xml_id = request.registry['website'].new_page(request.cr, request.uid, path, template=template, context=request.context)
+ else:
+ xml_id = request.registry['website'].new_page(request.cr, request.uid, path, context=request.context)
if add_menu:
request.registry['website.menu'].create(
request.cr, request.uid, {
diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py
index e1a861d3a9f..20200531a63 100644
--- a/addons/website/models/ir_ui_view.py
+++ b/addons/website/models/ir_ui_view.py
@@ -106,6 +106,7 @@ class view(osv.osv):
domain = [('key', '=', xml_id), '|', ('website_id', '=', context['website_id']), ('website_id', '=', False)]
[view_id] = self.search(cr, uid, domain, order='website_id', limit=1, context=context) or [None]
if not view_id:
+ _logger.warning("Could not find view object with xml_id '%s'" % (xml_id))
raise ValueError('View %r in website %r not found' % (xml_id, context['website_id']))
else:
view_id = super(view, self).get_view_id(cr, uid, xml_id, context=context)
diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml
index 61c62b0daa2..c5fdd214359 100644
--- a/addons/website/views/website_templates.xml
+++ b/addons/website/views/website_templates.xml
@@ -645,7 +645,7 @@
<div class="container">
<div class="well mt32">
<p>This page does not exists, but you can create it as you are administrator of this site.</p>
- <a class="btn btn-primary" t-attf-href="/website/add/#{ path }">Create Page</a>
+ <a class="btn btn-primary" t-attf-href="/website/add/#{ path }#{ from_template and '?template=%s' % from_template }">Create Page</a>
</div>
<div class="text-center text-muted">Edit the content below this line to adapt the default "page not found" page.</div>
</div>
diff --git a/addons/website_event/controllers/main.py b/addons/website_event/controllers/main.py
index a97acb0fb4c..6bf3801a961 100644
--- a/addons/website_event/controllers/main.py
+++ b/addons/website_event/controllers/main.py
@@ -2,6 +2,7 @@
import babel.dates
import time
+import re
import werkzeug.urls
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
@@ -162,6 +163,14 @@ class website_event(http.Controller):
if '.' not in page:
page = 'website_event.%s' % page
+ try:
+ request.website.get_template(page)
+ except ValueError:
+ # page not found
+ values['path'] = re.sub(r"^website_event\.", '', page)
+ values['from_template'] = 'website_event.default_page' # .strip('website_event.')
+ page = 'website.page_404'
+
return request.website.render(page, values)
@http.route(['/event/<model("event.event"):event>'], type='http', auth="public", website=True)
diff --git a/addons/website_event/views/website_event.xml b/addons/website_event/views/website_event.xml
index c4e4d41310c..0fb5117791a 100644
--- a/addons/website_event/views/website_event.xml
+++ b/addons/website_event/views/website_event.xml
@@ -257,6 +257,13 @@
</t>
</template>
+<template id="default_page">
+ <t t-call="website.layout">
+ <div class="oe_structure oe_empty"/>
+ </t>
+</template>
+
+
<template id="event_details">
<t t-call="website_event.layout">
<div itemscope="itemscope" itemtype="http://schema.org/Event" class="container">