-
-
Notifications
You must be signed in to change notification settings - Fork 394
[9.0] document_page #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0901b0f
7bc4c07
ccb60b3
ffe3744
c380a68
d92441c
e3dc6d8
1c72749
fc55660
53870f0
8b52e66
f978d2a
e49136b
086e98a
8390365
9dbe6eb
72f9a4b
6f5c619
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
| :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
| :alt: License: AGPL-3 | ||
|
|
||
| ============= | ||
| Document Page | ||
| ============= | ||
|
|
||
| This module allows you to write web pages for internal documentation. | ||
|
|
||
| Installation | ||
| ============ | ||
|
|
||
| This module depends on module knowledge. So make sure to have it in your addons list. | ||
|
|
||
| Configuration | ||
| ============= | ||
|
|
||
| No configuration required | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| To use this module, you need to: | ||
|
|
||
| * Go to Knowledge menu | ||
| * Click on Categories to create the document's category you need with the template | ||
| * Click on Pages to create pages and select the previous category to use the template | ||
|
|
||
|
|
||
| .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
| :alt: Try me on Runbot | ||
| :target: https://runbot.odoo-community.org/runbot/118/9.0 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The target link should be https://runbot.odoo-community.org/runbot/118/9.0 You can also remove the comments. |
||
| Known issues / Roadmap | ||
| ====================== | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/Knowledge/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 `here <https://github.com/OCA/knowledge/issues/new?body=module:%20document_page%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| * Odoo SA <info@odoo.com> | ||
| * Savoir-faire Linux <support@savoirfairelinux.com> | ||
| * Gervais Naoussi <gervaisnaoussi@gmail.com> | ||
|
|
||
| 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 http://odoo-community.org. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # -*- coding: utf-8 -*- | ||
| ############################################################################## | ||
| # | ||
| # OpenERP, Open Source Management Solution | ||
| # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). | ||
| # | ||
| # 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 document_page | ||
| from . import document_page_history |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,14 @@ | |
| # | ||
| ############################################################################## | ||
| import logging | ||
| import difflib | ||
| from openerp import models, fields, api, _ | ||
| from openerp import models, fields, api | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class document_page(models.Model): | ||
| class DocumentPage(models.Model): | ||
| """This class is use to manage Document.""" | ||
|
|
||
| _name = "document.page" | ||
| _inherit = ['mail.thread'] | ||
| _description = "Document Page" | ||
|
|
@@ -99,6 +100,7 @@ class document_page(models.Model): | |
| ) | ||
|
|
||
| def _get_page_index(self, page, link=True): | ||
| """Return the index of a document.""" | ||
| index = [] | ||
| for subpage in page.child_ids: | ||
| index += ["<li>" + self._get_page_index(subpage) + | ||
|
|
@@ -112,6 +114,7 @@ def _get_page_index(self, page, link=True): | |
| return r | ||
|
|
||
| def _get_display_content(self): | ||
| """Return the content of a document.""" | ||
| for page in self: | ||
| if page.type == "category": | ||
| display_content = self._get_page_index(page, link=False) | ||
|
|
@@ -121,11 +124,13 @@ def _get_display_content(self): | |
|
|
||
| @api.onchange("parent_id") | ||
| def do_set_content(self): | ||
| """We Set it the right content to the new parent.""" | ||
| if self.parent_id and not self.content: | ||
| if self.parent_id.type == "category": | ||
| self.content = self.parent_id.content | ||
|
|
||
| def create_history(self, page_id, content): | ||
| """Create the first history of a newly created document.""" | ||
| history = self.env['document.page.history'] | ||
| return history.create({ | ||
| "content": content, | ||
|
|
@@ -134,7 +139,8 @@ def create_history(self, page_id, content): | |
|
|
||
| @api.multi | ||
| def write(self, vals): | ||
| result = super(document_page, self).write(vals) | ||
| """Write the content and set the history.""" | ||
| result = super(DocumentPage, self).write(vals) | ||
| content = vals.get('content') | ||
| if content: | ||
| for page in self: | ||
|
|
@@ -144,51 +150,9 @@ def write(self, vals): | |
| @api.model | ||
| @api.returns('self', lambda value: value.id) | ||
| def create(self, vals): | ||
| page_id = super(document_page, self).create(vals) | ||
| """Create the first history of a document.""" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few lines below, shouldn't
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @dreispt.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forget it. |
||
| page_id = super(DocumentPage, self).create(vals) | ||
| content = vals.get('content') | ||
| if content: | ||
| self.create_history(page_id.id, content) | ||
| return page_id | ||
|
|
||
|
|
||
| class document_page_history(models.Model): | ||
| _name = "document.page.history" | ||
| _description = "Document Page History" | ||
| _order = 'id DESC' | ||
| _rec_name = "create_date" | ||
|
|
||
| page_id = fields.Many2one('document.page', 'Page') | ||
| summary = fields.Char('Summary', size=256, select=True) | ||
| content = fields.Text("Content") | ||
| create_date = fields.Datetime("Date") | ||
| create_uid = fields.Many2one('res.users', "Modified By") | ||
|
|
||
| def getDiff(self, v1, v2): | ||
| text1 = self.browse(v1).content | ||
| text2 = self.browse(v2).content | ||
| line1 = line2 = '' | ||
| if text1: | ||
| line1 = text1.splitlines(1) | ||
| if text2: | ||
| line2 = text2.splitlines(1) | ||
| if (not line1 and not line2) or (line1 == line2): | ||
| return _('There are no changes in revisions.') | ||
| else: | ||
| diff = difflib.HtmlDiff() | ||
| return diff.make_table( | ||
| line1, line2, | ||
| "Revision-{}".format(v1), | ||
| "Revision-{}".format(v2), | ||
| context=True | ||
| ) | ||
|
|
||
| def __getattr__(self, attr): | ||
| """Return a dummy callabale""" | ||
| if attr in ['_sql', 'init', '_ids']: | ||
| raise AttributeError | ||
|
|
||
| _logger.warning( | ||
| "Trying to access attribute %s on document_page_history", | ||
| attr | ||
| ) | ||
| return (lambda *a, **b: None) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # -*- coding: utf-8 -*- | ||
| ############################################################################## | ||
| # | ||
| # OpenERP, Open Source Management Solution | ||
| # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). | ||
| # | ||
| # 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/>. | ||
| # | ||
| ############################################################################## | ||
| import logging | ||
| import difflib | ||
| from openerp import models, fields, _ | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class DocumentPageHistory(models.Model): | ||
| """This model is necessary to manage a document history.""" | ||
|
|
||
| _name = "document.page.history" | ||
| _description = "Document Page History" | ||
| _order = 'id DESC' | ||
| _rec_name = "create_date" | ||
|
|
||
| page_id = fields.Many2one('document.page', 'Page') | ||
| summary = fields.Char('Summary', select=True) | ||
| content = fields.Text("Content") | ||
| create_date = fields.Datetime("Date") | ||
| create_uid = fields.Many2one('res.users', "Modified By") | ||
|
|
||
| def getDiff(self, v1, v2): | ||
| """Return the difference between two version of document version.""" | ||
| text1 = self.browse(v1).content | ||
| text2 = self.browse(v2).content | ||
| line1 = line2 = '' | ||
| if text1: | ||
| line1 = text1.splitlines(1) | ||
| if text2: | ||
| line2 = text2.splitlines(1) | ||
| if (not line1 and not line2) or (line1 == line2): | ||
| return _('There are no changes in revisions.') | ||
| else: | ||
| diff = difflib.HtmlDiff() | ||
| return diff.make_table( | ||
| line1, line2, | ||
| "Revision-{}".format(v1), | ||
| "Revision-{}".format(v2), | ||
| context=True | ||
| ) | ||
|
|
||
| def __getattr__(self, attr): | ||
| """Return a dummy callabale.""" | ||
| if attr in ['_sql', 'init', '_ids']: | ||
| raise AttributeError | ||
|
|
||
| _logger.warning( | ||
| "Trying to access attribute %s on document_page_history", | ||
| attr | ||
| ) | ||
| return (lambda *a, **b: None) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why this is needed. Any idea @max3903 ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dreispt I don't know. Odoo SA made this module originally and they deprecated it in v8.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even me i don't understand if this is needed. Can i removed it?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do that. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <openerp> | ||
| <odoo> | ||
| <data noupdate="0"> | ||
| <record id="base.group_document_user" model="res.groups"> | ||
| <field name="users" eval="[(4, ref('base.user_root'))]"/> | ||
| </record> | ||
| </data> | ||
| </openerp> | ||
| </odoo> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@naousse You need an extra line before the list, otherwise rendering fails.