[IMP] Moved binary controllers from FormView class to new Binary class
bzr revid: fme@openerp.com-20110523145219-0nwzvkm94bm5liag
This commit is contained in:
parent
fb9f16b6df
commit
d66a1ca348
|
@ -555,63 +555,6 @@ class FormView(View):
|
||||||
fields_view = self.fields_view_get(req, model, view_id, 'form', toolbar=toolbar)
|
fields_view = self.fields_view_get(req, model, view_id, 'form', toolbar=toolbar)
|
||||||
return {'fields_view': fields_view}
|
return {'fields_view': fields_view}
|
||||||
|
|
||||||
@openerpweb.httprequest
|
|
||||||
def image(self, request, session_id, model, id, field, **kw):
|
|
||||||
cherrypy.response.headers['Content-Type'] = 'image/png'
|
|
||||||
Model = request.session.model(model)
|
|
||||||
try:
|
|
||||||
if not id:
|
|
||||||
res = Model.default_get([field], request.context).get(field, '')
|
|
||||||
else:
|
|
||||||
res = Model.read([int(id)], [field], request.context)[0].get(field, '')
|
|
||||||
return base64.decodestring(res)
|
|
||||||
except: # TODO: what's the exception here?
|
|
||||||
return self.placeholder()
|
|
||||||
def placeholder(self):
|
|
||||||
return open(os.path.join(openerpweb.path_addons, 'base', 'static', 'src', 'img', 'placeholder.png'), 'rb').read()
|
|
||||||
|
|
||||||
@openerpweb.httprequest
|
|
||||||
def saveas(self, request, session_id, model, id, field, fieldname, **kw):
|
|
||||||
Model = request.session.model(model)
|
|
||||||
res = Model.read([int(id)], [field, fieldname])[0]
|
|
||||||
filecontent = res.get(field, '')
|
|
||||||
if not filecontent:
|
|
||||||
raise cherrypy.NotFound
|
|
||||||
else:
|
|
||||||
cherrypy.response.headers['Content-Type'] = 'application/octet-stream'
|
|
||||||
filename = '%s_%s' % (model.replace('.', '_'), id)
|
|
||||||
if fieldname:
|
|
||||||
filename = res.get(fieldname, '') or filename
|
|
||||||
cherrypy.response.headers['Content-Disposition'] = 'attachment; filename=' + filename
|
|
||||||
return base64.decodestring(filecontent)
|
|
||||||
|
|
||||||
@openerpweb.httprequest
|
|
||||||
def upload(self, request, session_id, callback, ufile=None):
|
|
||||||
cherrypy.response.timeout = 500
|
|
||||||
headers = {}
|
|
||||||
for key, val in cherrypy.request.headers.iteritems():
|
|
||||||
headers[key.lower()] = val
|
|
||||||
size = int(headers.get('content-length', 0))
|
|
||||||
# TODO: might be usefull to have a configuration flag for max-lenght file uploads
|
|
||||||
try:
|
|
||||||
out = """<script language="javascript" type="text/javascript">
|
|
||||||
var win = window.top.window,
|
|
||||||
callback = win[%s];
|
|
||||||
if (typeof(callback) === 'function') {
|
|
||||||
callback.apply(this, %s);
|
|
||||||
} else {
|
|
||||||
win.jQuery('#oe_notification', win.document).notify('create', {
|
|
||||||
title: "Ajax File Upload",
|
|
||||||
text: "Could not find callback"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>"""
|
|
||||||
data = ufile.file.read()
|
|
||||||
args = [size, ufile.filename, ufile.headers.getheader('Content-Type'), base64.encodestring(data)]
|
|
||||||
except Exception, e:
|
|
||||||
args = [False, e.message]
|
|
||||||
return out % (simplejson.dumps(callback), simplejson.dumps(args))
|
|
||||||
|
|
||||||
class ListView(View):
|
class ListView(View):
|
||||||
_cp_path = "/base/listview"
|
_cp_path = "/base/listview"
|
||||||
|
|
||||||
|
@ -704,7 +647,6 @@ class ListView(View):
|
||||||
return color[0]
|
return color[0]
|
||||||
return 'maroon'
|
return 'maroon'
|
||||||
|
|
||||||
|
|
||||||
class SearchView(View):
|
class SearchView(View):
|
||||||
_cp_path = "/base/searchview"
|
_cp_path = "/base/searchview"
|
||||||
|
|
||||||
|
@ -712,13 +654,73 @@ class SearchView(View):
|
||||||
def load(self, req, model, view_id):
|
def load(self, req, model, view_id):
|
||||||
fields_view = self.fields_view_get(req, model, view_id, 'search')
|
fields_view = self.fields_view_get(req, model, view_id, 'search')
|
||||||
return {'fields_view': fields_view}
|
return {'fields_view': fields_view}
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
def fields_get(self, req, model):
|
def fields_get(self, req, model):
|
||||||
Model = req.session.model(model)
|
Model = req.session.model(model)
|
||||||
fields = Model.fields_get()
|
fields = Model.fields_get()
|
||||||
return {'fields': fields}
|
return {'fields': fields}
|
||||||
|
|
||||||
|
class Binary(openerpweb.Controller):
|
||||||
|
_cp_path = "/base/binary"
|
||||||
|
|
||||||
|
@openerpweb.httprequest
|
||||||
|
def image(self, request, session_id, model, id, field, **kw):
|
||||||
|
cherrypy.response.headers['Content-Type'] = 'image/png'
|
||||||
|
Model = request.session.model(model)
|
||||||
|
try:
|
||||||
|
if not id:
|
||||||
|
res = Model.default_get([field], request.context).get(field, '')
|
||||||
|
else:
|
||||||
|
res = Model.read([int(id)], [field], request.context)[0].get(field, '')
|
||||||
|
return base64.decodestring(res)
|
||||||
|
except: # TODO: what's the exception here?
|
||||||
|
return self.placeholder()
|
||||||
|
def placeholder(self):
|
||||||
|
return open(os.path.join(openerpweb.path_addons, 'base', 'static', 'src', 'img', 'placeholder.png'), 'rb').read()
|
||||||
|
|
||||||
|
@openerpweb.httprequest
|
||||||
|
def saveas(self, request, session_id, model, id, field, fieldname, **kw):
|
||||||
|
Model = request.session.model(model)
|
||||||
|
res = Model.read([int(id)], [field, fieldname])[0]
|
||||||
|
filecontent = res.get(field, '')
|
||||||
|
if not filecontent:
|
||||||
|
raise cherrypy.NotFound
|
||||||
|
else:
|
||||||
|
cherrypy.response.headers['Content-Type'] = 'application/octet-stream'
|
||||||
|
filename = '%s_%s' % (model.replace('.', '_'), id)
|
||||||
|
if fieldname:
|
||||||
|
filename = res.get(fieldname, '') or filename
|
||||||
|
cherrypy.response.headers['Content-Disposition'] = 'attachment; filename=' + filename
|
||||||
|
return base64.decodestring(filecontent)
|
||||||
|
|
||||||
|
@openerpweb.httprequest
|
||||||
|
def upload(self, request, session_id, callback, ufile=None):
|
||||||
|
cherrypy.response.timeout = 500
|
||||||
|
headers = {}
|
||||||
|
for key, val in cherrypy.request.headers.iteritems():
|
||||||
|
headers[key.lower()] = val
|
||||||
|
size = int(headers.get('content-length', 0))
|
||||||
|
# TODO: might be usefull to have a configuration flag for max-lenght file uploads
|
||||||
|
try:
|
||||||
|
out = """<script language="javascript" type="text/javascript">
|
||||||
|
var win = window.top.window,
|
||||||
|
callback = win[%s];
|
||||||
|
if (typeof(callback) === 'function') {
|
||||||
|
callback.apply(this, %s);
|
||||||
|
} else {
|
||||||
|
win.jQuery('#oe_notification', win.document).notify('create', {
|
||||||
|
title: "Ajax File Upload",
|
||||||
|
text: "Could not find callback"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>"""
|
||||||
|
data = ufile.file.read()
|
||||||
|
args = [size, ufile.filename, ufile.headers.getheader('Content-Type'), base64.encodestring(data)]
|
||||||
|
except Exception, e:
|
||||||
|
args = [False, e.message]
|
||||||
|
return out % (simplejson.dumps(callback), simplejson.dumps(args))
|
||||||
|
|
||||||
class Action(openerpweb.Controller):
|
class Action(openerpweb.Controller):
|
||||||
_cp_path = "/base/action"
|
_cp_path = "/base/action"
|
||||||
|
|
||||||
|
|
|
@ -1255,7 +1255,7 @@ openerp.base.form.FieldBinary = openerp.base.form.Field.extend({
|
||||||
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
||||||
},
|
},
|
||||||
on_save_as: function() {
|
on_save_as: function() {
|
||||||
var url = '/base/formview/saveas?session_id=' + this.session.session_id + '&model=' +
|
var url = '/base/binary/saveas?session_id=' + this.session.session_id + '&model=' +
|
||||||
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name +
|
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name +
|
||||||
'&fieldname=' + (this.node.attrs.filename || '') + '&t=' + (new Date().getTime())
|
'&fieldname=' + (this.node.attrs.filename || '') + '&t=' + (new Date().getTime())
|
||||||
window.open(url);
|
window.open(url);
|
||||||
|
@ -1329,7 +1329,7 @@ openerp.base.form.FieldBinaryImage = openerp.base.form.FieldBinary.extend({
|
||||||
set_value: function(value) {
|
set_value: function(value) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.set_image_maxwidth();
|
this.set_image_maxwidth();
|
||||||
var url = '/base/formview/image?session_id=' + this.session.session_id + '&model=' +
|
var url = '/base/binary/image?session_id=' + this.session.session_id + '&model=' +
|
||||||
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime())
|
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime())
|
||||||
this.$image.attr('src', url);
|
this.$image.attr('src', url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -421,7 +421,7 @@
|
||||||
<td>
|
<td>
|
||||||
<div class="oe-binary-file-set" style="width: 40px; height:22px;">
|
<div class="oe-binary-file-set" style="width: 40px; height:22px;">
|
||||||
<form class="oe-binary-form" t-att-target="widget.iframe"
|
<form class="oe-binary-form" t-att-target="widget.iframe"
|
||||||
method="post" enctype="multipart/form-data" action="/base/formview/upload">
|
method="post" enctype="multipart/form-data" action="/base/binary/upload">
|
||||||
<input type="hidden" name="session_id" value=""/>
|
<input type="hidden" name="session_id" value=""/>
|
||||||
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
|
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
|
||||||
<button class="button" type="button" title="Set Image">
|
<button class="button" type="button" title="Set Image">
|
||||||
|
@ -464,7 +464,7 @@
|
||||||
<td>
|
<td>
|
||||||
<div class="oe-binary-file-set" style="width: 80px; height:22px;">
|
<div class="oe-binary-file-set" style="width: 80px; height:22px;">
|
||||||
<form class="oe-binary-form" t-att-target="widget.iframe"
|
<form class="oe-binary-form" t-att-target="widget.iframe"
|
||||||
method="post" enctype="multipart/form-data" action="/base/formview/upload">
|
method="post" enctype="multipart/form-data" action="/base/binary/upload">
|
||||||
<input type="hidden" name="session_id" value=""/>
|
<input type="hidden" name="session_id" value=""/>
|
||||||
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
|
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
|
||||||
<button class="button" type="button" title="Set Image">
|
<button class="button" type="button" title="Set Image">
|
||||||
|
|
Loading…
Reference in New Issue