Merge branch 'master' of github.com:webnotes/wnframework into comm_log

This commit is contained in:
Anand Doshi 2012-06-05 18:29:24 +05:30
commit ed3ef5a175
10 changed files with 81 additions and 49 deletions

View file

@ -41,6 +41,7 @@ function int_to_str(i, len) {
wn.datetime = {
str_to_obj: function(d) {
if(typeof d=="object") return d;
if(!d) return new Date();
var tm = [null, null];
if(d.search(' ')!=-1) {
@ -57,6 +58,7 @@ wn.datetime = {
},
obj_to_str: function(d) {
if(typeof d=='string') return d;
return d.getFullYear() + '-' + int_to_str(d.getMonth()+1,2) + '-' + int_to_str(d.getDate(),2);
},
@ -76,9 +78,9 @@ wn.datetime = {
},
add_days: function(d, days) {
dt = dateutil.str_to_obj(d)
dt.setTime(dt.getTime()+(days*24*60*60*1000));
return dateutil.obj_to_str(dt);
var dt = dateutil.str_to_obj(d);
var new_dt = new Date(dt.getTime()+(days*24*60*60*1000));
return dateutil.obj_to_str(new_dt);
},
add_months: function(d, months) {

View file

@ -374,7 +374,7 @@ wn.urllib = {
// returns the base url with http + domain + path (-index.cgi or # or ?)
get_base_url: function() {
var url= window.location.href.split('#')[0].split('?')[0].split('index.cgi')[0];
var url= window.location.href.split('#')[0].split('?')[0].split('app.html')[0];
if(url.substr(url.length-1, 1)=='/') url = url.substr(0, url.length-1)
return url
},

View file

@ -73,8 +73,10 @@ class DocType:
if not doclist:
doclist.append(to_doc)
tbl_list = sql("select from_table, to_table, from_field, to_field, match_id, validation_logic \
from `tabTable Mapper Detail` where parent ='%s' order by match_id" % self.doc.name, as_dict=1)
tbl_list = sql("""\
select from_table, to_table, from_field, to_field, match_id, validation_logic
from `tabTable Mapper Detail` where parent ="%s" order by match_id""" \
% self.doc.name, as_dict=1)
for t in tbl_list:
if [t['from_table'], t['to_table']] in eval(from_to_list):
@ -114,11 +116,14 @@ class DocType:
"""
docnames = ()
if t['from_table'] == self.doc.from_doctype:
docnames = sql("select name from `tab%s` where name = '%s' and %s" % (from_dt, from_dn, t['validation_logic']))
docnames = sql("""select name from `tab%s` where name = "%s" and %s""" \
% (from_dt, from_dn, t['validation_logic']))
if not docnames:
msgprint("Validation failed in doctype mapper. Please contact Administrator.", raise_exception=1)
else:
docnames = sql("select name from `tab%s` where parent='%s' and parenttype = '%s' and %s order by idx" \
docnames = sql("""\
select name from `tab%s`
where parent="%s" and parenttype = "%s" and %s order by idx""" \
% (t['from_table'], from_dn, self.doc.from_doctype, t['validation_logic']))
return docnames
@ -129,7 +134,7 @@ class DocType:
return [[f[0], f[1], f[2]] for f in sql("""
select from_field, to_field, map
from `tabField Mapper Detail`
where parent = '%s' and match_id = %s
where parent = "%s" and match_id = %s
""" % (self.doc.name, t['match_id']))]
@ -142,11 +147,11 @@ class DocType:
exception_flds = copy.copy(default_fields)
exception_flds += [f[1] for f in flds]
from_flds = [d.fieldname for d in get(t['from_table']) \
from_flds = [d.fieldname for d in get(t['from_table'], 0) \
if cint(d.no_copy) == 0 and d.docstatus != 2 and d.fieldname \
and d.fieldtype not in ('Table', 'Section Break', 'Column Break', 'HTML')]
to_flds = [d.fieldname for d in get(t['to_table']) \
to_flds = [d.fieldname for d in get(t['to_table'], 0) \
if cint(d.no_copy) == 0 and d.docstatus != 2 and d.fieldname \
and d.fieldtype not in ('Table', 'Section Break', 'Column Break', 'HTML')]
@ -200,8 +205,8 @@ class DocType:
"""
flds = {}
for t in getlist(self.doclist, 'table_mapper_details'):
from_flds = [cstr(d.fieldname) for d in get(t.from_table)]
to_flds = [cstr(d.fieldname) for d in get(t.to_table)]
from_flds = [cstr(d.fieldname) for d in get(t.from_table, 0)]
to_flds = [cstr(d.fieldname) for d in get(t.to_table, 0)]
flds[cstr(t.match_id)] = [cstr(t.from_table), from_flds, cstr(t.to_table), to_flds]
for d in getlist(self.doclist, 'field_mapper_details'):
@ -235,10 +240,10 @@ class DocType:
def get_label_and_type(self, from_dt, to_dt):
"""get label, fieldtype"""
from_flds, to_flds = {}, {}
for d in get(from_dt):
for d in get(from_dt, 0):
from_flds[d.fieldname] = {'label': d.label, 'fieldtype': d.fieldtype}
for d in get(to_dt):
for d in get(to_dt, 0):
to_flds[d.fieldname] = {'label': d.label, 'fieldtype': d.fieldtype}
return from_flds, to_flds
@ -262,15 +267,21 @@ class DocType:
cur_val = '%.2f' % flt(cur_val)
if cl['op'] == '=' and to_flds[cl['to_fld']]['fieldtype'] in ['Currency', 'Float']:
consistent = sql("select name, %s from `tab%s` where name = '%s' and '%s' - %s <= 0.5" \
% (cl['from_fld'], t.from_table, child_obj.fields[t.reference_key], flt(cur_val), cl['from_fld']))
consistent = sql("""\
select name, %s from `tab%s`
where name = "%s" and "%s" - %s <= 0.5""" \
% (cl['from_fld'], t.from_table, child_obj.fields[t.reference_key],
flt(cur_val), cl['from_fld']))
else:
consistent = sql("select name, %s from `tab%s` where name = '%s' and '%s' %s ifnull(%s, '')" \
consistent = sql("""\
select name, %s from `tab%s`
where name = "%s" and "%s" %s ifnull(%s, '')""" \
% (cl['from_fld'], t.from_table, child_obj.fields[t.reference_key], \
to_flds[cl['to_fld']]['fieldtype'] in ('Currency', 'Float', 'Int') and flt(cur_val) or cstr(cur_val), cl['op'], cl['from_fld']))
to_flds[cl['to_fld']]['fieldtype'] in ('Currency', 'Float', 'Int') \
and flt(cur_val) or cstr(cur_val), cl['op'], cl['from_fld']))
if not self.ref_doc:
det = sql("select name, parent from `tab%s` where name = '%s'" % (t.from_table, child_obj.fields[t.reference_key]))
det = sql("""select name, parent from `tab%s` where name = \"%s\"""" % (t.from_table, child_obj.fields[t.reference_key]))
self.ref_doc = det[0][1] and det[0][1] or det[0][0]
if not consistent:
@ -285,7 +296,8 @@ class DocType:
def check_ref_docstatus(self):
if self.ref_doc:
det = sql("select name, docstatus from `tab%s` where name = '%s'" % (self.doc.from_doctype, self.ref_doc))
det = sql("""select name, docstatus from `tab%s` where name = \"%s\"""" \
% (self.doc.from_doctype, self.ref_doc))
if not det:
msgprint("%s: %s does not exists in the system" % (self.doc.from_doctype, self.ref_doc), raise_exception=1)
elif self.doc.ref_doc_submitted and det[0][1] != 1:

View file

@ -34,7 +34,7 @@ cur_frm.cscript['set_from_image'] = function(doc, dt, dn) {
return;
}
var file_name = doc.file_list.split(',')[0]
var file_name = doc.file_list.split(',')[1]
if(!in_list(['gif','jpg','jpeg','png'], file_name.split('.')[1].toLowerCase())) {
msgprint("Please upload a web friendly (GIF, JPG or PNG) image file for the letter head");

View file

@ -121,6 +121,11 @@ wn.pages['data-import-tool'].onload = function(wrapper) {
$('<input type="checkbox" name="overwrite"><span> Overwrite</span><br><br>')
.insertBefore('#dit-upload-area form input[type="submit"]')
// add ignore option
$('<input type="checkbox" name="ignore_encoding_errors"><span> Ignore Encoding Errors</span><br><br>')
.insertBefore('#dit-upload-area form input[type="submit"]')
// add overwrite option
$('<span>Date Format: </span><select name="date_format"></select><br><br>')
.insertBefore('#dit-upload-area form input[type="submit"]')

View file

@ -132,13 +132,16 @@ def upload():
for row in csvrows:
newrow = []
for val in row:
try:
newrow.append(unicode(val.strip(), 'utf-8'))
except UnicodeDecodeError, e:
raise Exception, """Some character(s) in row #%s, column #%s are
not readable by utf-8. Ignoring them. If you are importing a non
english language, please make sure your file is saved in the 'utf-8'
encoding.""" % (csvrows.index(row)+1, row.index(val)+1)
if webnotes.form_dict.get('ignore_encoding_errors'):
newrow.append(unicode(val.strip(), 'utf-8', errors='ignore'))
else:
try:
newrow.append(unicode(val.strip(), 'utf-8'))
except UnicodeDecodeError, e:
raise Exception, """Some character(s) in row #%s, column #%s are
not readable by utf-8. Ignoring them. If you are importing a non
english language, please make sure your file is saved in the 'utf-8'
encoding.""" % (csvrows.index(row)+1, row.index(val)+1)
rows.append(newrow)

View file

@ -1,6 +1,7 @@
<div class="layout-wrapper layout-wrapper-appframe" id='login_wrapper'>
<div class="appframe-area"></div>
<div class="layout-main" style="padding: 15px;">
<form autocomplete="on">
<table border="0" cellspacing="8">
<tbody>
<tr>
@ -22,11 +23,12 @@
<tr>
<td>&nbsp;</td>
<td>
<button id="login_btn" class="btn btn-small btn-primary">Login</button>
<button type="submit" id="login_btn" class="btn btn-small btn-primary">Login</button>
</td>
</tr>
</tbody>
</table>
</form>
<p style="margin-left: 72px;"><span class="link_type"
onclick="wn.show_forgot_password()">Forgot Password</span></p>
</div>

View file

@ -31,8 +31,12 @@ pscript['onload_Login Page'] = function(wrapper){
$('#login_btn').click(pscript.doLogin)
$('#password').keypress(function(ev){
if(ev.which==13 && $('#password').val())
pscript.doLogin();
if(ev.which==13 && $('#password').val()) {
$('form').submit(function() {
pscript.doLogin();
return false;
});
}
});
$(document).trigger('login_rendered');
}
@ -65,6 +69,8 @@ pscript.doLogin = function(){
$('#login_btn').set_working();
$c("login", args, pscript.onLoginReply);
return false;
}

View file

@ -295,7 +295,7 @@ class _DocType:
# custom script
from webnotes.model.code import get_custom_script
custom = get_custom_script(doc.name, 'Client') or ''
doc.fields['__js'] = doc.fields.setdefault('__js', '') + custom
doc.fields['__js'] = doc.fields.setdefault('__js', '') + '\n' + custom
def load_select_options(self, doclist):

34
wnf.py
View file

@ -70,6 +70,23 @@ def search_replace_with_prompt(fpath, txt1, txt2):
f.write(''.join(tmp))
print colored('Updated', 'green')
def create_cms_files():
from webnotes.model.code import get_obj
os.system('rm public/login-page.html')
# rewrite pages
ws = get_obj('Website Settings')
ws.rewrite_pages()
ss = get_obj('Style Settings')
ss.validate()
ss.doc.save()
ss.on_update()
# create login-page.html if it doesnt exist by copying index.html
if not os.path.exists('public/login-page.html') and os.path.exists('public/index.html'):
os.system('cp public/index.html public/login-page.html')
# change owner of files
os.system('chown -R apache:apache *')
def setup_options():
from optparse import OptionParser
@ -173,22 +190,7 @@ def run():
build.project.build()
elif options.cms:
from webnotes.model.code import get_obj
# rewrite pages
ws = get_obj('Website Settings')
ws.rewrite_pages()
ss = get_obj('Style Settings')
ss.validate()
ss.doc.save()
ss.on_update()
# create login-page.html if it doesnt exist by copying index.html
if not os.path.exists('public/login-page.html') and os.path.exists('public/index.html'):
os.system('cp public/index.html public/login-page.html')
# change owner of files
os.system('chown -R apache:apache *')
create_cms_files()
# code replace
elif options.replace: