mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-15 11:42:56 -06:00
[ADD] document_reindex
This commit is contained in:
parent
420ae2218a
commit
ae3ad89e6f
33
document_reindex/README.rst
Normal file
33
document_reindex/README.rst
Normal 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.
|
21
document_reindex/__init__.py
Normal file
21
document_reindex/__init__.py
Normal 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
|
41
document_reindex/__openerp__.py
Normal file
41
document_reindex/__openerp__.py
Normal 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': [],
|
||||
},
|
||||
}
|
22
document_reindex/models/__init__.py
Normal file
22
document_reindex/models/__init__.py
Normal 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
|
50
document_reindex/models/ir_attachment.py
Normal file
50
document_reindex/models/ir_attachment.py
Normal 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()
|
43
document_reindex/models/knowledge_config_settings.py
Normal file
43
document_reindex/models/knowledge_config_settings.py
Normal 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,
|
||||
})
|
BIN
document_reindex/static/description/icon.png
Normal file
BIN
document_reindex/static/description/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
16
document_reindex/views/ir_attachment.xml
Normal file
16
document_reindex/views/ir_attachment.xml
Normal 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>
|
21
document_reindex/views/knowledge_config_settings.xml
Normal file
21
document_reindex/views/knowledge_config_settings.xml
Normal 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>
|
Loading…
Reference in New Issue
Block a user