Skip to content

Commit

Permalink
[MIG] website_local_font: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Reyes4711-S73 committed Jul 28, 2023
1 parent 44bdb33 commit 68c778a
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 13 deletions.
101 changes: 101 additions & 0 deletions website_local_font/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
==================
Website Local Font
==================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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/16.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-16-0/website-16-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/16.0
:alt: Try me on Runbot

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

This module allows to add local fonts on Odoo website.

By default,Odoo only allows to upload fonts available from Google(fonts.google.com) and
they can be made available locally or from Google's server in addition to the fonts
made available via website theme modules.But there's no option to upload and have local
fonts available across all website themes.

To overcome this limitation, this module has been developed to allow users to upload
proprietary (or custom) fonts in the most widely used font formats - otf,ttf,woff and
woff2 and make it available across all website themes.

**Table of contents**

.. contents::
:local:

Usage
=====

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

This legal page is complementary to the account terms.

If you install this module with account installed too, the added page will take on a
complementary function to /terms of account, but never replace the function of the page.



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:%2016.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
~~~~~~~

* Onestein

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

* `Onestein <https://www.onestein.nl/>`_:

* Anjeel Haria

* `Studio73 <https://www.studio73.es>`_:

* Carlos Reyes


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/16.0/website_legal_page>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 4 additions & 1 deletion website_local_font/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Website Local Font",
"summary": "Allows to add local fonts on Odoo website",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/website",
"author": "Onestein, Odoo Community Association (OCA)",
Expand All @@ -25,5 +25,8 @@
"website_local_font/static/src/scss/secondary_variables.scss",
),
],
"web.assets_backend": [
"website_local_font/static/src/xml/website.editor.xml",
],
},
}
3 changes: 2 additions & 1 deletion website_local_font/models/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import re

from odoo import models
from odoo import api, models


class Assets(models.AbstractModel):
_inherit = "web_editor.assets"

@api.model
def make_scss_customization(self, url, values):
"""
Added handling for local fonts deletion and addition in scss
Expand Down
Binary file added website_local_font/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 4 additions & 6 deletions website_local_font/static/src/js/snippets.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ odoo.define("website_local_font.editor.snippets.options", function (require) {
*/
start: async function () {
await this._super(...arguments);
$(this.menuEl).empty();
const style = window.getComputedStyle(document.documentElement);
const nbFonts = parseInt(
weUtils.getCSSVariableValue("number-of-fonts", style)
);
const nbFonts =
parseInt(weUtils.getCSSVariableValue("number-of-fonts", style)) || [];
const localFontsProperty = weUtils.getCSSVariableValue(
"local-fonts",
style
Expand All @@ -55,6 +53,7 @@ odoo.define("website_local_font.editor.snippets.options", function (require) {
this.menuEl.appendChild(fontEl);
});
if (this.localFonts.length) {
console.log(this.localFonts);
const localFontsEls = fontEls.splice(-this.localFonts.length);
localFontsEls.forEach((el, index) => {
$(el).append(
Expand Down Expand Up @@ -89,7 +88,6 @@ odoo.define("website_local_font.editor.snippets.options", function (require) {
);
});
}

$(this.menuEl).append(
$(
core.qweb.render("website.add_google_font_btn", {
Expand Down Expand Up @@ -221,9 +219,9 @@ odoo.define("website_local_font.editor.snippets.options", function (require) {
if (!save) {
return;
}

// Remove Local font
const localFontIndex = parseInt(ev.target.dataset.fontIndex);
console.log(localFontIndex);
const localFont = this.localFonts[localFontIndex].split(":");
const localFontName = localFont[0];
values["delete-local-font-attachment-id"] = localFont[1];
Expand Down
4 changes: 3 additions & 1 deletion website_local_font/static/src/xml/website.editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
t-att-aria-label="delete_font_title"
t-att-title="delete_font_title"
t-att-data-font-index="index"
/>
>
Delete this font
</i>
</t>

<t t-name="website.add_local_font_btn">
Expand Down
9 changes: 5 additions & 4 deletions website_local_font/tests/test_website_local_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def test_font_file_import(font_file_name):


class TestIrAttachment(common.TransactionCase):
def setUp(self):
super().setUp()
self.IrAttachment = self.env["ir.attachment"]
self.Web_Editor_Assets = self.env["web_editor.assets"]
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.IrAttachment = cls.env["ir.attachment"]
cls.Web_Editor_Assets = cls.env["web_editor.assets"]

def test_add_local_font_otf(self):
font_css_attachment_id = self.IrAttachment.add_local_font(
Expand Down

0 comments on commit 68c778a

Please sign in to comment.