Skip to content
Merged
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 website_blog_mgmt/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Contributors
------------

* Laurent Mignon <laurent.mignon@acsone.eu>
* Sergio Teruel <sergio@incaser.es>

Maintainer
----------
Expand Down
22 changes: 3 additions & 19 deletions website_blog_mgmt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Laurent Mignon
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from . import controllers
from .post_init import post_init
27 changes: 6 additions & 21 deletions website_blog_mgmt/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Laurent Mignon
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


{
'name': 'Website blog Management',
'version': '8.0.1.0.0',
'version': '9.0.1.0.0',
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
'website': 'http://www.acsone.eu',
'license': 'AGPL-3',
Expand All @@ -33,7 +18,7 @@
'views/website_blog_views.xml',
'views/website_blog_templates.xml',
],
'installable': False,
'installable': True,
'auto_install': False,
'post_init_hook': 'post_init',
}
22 changes: 3 additions & 19 deletions website_blog_mgmt/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Laurent Mignon
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import main
70 changes: 39 additions & 31 deletions website_blog_mgmt/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# -*- coding: utf-8 -*-
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website_blog.controllers.main import WebsiteBlog
from openerp.addons.website_blog.controllers.main import QueryURL
from openerp.addons.website.models.website import slug, unslug


class WebsiteBlog(WebsiteBlog):
Expand All @@ -13,9 +16,8 @@ class WebsiteBlog(WebsiteBlog):
@http.route([
'/blog/<model("blog.blog"):blog>',
'/blog/<model("blog.blog"):blog>/page/<int:page>',
'/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>',
'/blog/<model("blog.blog"):blog>/tag/<model("blog.tag")' +
':tag>/page/<int:page>',
'/blog/<model("blog.blog"):blog>/tag/<string:tag>',
'/blog/<model("blog.blog"):blog>/tag/<string:tag>/page/<int:page>',
], type='http', auth="public", website=True)
def blog(self, blog=None, tag=None, page=1, **opt):
""" Prepare all values to display the blog.
Expand All @@ -25,42 +27,36 @@ def blog(self, blog=None, tag=None, page=1, **opt):
- 'blog': current blog
- 'blogs': all blogs for navigation
- 'pager': pager of posts
- 'tag': current tag
- 'active_tag_ids' : list of active tag ids,
- 'tags_list' : function to built the comma-separated tag list ids
(for the url),
- 'tags': all tags, for navigation
- 'nav_list': a dict [year][month] for archives navigation
- 'date': date_begin optional parameter, used in archives navigation
- 'blog_url': help object to create URLs
"""
date_begin, date_end = opt.get('date_begin'), opt.get('date_end')

cr, uid, context = request.cr, request.uid, request.context
blog_post_obj = request.registry['blog.post']

blog_obj = request.registry['blog.blog']
blog_ids = blog_obj.search(
cr, uid, [], order="create_date asc", context=context)
blogs = blog_obj.browse(cr, uid, blog_ids, context=context)

blogs = request.env['blog.blog'].search([], order="create_date asc")
# build the domain for blog post to display
domain = []
# retrocompatibility to accept tag as slug
active_tag_ids = tag and map(
int, [unslug(t)[1] for t in tag.split(',')]) or []
if active_tag_ids:
domain += [('tag_ids', 'in', active_tag_ids)]
if blog:
domain += [('blog_id', '=', blog.id)]
if tag:
domain += [('tag_ids', 'in', tag.id)]
if date_begin and date_end:
domain += [("website_publication_date", ">=", date_begin),
("website_publication_date", "<=", date_end)]
domain += [
("website_publication_date", ">=", date_begin),
("website_publication_date", "<=", date_end),
]

blog_url = QueryURL(
'', ['blog', 'tag'], blog=blog, tag=tag,
date_begin=date_begin, date_end=date_end)
post_url = QueryURL(
'', ['blogpost'], tag_id=tag and tag.id or None,
date_begin=date_begin, date_end=date_end)

blog_post_ids = blog_post_obj.search(
cr, uid, domain, context=context)
blog_posts = blog_post_obj.browse(
cr, uid, blog_post_ids, context=context)
'', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin,
date_end=date_end)
blog_posts = request.env['blog.post'].search(domain)

pager = request.website.pager(
url=blog_url(),
Expand All @@ -72,18 +68,30 @@ def blog(self, blog=None, tag=None, page=1, **opt):
pager_end = page * self._blog_post_per_page
blog_posts = blog_posts[pager_begin:pager_end]

tags = blog.all_tags()[blog.id]
all_tags = blog.all_tags()[blog.id]

# Function to create the string list of tag ids, and toggle a
# given one. Used in the 'Tags Cloud' template.
def tags_list(tag_ids, current_tag):
tag_ids = list(tag_ids) # required to avoid using the same list
if current_tag in tag_ids:
tag_ids.remove(current_tag)
else:
tag_ids.append(current_tag)
tag_ids = request.env['blog.tag'].browse(tag_ids).exists()
return ','.join(map(slug, tag_ids))

values = {
'blog': blog,
'blogs': blogs,
'tags': tags,
'tag': tag,
'main_object': blog,
'tags': all_tags,
'active_tag_ids': active_tag_ids,
'tags_list': tags_list,
'blog_posts': blog_posts,
'pager': pager,
'nav_list': self.nav_list(),
'nav_list': self.nav_list(blog),
'blog_url': blog_url,
'post_url': post_url,
'date': date_begin,
}
response = request.website.render(
Expand Down
22 changes: 3 additions & 19 deletions website_blog_mgmt/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Laurent Mignon
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import website_blog
23 changes: 3 additions & 20 deletions website_blog_mgmt/models/website_blog.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Laurent Mignon
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, fields, api
from datetime import datetime
Expand All @@ -28,7 +11,7 @@ class BlogPost(models.Model):
_order = 'website_publication_date DESC, id DESC'

website_publication_date = fields.Datetime(
string='Published on', index=True, readonly=False)
string='Published on', index=True)

def _process_publication_date(self, vals):
"""Check if a publication date is given and compute the
Expand Down
21 changes: 2 additions & 19 deletions website_blog_mgmt/post_init.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Laurent Mignon
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


def post_init(cr, registry):
Expand Down
21 changes: 2 additions & 19 deletions website_blog_mgmt/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Laurent Mignon
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from. import test_website_blog_flow
21 changes: 2 additions & 19 deletions website_blog_mgmt/tests/test_website_blog_flow.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Laurent Mignon
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import datetime
from openerp.addons.website_blog.tests.common import TestWebsiteBlogCommon
Expand Down
6 changes: 4 additions & 2 deletions website_blog_mgmt/views/website_blog_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<openerp>
<data>
<template id="blog_post_short" inherit_id="website_blog.blog_post_short">
<xpath expr="//span[@t-field='blog_post.create_date']" position="replace">
<span t-field="blog_post.website_publication_date" t-field-options='{"format": "MMMM yyyy"}' />
<xpath expr="//span[@t-field='blog_post.create_date']"
position="replace">
<span t-field="blog_post.website_publication_date"
t-field-options='{"format": "MMMM yyyy"}'/>
</xpath>
</template>
</data>
Expand Down