[ADD] document_reindex

This commit is contained in:
Holger Brunn 2015-05-05 16:26:46 +02:00
parent 420ae2218a
commit ae3ad89e6f
9 changed files with 247 additions and 0 deletions

View File

@ -0,0 +1,33 @@
Reindex documents
=================
This module allows you to reindex documents in case they were uploaded when the right configuration for indexation was missing.
Usage
=====
To reindex a single document, open its form and click the `Reindex document` button.
To reindex all documents, go to Settings / Configuration / Knowledge, check the box `Reindex all documents` or `Reindex all unindexed documents` and click apply. Those are done in the background, so watch your logs for the process to finish.
Credits
=======
Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
* Icon courtesy of http://www.picol.org (refresh.svg) and https://github.com/odoo/odoo/blob/8.0/addons/knowledge/static/description/icon.png
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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 http://odoo-community.org.

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# 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 . import models

View File

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# 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/>.
#
##############################################################################
{
"name": "Reindex documents",
"version": "1.0",
"author": "Therp BV",
"license": "AGPL-3",
"category": "Knowledge Management",
"summary": "Reindex your already uploaded documents",
"depends": [
'document',
],
"data": [
"views/knowledge_config_settings.xml",
"views/ir_attachment.xml",
],
"auto_install": False,
"installable": True,
"application": False,
"external_dependencies": {
'python': [],
},
}

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# 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 . import ir_attachment
from . import knowledge_config_settings

View File

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
#
# 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 models, fields, api
class IrAttachment(models.Model):
_inherit = 'ir.attachment'
@api.multi
def document_reindex(self):
for this in self:
if not this.datas:
continue
mimetype, indexed_content = this._index(
this.datas.decode('base64'), this.datas_fname, this.file_type)
this.write({
'file_type': mimetype,
'index_content': indexed_content,
})
@api.model
def document_reindex_all(self):
self.search([('datas', '!=', False)]).document_reindex()
@api.model
def document_reindex_unindexed(self):
self.search([
('datas', '!=', False),
'|',
('index_content', '=', False),
('index_content', '=', ''),
]).document_reindex()

View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
#
# 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 models, fields, api
class KnowledgeConfigSettings(models.TransientModel):
_inherit = 'knowledge.config.settings'
document_reindex_all = fields.Boolean('Reindex all documents')
document_reindex_unindexed = fields.Boolean('Reindex unindexed documents')
@api.one
def set_document_reindex(self):
if self.document_reindex_all:
self.document_reindex_create_cronjob('document_reindex_all')
if self.document_reindex_unindexed:
self.document_reindex_create_cronjob('document_reindex_unindexed')
@api.multi
def document_reindex_create_cronjob(self, function):
self.env['ir.cron'].create({
'name': function,
'model': 'ir.attachment',
'function': function,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_attachment_form" model="ir.ui.view">
<field name="model">ir.attachment</field>
<field name="inherit_id" ref="base.view_attachment_form" />
<field name="arch" type="xml">
<sheet position="before">
<header>
<button type="object" name="document_reindex" string="Reindex document" attrs="{'invisible': [('datas', '=', False)]}" class="oe_highlight" groups="base.group_document_user" />
</header>
</sheet>
</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_knowledge_configuration" model="ir.ui.view">
<field name="model">knowledge.config.settings</field>
<field name="inherit_id" ref="knowledge.view_knowledge_configuration" />
<field name="arch" type="xml">
<xpath expr="//group/div" position="inside">
<div attrs="{'invisible': [('document_reindex_unindexed', '=', True)]}">
<field name="document_reindex_all" class="oe_inline" />
<label for="document_reindex_all" />
</div>
<div attrs="{'invisible': [('document_reindex_all', '=', True)]}">
<field name="document_reindex_unindexed" class="oe_inline" />
<label for="document_reindex_unindexed" />
</div>
</xpath>
</field>
</record>
</data>
</openerp>