commit af94c6ffa67ab420561731c2782c75da30d817e6 Author: Ieva Date: Fri Nov 29 09:07:32 2024 +0200 initial commit diff --git a/le_website_exclude_url/__init__.py b/le_website_exclude_url/__init__.py new file mode 100644 index 0000000..5305644 --- /dev/null +++ b/le_website_exclude_url/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models \ No newline at end of file diff --git a/le_website_exclude_url/__manifest__.py b/le_website_exclude_url/__manifest__.py new file mode 100644 index 0000000..f7761a8 --- /dev/null +++ b/le_website_exclude_url/__manifest__.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Remove Sitemap URLS', + 'version': '1.0.0', + 'category': 'Website', + 'summary': 'Allows the removal of specific urls from the sitemap.', + 'description': """ + sitemap + remove from sitemap + exclude url from sitemap + exclude url sitemap + remove url sitemap + sitemap improvements + advanced sitemap + """, + 'author': "Lean Easy", + 'website': "https://www.leaneasy.co.uk", + 'depends': ['base', 'website'], + 'data': [ + 'views/res_config_settings.xml', + ], + 'images': [ + 'static/description/module_banner.jpg', + 'static/description/icon.png' + ], + 'installable': True, + 'auto_install': False, + 'application': False, + 'license': 'OPL-1', +} diff --git a/le_website_exclude_url/__pycache__/__init__.cpython-37.pyc b/le_website_exclude_url/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..84d3180 Binary files /dev/null and b/le_website_exclude_url/__pycache__/__init__.cpython-37.pyc differ diff --git a/le_website_exclude_url/models/__init__.py b/le_website_exclude_url/models/__init__.py new file mode 100644 index 0000000..90dc508 --- /dev/null +++ b/le_website_exclude_url/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import website +from . import res_config_settings \ No newline at end of file diff --git a/le_website_exclude_url/models/__pycache__/__init__.cpython-37.pyc b/le_website_exclude_url/models/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..5b0dd38 Binary files /dev/null and b/le_website_exclude_url/models/__pycache__/__init__.cpython-37.pyc differ diff --git a/le_website_exclude_url/models/__pycache__/res_config_settings.cpython-37.pyc b/le_website_exclude_url/models/__pycache__/res_config_settings.cpython-37.pyc new file mode 100644 index 0000000..31265cc Binary files /dev/null and b/le_website_exclude_url/models/__pycache__/res_config_settings.cpython-37.pyc differ diff --git a/le_website_exclude_url/models/__pycache__/website.cpython-37.pyc b/le_website_exclude_url/models/__pycache__/website.cpython-37.pyc new file mode 100644 index 0000000..b42efe4 Binary files /dev/null and b/le_website_exclude_url/models/__pycache__/website.cpython-37.pyc differ diff --git a/le_website_exclude_url/models/res_config_settings.py b/le_website_exclude_url/models/res_config_settings.py new file mode 100644 index 0000000..8a419ef --- /dev/null +++ b/le_website_exclude_url/models/res_config_settings.py @@ -0,0 +1,7 @@ +from odoo import models, fields, api + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + le_excl_sitemap_url = fields.Text(string="Exclude from Sitemap",related='website_id.le_excl_sitemap_url', readonly=False) \ No newline at end of file diff --git a/le_website_exclude_url/models/website.py b/le_website_exclude_url/models/website.py new file mode 100644 index 0000000..89f42a5 --- /dev/null +++ b/le_website_exclude_url/models/website.py @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- + +import logging + +from odoo import api, fields, models, _, http +from odoo.http import request +from odoo.addons.website.models.ir_http import sitemap_qs2dom +from odoo.osv.expression import FALSE_DOMAIN + +logger = logging.getLogger(__name__) + + +class Website(models.Model): + _inherit = 'website' + + le_excl_sitemap_url = fields.Text() + + # Overwrite default method to add our own code + def _enumerate_pages(self, query_string=None, force=False): + """ Available pages in the website/CMS. This is mostly used for links + generation and can be overridden by modules setting up new HTML + controllers for dynamic pages (e.g. blog). + By default, returns template views marked as pages. + :param str query_string: a (user-provided) string, fetches pages + matching the string + :returns: a list of mappings with two keys: ``name`` is the displayable + name of the resource (page), ``url`` is the absolute URL + of the same. + :rtype: list({name: str, url: str}) + """ + + router = http.root.get_db_router(request.db) + # Force enumeration to be performed as public user + url_set = set() + + sitemap_endpoint_done = set() + + for rule in router.iter_rules(): + if 'sitemap' in rule.endpoint.routing and rule.endpoint.routing['sitemap'] is not True: + if rule.endpoint in sitemap_endpoint_done: + continue + sitemap_endpoint_done.add(rule.endpoint) + + func = rule.endpoint.routing['sitemap'] + if func is False: + continue + for loc in func(self.env, rule, query_string): + if self._check_loc_url(loc): + yield loc + continue + + if not self.rule_is_enumerable(rule): + continue + + if 'sitemap' not in rule.endpoint.routing: + logger.warning('No Sitemap value provided for controller %s (%s)' % + (rule.endpoint.method, ','.join(rule.endpoint.routing['routes']))) + + converters = rule._converters or {} + if query_string and not converters and (query_string not in rule.build({}, append_unknown=False)[1]): + continue + + values = [{}] + # converters with a domain are processed after the other ones + convitems = sorted( + converters.items(), + key=lambda x: (hasattr(x[1], 'domain') and (x[1].domain != '[]'), rule._trace.index((True, x[0])))) + + for (i, (name, converter)) in enumerate(convitems): + if 'website_id' in self.env[converter.model]._fields and (not converter.domain or converter.domain == '[]'): + converter.domain = "[('website_id', 'in', (False, current_website_id))]" + + newval = [] + for val in values: + query = i == len(convitems) - 1 and query_string + if query: + r = "".join([x[1] for x in rule._trace[1:] if not x[0]]) # remove model converter from route + query = sitemap_qs2dom(query, r, self.env[converter.model]._rec_name) + if query == FALSE_DOMAIN: + continue + + for rec in converter.generate(uid=self.env.uid, dom=query, args=val): + newval.append(val.copy()) + newval[-1].update({name: rec}) + values = newval + + for value in values: + domain_part, url = rule.build(value, append_unknown=False) + if not query_string or query_string.lower() in url.lower(): + page = {'loc': url} + if url in url_set: + continue + url_set.add(url) + + if self._check_loc_url(page): + yield page + + # '/' already has a http.route & is in the routing_map so it will already have an entry in the xml + domain = [('url', '!=', '/')] + if not force: + domain += [('website_indexed', '=', True), ('visibility', '=', False)] + # is_visible + domain += [ + ('website_published', '=', True), ('visibility', '=', False), + '|', ('date_publish', '=', False), ('date_publish', '<=', fields.Datetime.now()) + ] + + if query_string: + domain += [('url', 'like', query_string)] + + pages = self._get_website_pages(domain) + + for page in pages: + record = {'loc': page['url'], 'id': page['id'], 'name': page['name']} + if page.view_id and page.view_id.priority != 16: + record['priority'] = min(round(page.view_id.priority / 32.0, 1), 1) + if page['write_date']: + record['lastmod'] = page['write_date'].date() + + if self._check_loc_url(record): + yield record + + + def _check_loc_url(self, loc): + if self.le_excl_sitemap_url: + urls = self.le_excl_sitemap_url.split('\n') + + if loc['loc'] in urls: + return False + + return True diff --git a/le_website_exclude_url/security/ir.model.access.csv b/le_website_exclude_url/security/ir.model.access.csv new file mode 100644 index 0000000..0343f29 --- /dev/null +++ b/le_website_exclude_url/security/ir.model.access.csv @@ -0,0 +1 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" diff --git a/le_website_exclude_url/static/description/20943761.png b/le_website_exclude_url/static/description/20943761.png new file mode 100644 index 0000000..dcf18ae Binary files /dev/null and b/le_website_exclude_url/static/description/20943761.png differ diff --git a/le_website_exclude_url/static/description/20945365.png b/le_website_exclude_url/static/description/20945365.png new file mode 100644 index 0000000..8ee17c5 Binary files /dev/null and b/le_website_exclude_url/static/description/20945365.png differ diff --git a/le_website_exclude_url/static/description/20945457.png b/le_website_exclude_url/static/description/20945457.png new file mode 100644 index 0000000..05aeba2 Binary files /dev/null and b/le_website_exclude_url/static/description/20945457.png differ diff --git a/le_website_exclude_url/static/description/Lean Easy Logo.png b/le_website_exclude_url/static/description/Lean Easy Logo.png new file mode 100644 index 0000000..863ad78 Binary files /dev/null and b/le_website_exclude_url/static/description/Lean Easy Logo.png differ diff --git a/le_website_exclude_url/static/description/icon.png b/le_website_exclude_url/static/description/icon.png new file mode 100644 index 0000000..f4151da Binary files /dev/null and b/le_website_exclude_url/static/description/icon.png differ diff --git a/le_website_exclude_url/static/description/index.html b/le_website_exclude_url/static/description/index.html new file mode 100644 index 0000000..f45d48e --- /dev/null +++ b/le_website_exclude_url/static/description/index.html @@ -0,0 +1,74 @@ +
+
+

Remove Sitemap URLS

+

By Lean Easy Ltd

+ +
+
+

+ Easily remove unwanted URLs from your sitemap, such as /website/info and a redirected links. +

+
+

Only tested on Odoo Community Edition

+
+
+ +
+
+

Overview

+ +
+

Add URLs separated by new lines in settings.

+ +
+
+
+ +
+
+ +
+
+
+

+ We are a UK based Odoo development team specialising in Python, PostgreSQL, JavaScript and XML. We can supply bespoke odoo solutions including modules, customisations and website themes. We have worked closely with other companies and look forward to working with you, so feel + free to get in touch with any support questions or bespoke requests. +

+
Contact us by copying the link below:
+ https://www.leaneasy.co.uk/contactus +
+
+
+
+
+
+
+ +
+
+ Module
Development
+
+
+
+
+
+
+ +
+
+ Module
Customisation
+
+
+
+
+
+
+ +
+
+ Odoo
Websites
+
+
+
+
+
diff --git a/le_website_exclude_url/static/description/module_banner.jpg b/le_website_exclude_url/static/description/module_banner.jpg new file mode 100644 index 0000000..6891cc7 Binary files /dev/null and b/le_website_exclude_url/static/description/module_banner.jpg differ diff --git a/le_website_exclude_url/static/description/settings.jpg b/le_website_exclude_url/static/description/settings.jpg new file mode 100644 index 0000000..0d78982 Binary files /dev/null and b/le_website_exclude_url/static/description/settings.jpg differ diff --git a/le_website_exclude_url/views/res_config_settings.xml b/le_website_exclude_url/views/res_config_settings.xml new file mode 100644 index 0000000..7e65df2 --- /dev/null +++ b/le_website_exclude_url/views/res_config_settings.xml @@ -0,0 +1,26 @@ + + + + + res.config.settings.iw.website.exclude.view.form + res.config.settings + + + +
+
+
+
+
+
+
+
+ +
\ No newline at end of file