<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-Today OpenERP SA (<http://www.openerp.com>).
#
#    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/>.
#
##############################################################################


from openerp import tools
from openerp import SUPERUSER_ID
from openerp.osv import osv, fields
from openerp.tools.translate import _

import difflib


class BlogCategory(osv.Model):
    _name = 'blog.category'
    _description = 'Blog Category'
    _inherit = ['mail.thread', 'website.seo.metadata']
    _order = 'name'

    _columns = {
        'name': fields.char('Name', required=True),
        'description': fields.text('Description'),
        'blog_post_ids': fields.one2many(
            'blog.post', 'category_id',
            'Blogs',
        ),
    }


class BlogTag(osv.Model):
    _name = 'blog.tag'
    _description = 'Blog Tag'
    _inherit = ['website.seo.metadata']
    _order = 'name'

    _columns = {
        'name': fields.char('Name', required=True),
        'blog_post_ids': fields.many2many(
            'blog.post', string='Posts',
        ),
    }


class BlogPost(osv.Model):
    _name = "blog.post"
    _description = "Blog Post"
    _inherit = ['mail.thread', 'website.seo.metadata']
    _order = 'write_date DESC'
    # maximum number of characters to display in summary
    _shorten_max_char = 250

    def get_shortened_content(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for page in self.browse(cr, uid, ids, context=context):
            try:
                body_short = tools.html_email_clean(
                    page.content,
                    remove=True,
                    shorten=True,
                    max_length=self._shorten_max_char,
                    expand_options={
                        'oe_expand_container_tag': 'div',
                        'oe_expand_container_class': 'oe_mail_expand text-center',
                        'oe_expand_container_content': '',
                        'oe_expand_a_href': '/blog/%d/%d' % (page.category_id.id, page.id),
                        'oe_expand_a_class': 'oe_mail_expand btn btn-info',
                        'oe_expand_separator_node': 'br',
                    },
                    protect_sections=True,
                )
            except Exception:
                body_short = False
            res[page.id] = body_short
        return res

    _columns = {
        'name': fields.char('Title', required=True),
        'category_id': fields.many2one(
            'blog.category', 'Category',
            required=True, ondelete='cascade',
        ),
        'tag_ids': fields.many2many(
            'blog.tag', string='Tags',
        ),
        'content': fields.html('Content'),
        'shortened_content': fields.function(
            get_shortened_content,<commit_msg>[FIX] website_blog: read_more link was wrong, leading to a 404. The website_blog route is blog/<blog_id>, nothing related to category anymore.<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-Today OpenERP SA (<http://www.openerp.com>).
#
#    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/>.
#
##############################################################################


from openerp import tools
from openerp import SUPERUSER_ID
from openerp.osv import osv, fields
from openerp.tools.translate import _

import difflib


class BlogCategory(osv.Model):
    _name = 'blog.category'
    _description = 'Blog Category'
    _inherit = ['mail.thread', 'website.seo.metadata']
    _order = 'name'

    _columns = {
        'name': fields.char('Name', required=True),
        'description': fields.text('Description'),
        'blog_post_ids': fields.one2many(
            'blog.post', 'category_id',
            'Blogs',
        ),
    }


class BlogTag(osv.Model):
    _name = 'blog.tag'
    _description = 'Blog Tag'
    _inherit = ['website.seo.metadata']
    _order = 'name'

    _columns = {
        'name': fields.char('Name', required=True),
        'blog_post_ids': fields.many2many(
            'blog.post', string='Posts',
        ),
    }


class BlogPost(osv.Model):
    _name = "blog.post"
    _description = "Blog Post"
    _inherit = ['mail.thread', 'website.seo.metadata']
    _order = 'write_date DESC'
    # maximum number of characters to display in summary
    _shorten_max_char = 250

    def get_shortened_content(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for page in self.browse(cr, uid, ids, context=context):
            try:
                body_short = tools.html_email_clean(
                    page.content,
                    remove=True,
                    shorten=True,
                    max_length=self._shorten_max_char,
                    expand_options={
                        'oe_expand_container_tag': 'div',
                        'oe_expand_container_class': 'oe_mail_expand text-center',
                        'oe_expand_container_content': '',
                        'oe_expand_a_href': '/blog/%d/' % page.id,
                        'oe_expand_a_class': 'oe_mail_expand btn btn-info',
                        'oe_expand_separator_node': 'br',
                    },
                    protect_sections=True,
                )
            except Exception:
                body_short = False
            res[page.id] = body_short
        return res

    _columns = {
        'name': fields.char('Title', required=True),
        'category_id': fields.many2one(
            'blog.category', 'Category',
            required=True, ondelete='cascade',
        ),
        'tag_ids': fields.many2many(
            'blog.tag', string='Tags',
        ),
        'content': fields.html('Content'),
        'shortened_content': fields.function(
            get_shortened_content,
{'fraction_non_alphanumeric': 0.1444141689373297, 'fraction_numerical': 0.003950953678474115, 'mean_word_length': 2.280160857908847, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '921230', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1980, 'n_words': 551}