Skip to content

Commit

Permalink
Merge PR #897 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed May 26, 2022
2 parents e78c3a3 + 70e1433 commit ccf9155
Show file tree
Hide file tree
Showing 35 changed files with 9,037 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup/website_legal_page/odoo/addons/website_legal_page
6 changes: 6 additions & 0 deletions setup/website_legal_page/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
140 changes: 140 additions & 0 deletions website_legal_page/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
==================
Website Legal Page
==================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github
:target: https://github.com/OCA/website/tree/14.0/website_legal_page
:alt: OCA/website
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/website-14-0/website-14-0-website_legal_page
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/186/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module was written to provide common legal page needed in any website.
This legal page must be edited using the website builder.

**Table of contents**

.. contents::
:local:

Usage
=====

Website editor can change easily any text of these pages using website builder.

If you install this module after 'website_sale', it will be merge the content
of 'website_sale.terms' into a new page.

This module hard-redirect '/shop/terms' to '/legal'.


Disclaimer
~~~~~~~~~~

These legal pages are templates.

**You must edit the templates and adapt them to your particular case**

The provided agreements are for **informational purposes only** and do not
constitute legal advice.

Authors, contributors and maintainer are not law firms and are not providing legal advice.
All information (including agreements, forms and documents) available in this
addon are **provided without any warranty**, express or implied, including as to
their legal effect and completeness. The information **should be used as a
guide** and modified to meet your own individual needs and the laws of your
state. Your use of any information or forms is at your own risk.

Authors, contributors, maintainer and any of its employees, contractors, or
attorneys who participated in development of this addon **expressly disclaim any
warranty**: they are not creating or entering into any Attorney-Client
relationship by providing information to you.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/website/issues/new?body=module:%20website_legal_page%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Tecnativa
* LasLabs
* Nicolas JEUDY

Contributors
~~~~~~~~~~~~

* Antonio Espinosa <[email protected]>
* Igor Pastor <[email protected]>
* Dave Lasley <[email protected]>
* Nicola Malcontenti <[email protected]>
* Nicolas JEUDY <https://github.com/njeudy>
* Lorenzo Battistini <https://github.com/eLBati>
* Eduardo Magdalena <[email protected]> (C2i Change 2 improve http://www.c2i.es)

* `Tecnativa <https://www.tecnativa.com>`_:

* Rafael Blasco
* Jairo Llopis
* Alexandre Diaz

Other credits
~~~~~~~~~~~~~

Templates
~~~~~~~~~

Templates are based on legal templates publicy provided by `termsfeed.com <https://termsfeed.com>`_:

* `Privacy policy <https://media.termsfeed.com/pdf/privacy-policy-template.pdf>`_
* `Terms of use <https://media.termsfeed.com/pdf/terms-of-use-template.pdf>`_

Icon
~~~~

Icon based on ``johnny-automatic-scales-of-justice.svg`` from
`Openclipart <https://openclipart.org/detail/26849/scales-of-justice>`_

Thanks to `johnny_automatic <https://openclipart.org/user-detail/johnny_automatic>`_

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/website <https://github.com/OCA/website/tree/14.0/website_legal_page>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions website_legal_page/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import controllers
from .hooks import post_init_hook, _merge_views
26 changes: 26 additions & 0 deletions website_legal_page/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2015 Antonio Espinosa <[email protected]>
# Copyright 2017 Jairo Llopis <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Website Legal Page",
"category": "Website",
"version": "15.0.1.0.0",
"depends": ["website"],
"data": [
"views/reusable_templates.xml",
"views/website_legal_main_page.xml",
],
"assets": {
"web.assets_frontend": [
"/website_legal_page/static/src/css/website_legal_page.scss"
]
},
"author": "Tecnativa, "
"LasLabs, "
"Nicolas JEUDY, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/website",
"license": "AGPL-3",
"post_init_hook": "post_init_hook",
}
1 change: 1 addition & 0 deletions website_legal_page/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
16 changes: 16 additions & 0 deletions website_legal_page/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2020 Alexandre Díaz - Tecnativa
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import http
from odoo.http import request


class WebsiteLegalPage(http.Controller):
@http.route(["/terms"], type="http", auth="public", website=True)
def terms(self, **kw):
"""
Ensure the website_legal_page template usage, even if the page was edited.
This is done in this way because 'http.route' wins to
'website.rewrite' 301 redirections.
"""
return request.redirect("/legal")
109 changes: 109 additions & 0 deletions website_legal_page/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright 2020 Tecnativa - Alexandre Díaz
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from copy import deepcopy
from xml.sax.saxutils import escape

from lxml import etree as ElementTree

from odoo import SUPERUSER_ID, api


def _merge_views(env, xmlids):
old_view_ids = env["ir.ui.view"].search(
[("key", "in", xmlids), ("active", "=", True)]
)
# Get only the edited version of the views (if has it)
old_view_ids_edited = old_view_ids.filtered("website_id")
old_view_ids_edited_keys = old_view_ids_edited.mapped("key")
views_to_discard = env["ir.ui.view"]
for old_view in old_view_ids:
if not old_view.website_id and old_view.key in old_view_ids_edited_keys:
views_to_discard |= old_view
old_view_ids -= views_to_discard
new_website_page = env.ref("website_legal_page.legal_page_page")
new_view_id = env.ref("website_legal_page.legal_page")
# 'Dolly' separator element
separator = ElementTree.fromstring(
"<div class='s_hr text-left pt32 pb32' data-name='Separator'>"
+ "<hr class='s_hr_1px s_hr_solid border-600 w-100 mx-auto'/></div>"
)
# Replace new content with the old one per website
website_ids = old_view_ids.mapped("website_id")
for website_id in website_ids:
new_xml = ElementTree.fromstring(new_view_id.arch)
table_content_list = new_xml.xpath("//div[@id='section_list']/ul")[0]
sections_content = new_xml.xpath("//div[@id='section_content']")[0]
has_views_edited = any(
old_view_ids_edited.filtered(lambda x: x.website_id == website_id)
)
# Remove 'IS A SAMPLE' alert
if has_views_edited:
alert = new_xml.xpath(
"//section[@data-name='Title']//div[@data-name='Alert']"
)[0]
alert.find("..").remove(alert)
# Remove unused content
for child in table_content_list.getchildren():
table_content_list.remove(child)
for child in sections_content.getchildren():
sections_content.remove(child)
views_done = env["ir.ui.view"]
for old_view_id in old_view_ids:
if old_view_id.website_id != website_id:
continue
anchor_name = old_view_id.key.split(".")[1]
# Insert item in table content list
list_item = ElementTree.fromstring(
"<li><p><a href='#{}'>{}</a></p></li>".format(
anchor_name, escape(old_view_id.name)
)
)
table_content_list.append(list_item)
# Insert section content
old_xml = ElementTree.fromstring(old_view_id.arch)
old_content = old_xml.xpath("//div[@id='wrap']")[0]
sections_content.append(deepcopy(separator))
sections_content.append(
ElementTree.fromstring(
"<a class='legal_anchor' id='%s'/>" % anchor_name
)
)
for children in old_content.getchildren():
sections_content.append(children)
views_done |= old_view_id
old_view_ids -= views_done
# Create a new page with the changes
view_id = env["ir.ui.view"].create(
{
"arch": ElementTree.tostring(new_xml, encoding="unicode"),
"website_id": website_id.id,
"key": new_view_id.key,
"name": new_view_id.name,
"type": "qweb",
}
)
env["website.page"].create(
{
"name": new_website_page.name,
"url": new_website_page.url,
"view_id": view_id.id,
"is_published": True,
"website_id": website_id.id,
"website_indexed": True,
"website_published": True,
}
)


def post_init_hook(cr, registry):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
# In v15 the default page was changed to account.account_terms_conditions_page
is_account_installed = (
env["ir.module.module"].search_count(
[("name", "=", "account"), ("state", "=", "installed")]
)
> 0
)
if is_account_installed:
_merge_views(env, ["account.account_terms_conditions_page"])
Loading

0 comments on commit ccf9155

Please sign in to comment.