From 196ecf17a1ebe3534145d82299263cb4d2b065f4 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 8 Dec 2014 16:56:27 +0100 Subject: [PATCH] [FIX] website: auto-increment when new page; fix link (key) search page --- addons/website/models/ir_http.py | 12 +++++++----- addons/website/models/website.py | 33 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index ac92036cfa4..6f7c650bdbd 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -293,15 +293,17 @@ class PageConverter(werkzeug.routing.PathConverter): """ Only point of this converter is to bundle pages enumeration logic """ def generate(self, cr, uid, query=None, args={}, context=None): View = request.registry['ir.ui.view'] - views = View.search_read(cr, uid, [['page', '=', True]], - fields=['xml_id','priority','write_date'], order='name', context=context) + domain = [('page', '=', True)] + query = query and query.startswith('website.') and query[8:] or query + if query: + domain += [('key', 'like', query)] + + views = View.search_read(cr, uid, domain, fields=['key', 'priority', 'write_date'], order='name', context=context) for view in views: - xid = view['xml_id'].startswith('website.') and view['xml_id'][8:] or view['xml_id'] + xid = view['key'].startswith('website.') and view['key'][8:] or view['key'] # the 'page/homepage' url is indexed as '/', avoid aving the same page referenced twice # when we will have an url mapping mechanism, replace this by a rule: page/homepage --> / if xid=='homepage': continue - if query and query.lower() not in xid.lower(): - continue record = {'loc': xid} if view['priority'] <> 16: record['__priority'] = min(round(view['priority'] / 32.0,1), 1) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 2de6177eb77..253c6b71170 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -202,21 +202,24 @@ class website(osv.osv): page_name = slugify(name, max_length=50) page_xmlid = "%s.%s" % (template_module, page_name) - try: - # existing page - imd.get_object_reference(cr, uid, template_module, page_name) - except ValueError: - # new page - _, template_id = imd.get_object_reference(cr, uid, template_module, template_name) - website_id = context.get('website_id') - key = template_module+'.'+page_name - page_id = view.copy(cr, uid, template_id, {'website_id': website_id, 'key': key}, context=context) - page = view.browse(cr, uid, page_id, context=context) - page.write({ - 'arch': page.arch.replace(template, page_xmlid), - 'name': page_name, - 'page': ispage, - }) + # find a free xmlid + inc = 0 + while view.search(cr, openerp.SUPERUSER_ID, [('key', '=', page_xmlid)], context=dict(context or {}, active_test=False)): + inc += 1 + page_xmlid = "%s.%s" % (template_module, page_name + (inc and "-%s" % inc or "")) + page_name += (inc and "-%s" % inc or "") + + # new page + _, template_id = imd.get_object_reference(cr, uid, template_module, template_name) + website_id = context.get('website_id') + key = template_module+'.'+page_name + page_id = view.copy(cr, uid, template_id, {'website_id': website_id, 'key': key}, context=context) + page = view.browse(cr, uid, page_id, context=context) + page.write({ + 'arch': page.arch.replace(template, page_xmlid), + 'name': page_name, + 'page': ispage, + }) return page_xmlid def page_for_name(self, cr, uid, ids, name, module='website', context=None):