page work in progress model
bzr revid: al@openerp.com-20120809131141-m9xqa24u96sbgna7
This commit is contained in:
parent
62827193a9
commit
b9286a8eeb
|
@ -29,72 +29,72 @@ class document_page(osv.osv):
|
|||
_description = "Document Page"
|
||||
_order = 'name'
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Title', size=256, select=True, required=True),
|
||||
'type':fields.selection([('normal','Content Page'), ('index','Index Page')], 'Type', help="Define the type of the document"),
|
||||
def _get_page_index(self, cr, uid, page):
|
||||
index == []
|
||||
for subpage in page.child_ids:
|
||||
index += ["<li>"+ self._get_page_index(cr, uid, subpage) +"</li>"]
|
||||
if index:
|
||||
index = "<ul>" + "".join(index) + "</ul>"
|
||||
else:
|
||||
index = page.title
|
||||
|
||||
'parent_id': fields.many2one('document.page', 'Section', select=1 , ondelete='set null'),
|
||||
def _get_display_content(self, cr, uid, ids, name, args, context=None):
|
||||
res = {}
|
||||
for page in self.browse(cr, uid, ids, context=context):
|
||||
if parent.type == "index":
|
||||
content = self._get_page_index(cr, uid, page)
|
||||
else:
|
||||
content = page.content
|
||||
res[page.id] = {
|
||||
'display_content': content
|
||||
}
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Title', required=True),
|
||||
'type':fields.selection([('content','Content Page'), ('index','Index Page')], 'Type', help="Page type"),
|
||||
|
||||
'parent_id': fields.many2one('document.page', 'Section'),
|
||||
'child_ids': fields.one2many('document.page', 'parent_id', 'Children'),
|
||||
|
||||
'display_content': fields.text('Displayed Content'),
|
||||
'content': fields.text("Content"),
|
||||
'display_content': fields.function(_get_display_content, string='Displayed Content', type='text'),
|
||||
|
||||
'history_ids': fields.one2many('document.page.history', 'document_id', 'History'),
|
||||
'menu_id': fields.many2one('ir.ui.menu', "Menu", readonly=True),
|
||||
|
||||
'create_date': fields.datetime("Created on", select=True, readonly=True),
|
||||
'create_uid': fields.many2one('res.users', 'Author', select=True, readonly=True),
|
||||
'write_date': fields.datetime("Modification Date", select=True, readonly=True),
|
||||
'write_uid': fields.many2one('res.users', "Last Contributor", select=True),
|
||||
'create_uid': fields.many2one('res.users', 'Author', select=True, readonly=True),
|
||||
|
||||
'index': fields.char('Index', size=256),
|
||||
'minor_edit': fields.boolean('Minor edit', select=True),
|
||||
'edit_summary': fields.char('Summary', size=256),
|
||||
'tags': fields.char('Keywords', size=1024, select=True),
|
||||
|
||||
}
|
||||
_defaults = {
|
||||
'type':'normal',
|
||||
'type':'content',
|
||||
}
|
||||
|
||||
def onchange_parent_id(self, cr, uid, ids, parent_id, content, context=None):
|
||||
if (not parent_id) or content:
|
||||
return {}
|
||||
grp = self.pool.get('document.page.type').browse(cr, uid, parent_id, context=context)
|
||||
template = grp.content_template
|
||||
try:
|
||||
s[-1] = str(int(s[-1])+1)
|
||||
except:
|
||||
pass
|
||||
return {
|
||||
'value':{
|
||||
'content': template,
|
||||
}
|
||||
}
|
||||
|
||||
def onchange_content(self, cr, uid, ids, content, context=None):
|
||||
if content:
|
||||
return {'value':{'summary': content}}
|
||||
return {}
|
||||
|
||||
def copy_data(self, cr, uid, id, default=None, context=None):
|
||||
return super(document_page2, self).copy_data(cr, uid, id, {'document_id': False}, context)
|
||||
res = {}
|
||||
if parent_id and not content:
|
||||
parent = self.browse(cr, uid, parent_id, context=context)
|
||||
if parent.type == "content":
|
||||
res['value'] = {
|
||||
'content': parent.content_template,
|
||||
}
|
||||
return res
|
||||
|
||||
def create_history(self, cr, uid, ids, vals, context=None):
|
||||
history_id = False
|
||||
history = self.pool.get('document.page.history')
|
||||
if vals.get('content'):
|
||||
res = {
|
||||
'content': vals.get('content', ''),
|
||||
'write_uid': uid,
|
||||
'document_id': ids[0],
|
||||
'summary':vals.get('edit_summary', '')
|
||||
}
|
||||
history_id = history.create(cr, uid, res)
|
||||
return history_id
|
||||
for i in ids:
|
||||
history = self.pool.get('document.page.history')
|
||||
if vals.get('content'):
|
||||
res = {
|
||||
'content': vals.get('content', ''),
|
||||
'page_id': i,
|
||||
}
|
||||
history.create(cr, uid, res)
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
document_id = super(document_page2, self).create(cr, uid, vals, context)
|
||||
self.create_history(cr, uid, [document_id], vals, context)
|
||||
page_id = super(document_page2, self).create(cr, uid, vals, context)
|
||||
self.create_history(cr, uid, [page_id], vals, context)
|
||||
return document_id
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
|
@ -102,23 +102,18 @@ class document_page(osv.osv):
|
|||
self.create_history(cr, uid, ids, vals, context)
|
||||
return result
|
||||
|
||||
|
||||
class document_page_history(osv.osv):
|
||||
_name = "document.page.history"
|
||||
_description = "Document Page History"
|
||||
_rec_name = "summary"
|
||||
_order = 'id DESC'
|
||||
_rec_name = "create_date"
|
||||
|
||||
_columns = {
|
||||
'document_id': fields.many2one('document.page', 'Document Page', select=True)
|
||||
'page_id': fields.many2one('document.page', 'Page'),
|
||||
'summary': fields.char('Summary', size=256, select=True),
|
||||
'content': fields.text("Content"),
|
||||
'create_date': fields.datetime("Date", select=True),
|
||||
'write_uid': fields.many2one('res.users', "Modify By", select=True),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'write_uid': lambda obj, cr, uid, context: uid,
|
||||
'create_date': fields.datetime("Date"),
|
||||
'create_uid': fields.many2one('res.users', "Modified By"),
|
||||
}
|
||||
|
||||
def getDiff(self, cr, uid, v1, v2, context=None):
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import document_page_page_open
|
||||
import document_page_make_index
|
||||
import document_page_create_menu
|
||||
import document_page_show_diff
|
||||
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
# -*- 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 osv import fields, osv
|
||||
from tools.translate import _
|
||||
|
||||
class document_page_make_index(osv.osv_memory):
|
||||
""" Create Index For Selected Page """
|
||||
|
||||
_name = "document.page.make.index"
|
||||
_description = "Create Index"
|
||||
|
||||
def document_page_do_index(self, cr, uid, ids, context=None):
|
||||
|
||||
""" Makes Index according to page hierarchy
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: list of document page index’s IDs
|
||||
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
data = context and context.get('active_ids', []) or []
|
||||
print 'data',tuple(data)
|
||||
if not data:
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
for index_obj in self.browse(cr, uid, ids, context=context):
|
||||
document_obj = self.pool.get('document.page')
|
||||
if not ids:
|
||||
return {}
|
||||
cr.execute('select id,index,parent_id from document_page where id in %s '\
|
||||
'and type=%s' ,(tuple(data),'index',))
|
||||
lst_all = cr.fetchall()
|
||||
ls_p = []
|
||||
ls_np =[]
|
||||
s_ids = {}
|
||||
p_ids = {}
|
||||
for m in lst_all:
|
||||
if m[2] == None:
|
||||
ls_np.append(m)
|
||||
if m[1]:
|
||||
s_ids[int(m[1])] = ls_np.index(m)+1
|
||||
if s_ids:
|
||||
document_obj.write(cr, uid, m[0], {'index':s_ids[int(m[1])]})
|
||||
if m[2]:
|
||||
ls_p.append(m)
|
||||
if m[1]:
|
||||
dict = {}
|
||||
for l in ls_p:
|
||||
if l[2] not in dict:
|
||||
dict[l[2]] = []
|
||||
dict[l[2]].append(l)
|
||||
else:
|
||||
dict[l[2]].append(l)
|
||||
|
||||
p_ids[m[1]] = str(m[2]) + "." + str(dict[m[2]].index(m)+1)
|
||||
if p_ids:
|
||||
document_obj.write(cr, uid, m[0], {'index':p_ids[m[1]]})
|
||||
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
document_page_make_index()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Create Index Form view -->
|
||||
|
||||
<record id="view_wiki_make_index" model="ir.ui.view">
|
||||
<field name="name">Create Index</field>
|
||||
<field name="model">document.page.make.index</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create Index" version="7.0">
|
||||
<label string="Want to create a Index on Selected Pages ? "/>
|
||||
<footer>
|
||||
<button name="document_page_do_index" string="Create Index" type="object" class="oe_highlight"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Create Index Action -->
|
||||
|
||||
<record id="action_view_wiki_make_index" model="ir.actions.act_window">
|
||||
<field name="name">Create Index</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">document.page.make.index</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<!-- Create Index Action Window -->
|
||||
|
||||
<act_window id="action_view_wiki_make_index_values"
|
||||
key2="client_action_multi" name="Create Index"
|
||||
res_model="document.page.make.index" src_model="document.page"
|
||||
view_mode="form" target="new" view_type="form" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,65 +0,0 @@
|
|||
# -*- 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 osv import osv
|
||||
|
||||
class document_page_page_open(osv.osv_memory):
|
||||
""" wizard Open Page """
|
||||
|
||||
_name = "document.page.page.open"
|
||||
_description = "wiz open page"
|
||||
|
||||
def open_document_page(self, cr, uid, ids, context=None):
|
||||
|
||||
""" Opens Wiki Page of Group
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of open wiki page’s IDs
|
||||
@return: dictionay of open wiki window on give group id
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
group_ids = context.get('active_ids', [])
|
||||
for group in self.pool.get('document.page.type').browse(cr, uid, group_ids, context=context):
|
||||
value = {
|
||||
'name': 'Document Page',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'res_model': 'document.page',
|
||||
'view_id': False,
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
if group.method == 'page':
|
||||
value['res_id'] = group.home.id
|
||||
elif group.method == 'list':
|
||||
value['view_type'] = 'form'
|
||||
value['view_mode'] = 'tree,form'
|
||||
elif group.method == 'tree':
|
||||
view_id = self.pool.get('ir.ui.view').search(cr, uid, [('name', '=', 'document.page.tree.children')])
|
||||
value['view_id'] = view_id
|
||||
value['domain'] = [('parent_id', '=', False)]
|
||||
value['view_type'] = 'tree'
|
||||
|
||||
return value
|
||||
|
||||
document_page_page_open()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Open Page Form view -->
|
||||
|
||||
<record id="view_wiki_wiki_page_open" model="ir.ui.view">
|
||||
<field name="name">Open Page</field>
|
||||
<field name="model">document.page.page.open</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Open Page" version="7.0">
|
||||
<label string="Want to open a Document page? "/>
|
||||
<footer>
|
||||
<button name="open_document_page" string="Open Document Page" type="object" class="oe_highlight"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Open Page Action -->
|
||||
|
||||
<record id="action_view_wiki_wiki_page_open" model="ir.actions.act_window">
|
||||
<field name="name">Open Page</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">document.page.page.open</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue