Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] website_local_font: Migration to 16.0 #1051

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup/website_local_font/odoo/addons/website_local_font
6 changes: 6 additions & 0 deletions setup/website_local_font/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,
)
114 changes: 114 additions & 0 deletions website_local_font/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
==================
Website Local Font
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:21948d7b105e692895d067c8fee8367e630601f87e0a96393bed77d7fbf1a58b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-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_local_font
: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_local_font
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=16.0
:alt: Try me on Runboat

|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.

The fonts can be deleted as well if not needed anymore.

**Table of contents**

.. contents::
:local:

Usage
=====

To upload local fonts and use it for the website, you need to :

1.Go to website (with editor enabled),click on 'Edit' and go to 'THEMES' section.Under Font Family, you would find an option 'Add a Local Font'.

.. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/AddALocalFontOption.png

2.When you click on the 'Add a Local Font' option, a wizard would open with two fields- 'Font File' and 'Font Name'.Upload the file with one of the supported file formats and the font name would be automatically updated based on the file.You can update the name or leave it as it is.

.. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/SaveTheFont.png

3.Click on 'Save & Reload' Button, you will see the font is applied to the elements of the website.

.. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/FontAppliedOnWebsite.png

4.If you want to see the list of local fonts or delete the locally uploaded fonts,click on 'Edit' on website and go to 'THEMES' section.Under Font Family, you would find the newly added font.

.. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/NewlyAddedFont.png

5.If you want to delete this locally added font , you can click on the delete icon next to it.Once, you click on the delete icon, it would open up a confirmation dialog.

.. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/DeleteFontConfirmation.png

6.Once you click on 'Ok' button, the page would be refreshed and you would see the font is changed for the website and also the font is not found in the list.

.. image:: https://raw.githubusercontent.com/OCA/website/16.0/website_local_font/static/description/FontDeleted.png

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/website/issues/new?body=module:%20website_local_font%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

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_local_font>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions website_local_font/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
32 changes: 32 additions & 0 deletions website_local_font/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2023 Onestein- Anjeel Haria
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

{
"name": "Website Local Font",
"summary": "Allows to add local fonts on Odoo website",
"version": "16.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/website",
"author": "Onestein, Odoo Community Association (OCA)",
"license": "LGPL-3",
"installable": True,
"depends": ["website"],
"assets": {
"website.assets_wysiwyg": [
"website_local_font/static/src/js/snippets.options.js",
],
"web._assets_primary_variables": [
("prepend", "website_local_font/static/src/scss/primary_variables.scss"),
],
"web._assets_secondary_variables": [
(
"replace",
"website/static/src/scss/secondary_variables.scss",
"website_local_font/static/src/scss/secondary_variables.scss",
),
],
"web.assets_backend": [
"website_local_font/static/src/xml/website.editor.xml",
],
},
}
Binary file added website_local_font/examples/AmaticSC-Bold.woff
Binary file not shown.
Binary file not shown.
Binary file added website_local_font/examples/Trueno-wml2.otf
Binary file not shown.
2 changes: 2 additions & 0 deletions website_local_font/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import assets
from . import ir_attachment
35 changes: 35 additions & 0 deletions website_local_font/models/assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2023 Onestein - Anjeel Haria
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import re

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
"""
delete_attachment_id = values.pop("delete-local-font-attachment-id", None)
if delete_attachment_id:
delete_attachment_id = int(delete_attachment_id)
self.env["ir.attachment"].search(
[
"|",
("id", "=", delete_attachment_id),
("original_id", "=", delete_attachment_id),
]
).unlink()

local_fonts = values.get("local-fonts")
if local_fonts and local_fonts != "null":
local_fonts = dict(re.findall(r"'([^']+)': '?(\d*)", local_fonts))
for font_name in local_fonts:
if local_fonts[font_name]:
local_fonts[font_name] = int(local_fonts[font_name])
values["local-fonts"] = str(local_fonts).replace("{", "(").replace("}", ")")
return super(Assets, self).make_scss_customization(url, values)
47 changes: 47 additions & 0 deletions website_local_font/models/ir_attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2023 Onestein - Anjeel Haria
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


import base64

from odoo import models


class Attachment(models.Model):
_inherit = "ir.attachment"

def add_local_font(self, font_name, extension, file_data):
font_attachment = self.create(
{
"name": f"local-font-{font_name}",
"type": "binary",
"datas": file_data,
"mimetype": "font/" + extension,
"public": True,
}
)
if extension == "otf":
font_format = "opentype"
elif extension == "ttf":
font_format = "truetype"
else:
font_format = extension
src = "url(/web/content/%s/%s) format('%s')" % (
font_attachment.id,
f"local-font-{font_name}",
font_format,
)
file_string = (
"@font-face { \n" " font-family: %s; \n" "src:%s; \n" "}" % (font_name, src)
)
font_css_attachment = self.create(
{
"datas": base64.b64encode(file_string.encode("utf-8")),
"name": f"{font_name} (local-font)",
"type": "binary",
"mimetype": "text/css",
"public": True,
}
)
font_attachment.original_id = font_css_attachment.id
return font_css_attachment.id
3 changes: 3 additions & 0 deletions website_local_font/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Onestein <https://www.onestein.nl>`_:

* Anjeel Haria
8 changes: 8 additions & 0 deletions website_local_font/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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.

The fonts can be deleted as well if not needed anymore.
25 changes: 25 additions & 0 deletions website_local_font/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
To upload local fonts and use it for the website, you need to :

1.Go to website (with editor enabled),click on 'Edit' and go to 'THEMES' section.Under Font Family, you would find an option 'Add a Local Font'.

.. image:: ../static/description/AddALocalFontOption.png

2.When you click on the 'Add a Local Font' option, a wizard would open with two fields- 'Font File' and 'Font Name'.Upload the file with one of the supported file formats and the font name would be automatically updated based on the file.You can update the name or leave it as it is.

.. image:: ../static/description/SaveTheFont.png

3.Click on 'Save & Reload' Button, you will see the font is applied to the elements of the website.

.. image:: ../static/description/FontAppliedOnWebsite.png

4.If you want to see the list of local fonts or delete the locally uploaded fonts,click on 'Edit' on website and go to 'THEMES' section.Under Font Family, you would find the newly added font.

.. image:: ../static/description/NewlyAddedFont.png

5.If you want to delete this locally added font , you can click on the delete icon next to it.Once, you click on the delete icon, it would open up a confirmation dialog.

.. image:: ../static/description/DeleteFontConfirmation.png

6.Once you click on 'Ok' button, the page would be refreshed and you would see the font is changed for the website and also the font is not found in the list.

.. image:: ../static/description/FontDeleted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Loading
Loading