[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.
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user