[FIX] pad everything, remove unused api
bzr revid: al@openerp.com-20120721192551-q6nbqn4xxau0e64x
This commit is contained in:
parent
76354a6ac5
commit
a79139048d
|
@ -1,15 +0,0 @@
|
|||
OpenERP, Open Source Management Solution
|
||||
Copyright © 2010-2011 OpenERP SA (<http://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 Lice
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
@ -1,254 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
"""Module to talk to EtherpadLite API."""
|
||||
|
||||
import json
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
|
||||
class EtherpadLiteClient:
|
||||
"""Client to talk to EtherpadLite API."""
|
||||
API_VERSION = 1 # TODO probably 1.1 sometime soon
|
||||
|
||||
CODE_OK = 0
|
||||
CODE_INVALID_PARAMETERS = 1
|
||||
CODE_INTERNAL_ERROR = 2
|
||||
CODE_INVALID_FUNCTION = 3
|
||||
CODE_INVALID_API_KEY = 4
|
||||
TIMEOUT = 20
|
||||
|
||||
apiKey = ""
|
||||
baseUrl = ""
|
||||
|
||||
def __init__(self, apiKey=None, baseUrl=None):
|
||||
if apiKey:
|
||||
self.apiKey = apiKey
|
||||
|
||||
if baseUrl:
|
||||
self.baseUrl = baseUrl
|
||||
|
||||
def call(self, function, arguments=None):
|
||||
"""Create a dictionary of all parameters"""
|
||||
url = '%s/%d/%s' % (self.baseUrl, self.API_VERSION, function)
|
||||
|
||||
params = arguments or {}
|
||||
params.update({'apikey': self.apiKey})
|
||||
data = urllib.urlencode(params, True)
|
||||
|
||||
try:
|
||||
opener = urllib2.build_opener()
|
||||
request = urllib2.Request(url=url, data=data)
|
||||
response = opener.open(request, timeout=self.TIMEOUT)
|
||||
result = response.read()
|
||||
response.close()
|
||||
except urllib2.HTTPError:
|
||||
raise
|
||||
|
||||
result = json.loads(result)
|
||||
if result is None:
|
||||
raise ValueError("JSON response could not be decoded")
|
||||
|
||||
return self.handleResult(result)
|
||||
|
||||
def handleResult(self, result):
|
||||
"""Handle API call result"""
|
||||
if 'code' not in result:
|
||||
raise Exception("API response has no code")
|
||||
if 'message' not in result:
|
||||
raise Exception("API response has no message")
|
||||
|
||||
if 'data' not in result:
|
||||
result['data'] = None
|
||||
|
||||
if result['code'] == self.CODE_OK:
|
||||
return result['data']
|
||||
elif result['code'] == self.CODE_INVALID_PARAMETERS or result['code'] == self.CODE_INVALID_API_KEY:
|
||||
raise ValueError(result['message'])
|
||||
elif result['code'] == self.CODE_INTERNAL_ERROR:
|
||||
raise Exception(result['message'])
|
||||
elif result['code'] == self.CODE_INVALID_FUNCTION:
|
||||
raise Exception(result['message'])
|
||||
else:
|
||||
raise Exception("An unexpected error occurred whilst handling the response")
|
||||
|
||||
# GROUPS
|
||||
# Pads can belong to a group. There will always be public pads that do not belong to a group (or we give this group the id 0)
|
||||
|
||||
def createGroup(self):
|
||||
"""creates a new group"""
|
||||
return self.call("createGroup")
|
||||
|
||||
def createGroupIfNotExistsFor(self, groupMapper):
|
||||
"""this functions helps you to map your application group ids to etherpad lite group ids"""
|
||||
return self.call("createGroupIfNotExistsFor", {
|
||||
"groupMapper": groupMapper
|
||||
})
|
||||
|
||||
def deleteGroup(self, groupID):
|
||||
"""deletes a group"""
|
||||
return self.call("deleteGroup", {
|
||||
"groupID": groupID
|
||||
})
|
||||
|
||||
def listPads(self, groupID):
|
||||
"""returns all pads of this group"""
|
||||
return self.call("listPads", {
|
||||
"groupID": groupID
|
||||
})
|
||||
|
||||
def createGroupPad(self, groupID, padName, text=''):
|
||||
"""creates a new pad in this group"""
|
||||
params = {
|
||||
"groupID": groupID,
|
||||
"padName": padName,
|
||||
}
|
||||
if text:
|
||||
params['text'] = text
|
||||
return self.call("createGroupPad", params)
|
||||
|
||||
# AUTHORS
|
||||
# Theses authors are bind to the attributes the users choose (color and name).
|
||||
|
||||
def createAuthor(self, name=''):
|
||||
"""creates a new author"""
|
||||
params = {}
|
||||
if name:
|
||||
params['name'] = name
|
||||
return self.call("createAuthor", params)
|
||||
|
||||
def createAuthorIfNotExistsFor(self, authorMapper, name=''):
|
||||
"""this functions helps you to map your application author ids to etherpad lite author ids"""
|
||||
params = {
|
||||
'authorMapper': authorMapper
|
||||
}
|
||||
if name:
|
||||
params['name'] = name
|
||||
return self.call("createAuthorIfNotExistsFor", params)
|
||||
|
||||
# SESSIONS
|
||||
# Sessions can be created between a group and a author. This allows
|
||||
# an author to access more than one group. The sessionID will be set as
|
||||
# a cookie to the client and is valid until a certain date.
|
||||
|
||||
def createSession(self, groupID, authorID, validUntil):
|
||||
"""creates a new session"""
|
||||
return self.call("createSession", {
|
||||
"groupID": groupID,
|
||||
"authorID": authorID,
|
||||
"validUntil": validUntil
|
||||
})
|
||||
|
||||
def deleteSession(self, sessionID):
|
||||
"""deletes a session"""
|
||||
return self.call("deleteSession", {
|
||||
"sessionID": sessionID
|
||||
})
|
||||
|
||||
def getSessionInfo(self, sessionID):
|
||||
"""returns informations about a session"""
|
||||
return self.call("getSessionInfo", {
|
||||
"sessionID": sessionID
|
||||
})
|
||||
|
||||
def listSessionsOfGroup(self, groupID):
|
||||
"""returns all sessions of a group"""
|
||||
return self.call("listSessionsOfGroup", {
|
||||
"groupID": groupID
|
||||
})
|
||||
|
||||
def listSessionsOfAuthor(self, authorID):
|
||||
"""returns all sessions of an author"""
|
||||
return self.call("listSessionsOfAuthor", {
|
||||
"authorID": authorID
|
||||
})
|
||||
|
||||
# PAD CONTENT
|
||||
# Pad content can be updated and retrieved through the API
|
||||
|
||||
def getText(self, padID, rev=None):
|
||||
"""returns the text of a pad"""
|
||||
params = {"padID": padID}
|
||||
if rev is not None:
|
||||
params['rev'] = rev
|
||||
return self.call("getText", params)
|
||||
|
||||
# introduced with pull request merge
|
||||
def getHtml(self, padID, rev=None):
|
||||
"""returns the html of a pad"""
|
||||
params = {"padID": padID}
|
||||
if rev is not None:
|
||||
params['rev'] = rev
|
||||
return self.call("getHTML", params)
|
||||
|
||||
def setText(self, padID, text):
|
||||
"""sets the text of a pad"""
|
||||
return self.call("setText", {
|
||||
"padID": padID,
|
||||
"text": text
|
||||
})
|
||||
|
||||
def setHtml(self, padID, html):
|
||||
"""sets the text of a pad from html"""
|
||||
return self.call("setHTML", {
|
||||
"padID": padID,
|
||||
"html": html
|
||||
})
|
||||
|
||||
# PAD
|
||||
# Group pads are normal pads, but with the name schema
|
||||
# GROUPID$PADNAME. A security manager controls access of them and its
|
||||
# forbidden for normal pads to include a in the name.
|
||||
|
||||
def createPad(self, padID, text=''):
|
||||
"""creates a new pad"""
|
||||
params = {
|
||||
"padID": padID,
|
||||
}
|
||||
if text:
|
||||
params['text'] = text
|
||||
return self.call("createPad", params)
|
||||
|
||||
def getRevisionsCount(self, padID):
|
||||
"""returns the number of revisions of this pad"""
|
||||
return self.call("getRevisionsCount", {
|
||||
"padID": padID
|
||||
})
|
||||
|
||||
def deletePad(self, padID):
|
||||
"""deletes a pad"""
|
||||
return self.call("deletePad", {
|
||||
"padID": padID
|
||||
})
|
||||
|
||||
def getReadOnlyID(self, padID):
|
||||
"""returns the read only link of a pad"""
|
||||
return self.call("getReadOnlyID", {
|
||||
"padID": padID
|
||||
})
|
||||
|
||||
def setPublicStatus(self, padID, publicStatus):
|
||||
"""sets a boolean for the public status of a pad"""
|
||||
return self.call("setPublicStatus", {
|
||||
"padID": padID,
|
||||
"publicStatus": publicStatus
|
||||
})
|
||||
|
||||
def getPublicStatus(self, padID):
|
||||
"""return true of false"""
|
||||
return self.call("getPublicStatus", {
|
||||
"padID": padID
|
||||
})
|
||||
|
||||
def setPassword(self, padID, password):
|
||||
"""returns ok or a error message"""
|
||||
return self.call("setPassword", {
|
||||
"padID": padID,
|
||||
"password": password
|
||||
})
|
||||
|
||||
def isPasswordProtected(self, padID):
|
||||
"""returns true or false"""
|
||||
return self.call("isPasswordProtected", {
|
||||
"padID": padID
|
||||
})
|
||||
|
|
@ -2,52 +2,29 @@
|
|||
from osv import fields, osv
|
||||
import random
|
||||
import string
|
||||
from etherpad import EtherpadLiteClient
|
||||
import urllib2
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class pad_common(osv.osv_memory):
|
||||
_name = 'pad.common'
|
||||
_pad_url = None # name of the field for the etherpad
|
||||
def pad_generate_url(self, cr, uid, model, context=None):
|
||||
pad_url_template = self._pad_url_template(cr, uid, context)
|
||||
_pad_fields = []
|
||||
def pad_generate_url(self, cr, uid, context=None):
|
||||
pad_url_template = self.pool.get('res.users').browse(cr,uid, uid, context).company_id.pad_url_template
|
||||
s = string.ascii_uppercase + string.digits
|
||||
salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(8)])
|
||||
template_vars = {
|
||||
'db' : cr.dbname,
|
||||
'model' : model,
|
||||
'model' : self._name,
|
||||
'salt' : salt,
|
||||
}
|
||||
url = pad_url_template % template_vars
|
||||
api_key = self._pad_api_key(cr, uid, context)
|
||||
if api_key:
|
||||
urls = url.split('/')
|
||||
api_url = '/'.join(urls[:3]) + "/api"
|
||||
pad_id = urls[-1]
|
||||
ep_client = EtherpadLiteClient(api_key, api_url)
|
||||
try:
|
||||
ep_client.createPad(pad_id," ")
|
||||
except ValueError as strerror:
|
||||
raise osv.except_osv(_('Configuration Error !'),_("Etherpad Have Wrong API Key."))
|
||||
except urllib2.HTTPError as e:
|
||||
raise osv.except_osv(_('Configuration Error !'),_("Etherpad Have Wrong API URL."))
|
||||
except urllib2.URLError as e:
|
||||
raise osv.except_osv(_('Configuration Error !'),_("Etherpad Have Wrong Pad URL Template."))
|
||||
return url
|
||||
|
||||
def _pad_api_key(self, cr, uid, context=None):
|
||||
return self.pool.get('res.users').browse(cr,uid, uid, context).company_id.etherpad_api_key
|
||||
|
||||
def _pad_url_template(self, cr, uid, context=None):
|
||||
return self.pool.get('res.users').browse(cr,uid, uid, context).company_id.pad_url_template
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
if not default:
|
||||
default = {}
|
||||
default.update({
|
||||
self._pad_url:self.pad_generate_url(cr, uid, self._name),
|
||||
})
|
||||
update = [(field,self.pad_generate_url(cr, uid, context)) for field in self._pad_fields]
|
||||
default.update(update)
|
||||
return super(pad_common, self).copy(cr, uid, id, default, context)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from osv import fields, osv
|
||||
|
||||
PAD_TEMPLATE = 'http://beta.etherpad.org/p/%(db).10s-%(model)s-%(salt)s'
|
||||
PAD_API_KEY = 'EtherpadFTW'
|
||||
DEFAULT_PAD_TEMPLATE = 'http://beta.etherpad.org/p/%(db)s-%(model)s-%(salt)s'
|
||||
|
||||
class company_pad(osv.osv):
|
||||
_inherit = 'res.company'
|
||||
_columns = {
|
||||
'pad_url_template': fields.char('Pad URL Template', size=128, required=True,
|
||||
help="Template used to generate pad URL."),
|
||||
'etherpad_api_key': fields.char('Pad API Key', size=128),
|
||||
'pad_url_template': fields.char('Pad URL Template', size=128, required=True, help="Template used to generate pad URL."),
|
||||
}
|
||||
_defaults = {
|
||||
'pad_url_template': PAD_TEMPLATE,
|
||||
'etherpad_api_key': PAD_API_KEY,
|
||||
'pad_url_template': DEFAULT_PAD_TEMPLATE,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='account_grp']" position="after">
|
||||
<group string="Pads">
|
||||
<field name="pad_url_template"/>
|
||||
<field name="etherpad_api_key"/>
|
||||
<field name="pad_url_template" placeholder="e.g. http://beta.etherpad.org/p/%%(db)s-%%(model)s-%%(salt)s"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
|
|
|
@ -1,37 +1,40 @@
|
|||
openerp.pad = function(instance) {
|
||||
|
||||
instance.web.form.FieldEtherpad = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
|
||||
template: 'FieldEtherpad',
|
||||
instance.web.form.FieldPad = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
|
||||
template: 'FieldPad',
|
||||
initialize_content: function() {
|
||||
this.$textarea = undefined;
|
||||
this.$element.find('div.oe_etherpad_head').click(_.bind(function(ev){
|
||||
this.$element.toggleClass('oe_etherpad_fullscreen').toggleClass('oe_etherpad_normal');
|
||||
|
||||
},this));
|
||||
},
|
||||
set_value: function(value_) {
|
||||
this._super(value_);
|
||||
this.render_value();
|
||||
},
|
||||
render_value: function() {
|
||||
var show_value = instance.web.format_value(this.get('value'), this, '');
|
||||
if (!this.get("effective_readonly")) {
|
||||
var self = this;
|
||||
this.$textarea = undefined;
|
||||
this.$element.find('div.oe_etherpad_head').click(function(ev) {
|
||||
self.$element.toggleClass('oe_etherpad_fullscreen').toggleClass('oe_etherpad_normal');
|
||||
});
|
||||
},
|
||||
set_value: function(value_) {
|
||||
this._super(value_);
|
||||
this.render_value();
|
||||
},
|
||||
render_value: function() {
|
||||
var self = this;
|
||||
var value = this.get('value');
|
||||
if(value !== false) {
|
||||
var url = value.split('\n')[0];
|
||||
if (!this.get("effective_readonly")) {
|
||||
var pad_username = this.session.username;
|
||||
this.$element.find('div.oe_etherpad_default').html('<iframe width="100%" height="100%" frameborder="0" src="'+show_value.split('\n')[0]+'?showChat=false&showLineNumbers=false&userName='+pad_username+'"></iframe>');
|
||||
var code = '<iframe width="100%" height="100%" frameborder="0" src="'+url+'?showChat=false&userName='+pad_username+'"></iframe>';
|
||||
this.$element.find('div.oe_etherpad_default').html(code);
|
||||
} else {
|
||||
if(this.get('value') != false)
|
||||
{
|
||||
var self = this;
|
||||
if(show_value.split('\n')[0] != '')
|
||||
$.get(show_value.split('\n')[0]+'/export/html')
|
||||
.success(function(data) { self.$element.html('<div class="etherpad_readonly">'+data+'</div>'); })
|
||||
.error(function() { self.$element.text('Unable to load pad'); });
|
||||
}
|
||||
$.get(url+'/export/html').success(function(data) {
|
||||
self.$element.html('<div class="etherpad_readonly">'+data+'</div>');
|
||||
}).error(function() {
|
||||
self.$element.text('Unable to load pad');
|
||||
});
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
instance.web.form.widgets = instance.web.form.widgets.extend({
|
||||
'etherpad': 'instance.web.form.FieldEtherpad',
|
||||
});
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
instance.web.form.widgets = instance.web.form.widgets.extend({
|
||||
'pad': 'instance.web.form.FieldPad',
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
-->
|
||||
<templates id="template" xml:space="preserve">
|
||||
|
||||
<t t-name="FieldEtherpad">
|
||||
<t t-name="FieldPad">
|
||||
<t t-if="!widget.get('effective_readonly')">
|
||||
<div class="oe_form_field_text oe_etherpad_normal">
|
||||
<div class="oe_etherpad_head">
|
||||
<span class="oe_normal">Fullscreen</span>
|
||||
<span class="oe_fullscreen">Return to Record</span>
|
||||
</div>
|
||||
<div class="oe_etherpad_default" ></div>
|
||||
<div class="oe_etherpad_head">
|
||||
<span class="oe_normal">Fullscreen</span>
|
||||
<span class="oe_fullscreen">Return to Record</span>
|
||||
</div>
|
||||
<div class="oe_etherpad_default" ></div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
##############################################################################
|
||||
|
||||
{
|
||||
'name': 'Specifications on PADs',
|
||||
'name': 'Pad on tasks',
|
||||
'version': '1.0',
|
||||
"category": "Project Management",
|
||||
'description': """
|
||||
|
|
|
@ -5,10 +5,10 @@ from osv import fields, osv
|
|||
class task(osv.osv):
|
||||
_name = "project.task"
|
||||
_inherit = ["project.task",'pad.common']
|
||||
_pad_url = 'description_pad'
|
||||
_pad_fields = ['description_pad']
|
||||
_columns = {
|
||||
'description_pad': fields.char('PAD Description', size=250)
|
||||
'description_pad': fields.char('Description PAD', size=250)
|
||||
}
|
||||
_defaults = {
|
||||
_pad_url: lambda self, cr, uid, context: self.pad_generate_url(cr, uid, self._name, context),
|
||||
'description_pad': lambda self, cr, uid, context: self.pad_generate_url(cr, uid, context),
|
||||
}
|
||||
|
|
|
@ -7,10 +7,7 @@
|
|||
<field name="inherit_id" ref="project.view_task_form2"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="description" position="replace">
|
||||
<field name="description_pad"
|
||||
attrs="{'readonly':[('state','=','done')]}"
|
||||
widget="etherpad"
|
||||
/>
|
||||
<field name="description_pad" attrs="{'readonly':[('state','=','done')]}" widget="pad"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
|
Loading…
Reference in New Issue