forked from OCA/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[9.0][website_blog_excerpt_img] Migrate, LGPL. (OCA#298)
* [8.0][website_blog_excerpt_img] New layout for blog. Add an excerpt and an image taken from the post to the blog summary page. To make this work, these open PR need to be merged: - OCA/server-tools#354 - OCA/server-tools#355 * Default value for `background_image` is usually something like `http://localhost/blog/our-news-1/post/blog-post-title-3?enable_editor=1`, not empty, so fixing here to avoid failure loading empty covers. * Simpler logic and better layout in phones. Fix bug in generated images, add convenient classes. The output of some images was a generator instead of an URL. I add excerpt-txt and excerpt-img classes for make life easier for themes. Add basic styling. All images now have the same height, and excerpts are 80 words long, which mostly matches the image height. Update for upstream module rename. * OCA Transbot updated translations from Transifex * [9.0][website_blog_excerpt_img] Migrate, LGPL. Relicensed, migrated, new tests.
- Loading branch information
Showing
15 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
|
||
======================= | ||
Excerpt + Image in Blog | ||
======================= | ||
|
||
This module extends the functionality of blogs to support having a more | ||
attractive layout that automatically displays an excerpt of each post, a "Read | ||
more" button and an image. | ||
|
||
Installation | ||
============ | ||
|
||
To install this module, you need to: | ||
|
||
* Install `OCA/server-tools <https://github.com/OCA/server-tools>`_. | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
* Go to your blog. | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/186/9.0 | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* Right now, it will display the cover image if available, and an image | ||
extracted from the post body otherwise. It would be nice to let the web admin | ||
choose that, or even better to display a carousel with all images from the | ||
post. | ||
|
||
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. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Jairo Llopis <[email protected]> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
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. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Jairo Llopis <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
{ | ||
"name": "Excerpt + Image in Blog", | ||
"summary": "New layout for blog summary, including an excerpt and image", | ||
"version": "9.0.1.0.0", | ||
"category": "Website", | ||
"website": "https://grupoesoc.es", | ||
"author": "Grupo ESOC Ingeniería de Servicios, " | ||
"Odoo Community Association (OCA)", | ||
"license": "LGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"images": [ | ||
"images/style-default.png", | ||
], | ||
"depends": [ | ||
"website_blog", | ||
"html_image_url_extractor", | ||
"html_text", | ||
], | ||
"data": [ | ||
"templates/assets.xml", | ||
"templates/blog.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * website_blog_excerpt_img | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 8.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2016-02-11 12:37+0000\n" | ||
"PO-Revision-Date: 2016-02-11 13:38+0100\n" | ||
"Last-Translator: Jairo Llopis <[email protected]>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: \n" | ||
"Language: es\n" | ||
"X-Generator: Poedit 1.8.6\n" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "Read more" | ||
msgstr "Leer más" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "col-xs-10" | ||
msgstr "col-xs-10" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "mb32 row" | ||
msgstr "mb32 row" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "text-muted col-xs-12 mb16" | ||
msgstr "text-muted col-xs-12 mb16" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * website_blog_excerpt_img | ||
# | ||
# Translators: | ||
# Christophe CHAUVET <[email protected]>, 2016 | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 8.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2016-07-29 17:03+0000\n" | ||
"PO-Revision-Date: 2016-07-29 17:03+0000\n" | ||
"Last-Translator: Christophe CHAUVET <[email protected]>, 2016\n" | ||
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Language: fr\n" | ||
"Plural-Forms: nplurals=2; plural=(n > 1);\n" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "Read more" | ||
msgstr "Lire plus" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "col-xs-10" | ||
msgstr "col-xs-10" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "mb32 row" | ||
msgstr "mb32 row" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "text-muted col-xs-12 mb16" | ||
msgstr "text-muted col-xs-12 mb16" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * website_blog_excerpt_img | ||
# | ||
# Translators: | ||
# Matjaž Mozetič <[email protected]>, 2016 | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 8.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2016-06-23 03:09+0000\n" | ||
"PO-Revision-Date: 2016-06-23 03:09+0000\n" | ||
"Last-Translator: Matjaž Mozetič <[email protected]>, 2016\n" | ||
"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Language: sl\n" | ||
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "Read more" | ||
msgstr "Preberi več" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "col-xs-10" | ||
msgstr "col-xs-10" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "mb32 row" | ||
msgstr "mb32 row" | ||
|
||
#. module: website_blog_excerpt_img | ||
#: view:website:website_blog.blog_post_short | ||
msgid "text-muted col-xs-12 mb16" | ||
msgstr "text-muted col-xs-12 mb16" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Jairo Llopis <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import blog_post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Jairo Llopis <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
import json | ||
from openerp import models | ||
|
||
|
||
class BlogPost(models.Model): | ||
_inherit = "blog.post" | ||
|
||
def main_image(self): | ||
"""Get blog's main image URL.""" | ||
Converter = self.env['ir.fields.converter'] | ||
html = self.content | ||
# Get a dictionary of properties, avoiding possible malformed ones | ||
try: | ||
properties = json.loads(self.cover_properties) | ||
except (TypeError, ValueError): | ||
properties = dict() | ||
# Prepend cover image to post content, if there is one | ||
cover = properties.pop("background-image", "none") | ||
if cover and cover != "none": | ||
html = u"<div style={q}background-image:{}{q}/>{}".format( | ||
cover, | ||
html, | ||
q='"' if '"' not in cover else "'", | ||
) | ||
# Return the first found image URL or None | ||
try: | ||
return next(Converter.imgs_from_html(html, 1)) | ||
except StopIteration: | ||
return None | ||
|
||
def content_excerpt(self, length=80): | ||
"""Get the blog post content excerpt.""" | ||
return self.env['ir.fields.converter'].text_from_html( | ||
self.content, | ||
length, | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions
10
website_blog_excerpt_img/static/src/css/website_blog_excerpt_img.sass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/*! Copyright 2016 Jairo Llopis <[email protected]> | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
.website_blog | ||
.excerpt-img .img | ||
height: 15em | ||
width: 100% | ||
object: | ||
fit: cover | ||
position: center |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). --> | ||
|
||
<odoo> | ||
|
||
<template id="assets_frontend" inherit_id="website_blog.assets_frontend"> | ||
<xpath expr="."> | ||
<link | ||
rel="stylesheet" | ||
href="/website_blog_excerpt_img/static/src/css/website_blog_excerpt_img.sass"/> | ||
</xpath> | ||
</template> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). --> | ||
|
||
<odoo> | ||
|
||
<template id="blog_post_short" | ||
inherit_id="website_blog.blog_post_short"> | ||
<!-- Entries are Bootstrap rows --> | ||
<xpath expr="//div[@t-as='blog_post']" position="attributes"> | ||
<attribute name="class">mb32 row</attribute> | ||
</xpath> | ||
<xpath expr="//h2/.." position="attributes"> | ||
<attribute name="class">col-xs-10</attribute> | ||
</xpath> | ||
<xpath expr="//div[@name='blog_post_data']/.." position="attributes"> | ||
<attribute name="class">text-muted col-xs-12 mb16</attribute> | ||
</xpath> | ||
|
||
<!-- Excerpt, image, read more button --> | ||
<xpath expr="//div[@name='blog_post_data']/.." position="after"> | ||
<t t-set="image_url" t-value="blog_post.main_image()"/> | ||
|
||
<div t-attf-class="excerpt-txt col-sm-#{7 if image_url else 12}"> | ||
<p t-esc="blog_post.content_excerpt()"/> | ||
<p> | ||
<a t-attf-href="/blog/#{slug(blog_post.blog_id)}/post/#{slug(blog_post)}" | ||
class="btn btn-primary"> | ||
Read more | ||
</a> | ||
</p> | ||
</div> | ||
<div t-if="image_url" class="col-sm-5 text-center excerpt-img"> | ||
<!-- Use cover image if available --> | ||
<img class="img img-responsive img-thumbnail" | ||
t-att-src="image_url"/> | ||
</div> | ||
</xpath> | ||
</template> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Jairo Llopis <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import test_html |
Oops, something went wrong.