Files
odoo_source/addons/website_blog/models/website.py
T
rde a91a3a5633 [IMP] website: warn user about key change when editing special file name
The idea is to warn user if he created a special file (website.page with
supported extension) and he wants to change the file's name, which will at the
end also change the key).
If this special file has been t-called elsewhere, they t-call wont work anymore
This is why warning user is needed.

Note that this is different than the already existing page_search_dependencies
that is just checking if the URL is present in menus, templates, blog or pages.
This is about checking if the key is present somewhere. (we assume that if the
key is present, it is surely about a t-call.

Technically, the flow is:
1. Get supported extension
2. Get key dependencies
3. Check if user modify name
4. If name changed and it is/was a supported extension (special file) and it
   has dependencies (surely t-call) then warn user these call wont work anymore

--

search_page_dependencies is also improved by returning links to be clickable
(on delete dialog eg) and splitting template/page results.

it also refactor dependencies warning that was creating HTML in javascript into
using XML template
2017-10-12 16:20:42 +02:00

59 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, _
class Website(models.Model):
_inherit = "website"
@api.model
def page_search_dependencies(self, page_id=False):
dep = super(Website, self).page_search_dependencies(page_id=page_id)
page = self.env['website.page'].browse(int(page_id))
path = page.url
dom = [
('content', 'ilike', path)
]
posts = self.env['blog.post'].search(dom)
if posts:
page_key = _('Blog Post')
if len(posts) > 1:
page_key = _('Blog Posts')
dep[page_key] = []
for p in posts:
dep[page_key].append({
'text': _('Blog Post <b>%s</b> seems to have a link to this page !') % p.name,
'item': p.name,
'link': p.website_url,
})
return dep
@api.model
def page_search_key_dependencies(self, page_id=False):
dep = super(Website, self).page_search_key_dependencies(page_id=page_id)
page = self.env['website.page'].browse(int(page_id))
key = page.key
dom = [
('content', 'ilike', key)
]
posts = self.env['blog.post'].search(dom)
if posts:
page_key = _('Blog Post')
if len(posts) > 1:
page_key = _('Blog Posts')
dep[page_key] = []
for p in posts:
dep[page_key].append({
'text': _('Blog Post <b>%s</b> seems to be calling this file !') % p.name,
'item': p.name,
'link': p.website_url,
})
return dep