[FIX] website: auto-increment when new page; fix link (key) search page
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user