浏览代码

Merge branch 'live'

version-14
Rushabh Mehta 14 年前
父节点
当前提交
2e85a5f875
共有 10 个文件被更改,包括 129 次插入38 次删除
  1. +1
    -1
      cgi-bin/core/doctype/doctype/doctype.py
  2. +12
    -1
      cgi-bin/core/doctype/sandbox/sandbox.txt
  3. +4
    -2
      cgi-bin/webnotes/__init__.py
  4. +6
    -3
      cgi-bin/webnotes/model/doclist.py
  5. +4
    -1
      cgi-bin/webnotes/utils/__init__.py
  6. +70
    -4
      cgi-bin/webnotes/utils/file_manager.py
  7. +1
    -1
      cgi-bin/webnotes/utils/scheduler.py
  8. +4
    -0
      cgi-bin/webnotes/widgets/form.py
  9. +8
    -7
      js/form.compressed.js
  10. +19
    -18
      js/wn/widgets/form/attachments.js

+ 1
- 1
cgi-bin/core/doctype/doctype/doctype.py 查看文件

@@ -80,7 +80,7 @@ class DocType:

self.change_modified_of_parent()
import webnotes.defs
from webnotes import defs
from webnotes.utils.transfer import in_transfer

if (not in_transfer) and getattr(webnotes.defs,'developer_mode', 0):


+ 12
- 1
cgi-bin/core/doctype/sandbox/sandbox.txt 查看文件

@@ -76,7 +76,18 @@
'fieldname': 'test_link',
'fieldtype': 'Link',
'idx': 2,
'label': 'Test Link'
'label': 'Test Link',
'options': 'Profile'
},

# DocField
{
'doctype': 'DocField',
'fieldname': 'test_select',
'fieldtype': 'Select',
'idx': 2,
'label': 'Test Select',
'options': 'A\nB\nC'
},

# DocField


+ 4
- 2
cgi-bin/webnotes/__init__.py 查看文件

@@ -57,6 +57,8 @@ cookies = {}
auto_masters = {}
tenant_id = None

from webnotes.utils import cstr

#
# Custom Class (no traceback)
#
@@ -90,13 +92,13 @@ def errprint(msg):
"""
Append to the :data:`debug log`
"""
debug_log.append(str(msg or ''))
debug_log.append(cstr(msg or ''))

def msgprint(msg, small=0, raise_exception=0):
"""
Append to the :data:`message_log`
"""
message_log.append((small and '__small:' or '')+str(msg or ''))
message_log.append((small and '__small:' or '')+cstr(msg or ''))
if raise_exception:
raise ValidationError



+ 6
- 3
cgi-bin/webnotes/model/doclist.py 查看文件

@@ -97,7 +97,7 @@ class DocList:
"""
from webnotes.model.meta import is_single

if (not is_single(self.doc.doctype)) and (not self.doc.fields.get('__islocal')):
if (not is_single(self.doc.doctype)) and (not cint(self.doc.fields.get('__islocal'))):
tmp = webnotes.conn.sql("""
SELECT modified FROM `tab%s` WHERE name="%s" for update"""
% (self.doc.doctype, self.doc.name))
@@ -130,7 +130,7 @@ class DocList:
webnotes.msgprint("""[Link Validation] Could not find the following values: %s.
Please correct and resave. Document Not Saved.""" % ', '.join(err_list), raise_exception=1)
def update_timestamps(self):
def update_timestamps_and_docstatus(self):
"""
Update owner, creation, modified_by, modified, docstatus
"""
@@ -156,7 +156,7 @@ class DocList:
self.check_permission()
if check_links:
self.check_links()
self.update_timestamps()
self.update_timestamps_and_docstatus()

def run_method(self, method):
"""
@@ -239,7 +239,10 @@ class DocList:
"""
Update after submit - some values changed after submit
"""
if self.doc.docstatus != 1:
msgprint("Only to called after submit", raise_exception=1)
self.to_docstatus = 1
self.prepare_for_save(1)
self.save_main()
self.save_children()
self.run_method('on_update_after_submit')


+ 4
- 1
cgi-bin/webnotes/utils/__init__.py 查看文件

@@ -295,7 +295,10 @@ def cstr(s):
s = s.encode('utf-8', 'ignore')
except:
pass
return str(s)
try:
return unicode(s)
except UnicodeDecodeError:
return unicode(s, 'utf-8')

def str_esc_quote(s):
"""


+ 70
- 4
cgi-bin/webnotes/utils/file_manager.py 查看文件

@@ -7,20 +7,86 @@ def upload():
dn = form.getvalue('docname')
at_id = form.getvalue('at_id')

webnotes.response['type'] = 'iframe'
if not webnotes.form['filedata'].filename:
webnotes.response['result'] = """
<script type='text/javascript'>
window.parent.frms['%s'].attachments.dialog.hide();
window.parent.msgprint("Please select a file!");
</script>""" % dt
return
# save
fid, fname = save_uploaded()
if fid:
# save it in the form
updated = add_file_list(dt, dn, fname, fid)
if fid and updated:
# refesh the form!
# with the new modified timestamp
webnotes.response['result'] = """
<script type='text/javascript'>
window.parent.wn.widgets.form.file_upload_done('%s', '%s', '%s', '%s', '%s');
window.parent.frms['%s'].show_doc('%s');
window.parent.wn.widgets.form.file_upload_done('%(dt)s', '%(dn)s', '%(fid)s', '%(fname)s', '%(at_id)s', '%(mod)s');
window.parent.frms['%(dt)s'].show_doc('%(dn)s');
</script>
""" % (dt, dn, fid, fname.replace("'", "\\'"), at_id, dt, dn)
""" % {
'dt': dt,
'dn': dn,
'fid': fid,
'fname': fname.replace("'", "\\'"),
'at_id': at_id,
'mod': webnotes.conn.get_value(dt, dn, 'modified')
}

# -------------------------------------------------------

def add_file_list(dt, dn, fname, fid):
"""
udpate file_list attribute of the record
"""
import webnotes
try:
# get the old file_list
fl = webnotes.conn.get_value(dt, dn, 'file_list') or ''
if fl:
fl += '\n'
# add new file id
fl += fname + ',' + fid
# save
webnotes.conn.set_value(dt, dn, 'file_list', fl)
return True

except Exception, e:
webnotes.response['result'] = """
<script type='text/javascript'>
window.parent.msgprint("Error while uploading: %s");
</script>""" % str(e)


def remove_file_list(dt, dn, fid):
"""
Remove fid from the give file_list
"""
import webnotes
# get the old file_list
fl = webnotes.conn.get_value(dt, dn, 'file_list') or ''
new_fl = []
fl = fl.split('\n')
for f in fl:
if f.split(',')[1]!=fid:
new_fl.append(f)
# update the file_list
webnotes.conn.set_value(dt, dn, 'file_list', '\n'.join(new_fl))
# return the new timestamp
return webnotes.conn.get_value(dt, dn, 'modified')

def make_thumbnail(blob, size):
from PIL import Image
import cStringIO


+ 1
- 1
cgi-bin/webnotes/utils/scheduler.py 查看文件

@@ -138,7 +138,7 @@ class Scheduler:
# if recurring, update next_execution
if e['recurring']:
self.conn.sql("update Event set next_execution = addtime(now(), sec_to_time(%s))", e['interval'])
self.conn.sql("update Event set next_execution = addtime(now(), sec_to_time(%s)) where event=%s", (e['interval'], e['event']))
# else clear
else:


+ 4
- 0
cgi-bin/webnotes/widgets/form.py 查看文件

@@ -197,6 +197,7 @@ def runserverobj():
doclist = DocList()
doclist.from_compressed(form.getvalue('docs'), dn)
so = doclist.make_obj()
doclist.check_if_latest()
check_guest_access(so.doc)
@@ -288,6 +289,9 @@ def remove_attach():
fid = webnotes.form.getvalue('fid')
webnotes.utils.file_manager.delete_file(fid, verbose=1)
# remove from dt dn
return str(webnotes.utils.file_manager.remove_file_list(webnotes.form.getvalue('dt'), webnotes.form.getvalue('dn'), fid))

# Get Fields - Counterpart to $c_get_fields
#===========================================================================================


+ 8
- 7
js/form.compressed.js 查看文件

@@ -474,7 +474,9 @@ for(var i=0;i<cl.length;i++){this.render_one_comment(cl[i]);}}else{this.msg.inne
this.render_one_comment=function(det){$a(this.wrapper,'div','social sidebar-comment-text','',det.comment);$a(this.wrapper,'div','sidebar-comment-info','',comment_when(det.creation)+' by '+det.comment_by_fullname);}
this.add_comment=function(){if(!this.input.value)return;this.btn.set_working();wn.widgets.form.comments.add(this.input,me.doctype,me.docname,function(){me.btn.done_working();me.make_body();});}
this.refresh();}
wn.widgets.form.sidebar.Attachments=function(parent,sidebar,doctype,docname){var me=this;this.frm=sidebar.form;this.make=function(){if(this.wrapper)this.wrapper.innerHTML='';else this.wrapper=$a(parent,'div','sidebar-comment-wrapper');this.attach_wrapper=$a(this.wrapper,'div');var n=this.frm.doc.file_list?this.frm.doc.file_list.split('\n').length:0;if(n<this.frm.meta.max_attachments||!this.frm.meta.max_attachments){this.btn=$btn($a(this.wrapper,'div','sidebar-comment-message'),'Add',function(){me.add_attachment()});}
wn.widgets.form.sidebar.Attachments=function(parent,sidebar,doctype,docname){var me=this;this.frm=sidebar.form;this.make=function(){if(this.wrapper)this.wrapper.innerHTML='';else this.wrapper=$a(parent,'div','sidebar-comment-wrapper');this.attach_wrapper=$a(this.wrapper,'div');if(this.frm.doc.__islocal){this.attach_wrapper.innerHTML='Attachments can be uploaded after saving'
return;}
var n=this.frm.doc.file_list?this.frm.doc.file_list.split('\n').length:0;if(n<this.frm.meta.max_attachments||!this.frm.meta.max_attachments){this.btn=$btn($a(this.wrapper,'div','sidebar-comment-message'),'Add',function(){me.add_attachment()});}
this.render();}
this.render=function(){this.attach_wrapper.innerHTML=''
var doc=locals[me.frm.doctype][me.frm.docname];var fl=doc.file_list?doc.file_list.split('\n'):[];for(var i=0;i<fl.length;i++){new wn.widgets.form.sidebar.Attachment(this.attach_wrapper,fl[i],me.frm)}}
@@ -486,12 +488,11 @@ this.make();}
wn.widgets.form.sidebar.Attachment=function(parent,filedet,frm){filedet=filedet.split(',')
this.filename=filedet[0];this.fileid=filedet[1];this.frm=frm;var me=this;this.wrapper=$a(parent,'div','sidebar-comment-message');this.remove_fileid=function(){var doc=locals[me.frm.doctype][me.frm.docname];var fl=doc.file_list.split('\n');new_fl=[];for(var i=0;i<fl.length;i++){if(fl[i].split(',')[1]!=me.fileid)new_fl.push(fl[i]);}
doc.file_list=new_fl.join('\n');}
this.ln=$a(this.wrapper,'a','link_type',{fontSize:'11px'},this.filename);this.ln.href=outUrl+'?cmd=get_file&fname='+this.fileid;this.ln.target='_blank';this.del=$a(this.wrapper,'span','link_type',{marginLeft:'3px'},'[x]');this.del.onclick=function(){var yn=confirm("The document will be saved after the attachment is deleted for the changes to be permanent. Proceed?")
if(yn){var callback=function(r,rt){$dh(me.wrapper);me.remove_fileid();var ret=me.frm.save('Save');if(ret=='Error')
msgprint("error:The document was not saved. To make the removal permanent, you must save the document before closing.");}
$c('webnotes.widgets.form.remove_attach',args={'fid':me.fileid},callback);}}}
wn.widgets.form.file_upload_done=function(doctype,docname,fileid,filename,at_id){var at_id=cint(at_id);var doc=locals[doctype][docname];if(doc.file_list){var fl=doc.file_list.split('\n')
this.ln=$a(this.wrapper,'a','link_type',{fontSize:'11px'},this.filename);this.ln.href=outUrl+'?cmd=get_file&fname='+this.fileid;this.ln.target='_blank';this.del=$a(this.wrapper,'span','link_type',{marginLeft:'3px'},'[x]');this.del.onclick=function(){var yn=confirm("Are you sure you want to delete the attachment?")
if(yn){var callback=function(r,rt){locals[me.frm.doctype][me.frm.docname].modified=r.message;$dh(me.wrapper);me.remove_fileid();frm.refresh();}
$c('webnotes.widgets.form.remove_attach',args={'fid':me.fileid,dt:me.frm.doctype,dn:me.frm.docname},callback);}}}
wn.widgets.form.file_upload_done=function(doctype,docname,fileid,filename,at_id,new_timestamp){var at_id=cint(at_id);var doc=locals[doctype][docname];if(doc.file_list){var fl=doc.file_list.split('\n')
fl.push(filename+','+fileid)
doc.file_list=fl.join('\n');}
else
doc.file_list=filename+','+fileid;var frm=frms[doctype];frm.attachments.dialog.hide();frm.attachments.render();var do_save=confirm('File Uploaded Sucessfully. You must save this document for the uploaded file to be registred. Save this document now?');if(do_save){var ret=frm.save('Save');if(ret=='Error')msgprint("error:The document was not saved. To make the attachment permanent, you must save the document before closing.");}else{msgprint("error:The document was not saved. To make the attachment permanent, you must save the document before closing.");}}
doc.file_list=filename+','+fileid;doc.modified=new_timestamp;var frm=frms[doctype];frm.attachments.dialog.hide();msgprint('File Uploaded Sucessfully.');frm.refresh();}

+ 19
- 18
js/wn/widgets/form/attachments.js 查看文件

@@ -9,6 +9,12 @@ wn.widgets.form.sidebar.Attachments = function(parent, sidebar, doctype, docname
// attachment
this.attach_wrapper = $a(this.wrapper, 'div');
// no attachments if file is unsaved
if(this.frm.doc.__islocal) {
this.attach_wrapper.innerHTML = 'Attachments can be uploaded after saving'
return;
}
// no of attachments
var n = this.frm.doc.file_list ? this.frm.doc.file_list.split('\n').length : 0;
@@ -90,25 +96,24 @@ wn.widgets.form.sidebar.Attachment = function(parent, filedet, frm) {
// remove
this.del = $a(this.wrapper, 'span', 'link_type', {marginLeft:'3px'}, '[x]');
this.del.onclick = function() {
var yn = confirm("The document will be saved after the attachment is deleted for the changes to be permanent. Proceed?")
var yn = confirm("Are you sure you want to delete the attachment?")
if(yn) {
var callback = function(r, rt) {
// update timestamp
locals[me.frm.doctype][me.frm.docname].modified = r.message;
$dh(me.wrapper);
me.remove_fileid();
var ret=me.frm.save('Save');
if(ret=='Error')
msgprint("error:The document was not saved. To make the removal permanent, you must save the document before closing.");
}
$c('webnotes.widgets.form.remove_attach', args = {'fid': me.fileid }, callback );
frm.refresh();
}
$c('webnotes.widgets.form.remove_attach',
args = {'fid': me.fileid, dt: me.frm.doctype, dn: me.frm.docname }, callback );
}
}
}

// this function will be called after the upload is done
// from webnotes.utils.file_manager
wn.widgets.form.file_upload_done = function(doctype, docname, fileid, filename, at_id) {
wn.widgets.form.file_upload_done = function(doctype, docname, fileid, filename, at_id, new_timestamp) {
var at_id = cint(at_id);
@@ -122,16 +127,12 @@ wn.widgets.form.file_upload_done = function(doctype, docname, fileid, filename,
else
doc.file_list = filename + ',' + fileid;
// update timestamp
doc.modified = new_timestamp;
// update file_list
var frm = frms[doctype];
frm.attachments.dialog.hide();
frm.attachments.render();

var do_save = confirm('File Uploaded Sucessfully. You must save this document for the uploaded file to be registred. Save this document now?');
if(do_save) {
var ret = frm.save('Save');
if(ret=='Error')msgprint("error:The document was not saved. To make the attachment permanent, you must save the document before closing.");
} else {
msgprint("error:The document was not saved. To make the attachment permanent, you must save the document before closing.");
}
msgprint('File Uploaded Sucessfully.');
frm.refresh();
}

正在加载...
取消
保存