From 462a685e9aa60225c2f7dd7e2f53052c6c4bcc7c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 29 Feb 2012 15:11:48 +0530 Subject: [PATCH] merge --- js/legacy/utils/datatype.js | 36 +++++++-------------- js/legacy/utils/datetime.js | 11 ++++--- js/wn/ui/listing.js | 2 +- py/core/doctype/page/page.py | 54 +++++++++++++++++--------------- py/webnotes/__init__.py | 14 +++++++-- py/webnotes/model/import_docs.py | 2 +- 6 files changed, 62 insertions(+), 57 deletions(-) diff --git a/js/legacy/utils/datatype.js b/js/legacy/utils/datatype.js index 8e65474127..49adfd28eb 100644 --- a/js/legacy/utils/datatype.js +++ b/js/legacy/utils/datatype.js @@ -151,6 +151,15 @@ function cstr(s) { if(s==null)return ''; return s+''; } +function nth(number) { + number = cint(number); + var s = 'th'; + if((number+'').substr(-1)=='1') s = 'st'; + if((number+'').substr(-1)=='2') s = 'nd'; + if((number+'').substr(-1)=='3') s = 'rd'; + return number+s; +} + function flt(v,decimals) { if(v==null || v=='')return 0; v=(v+'').replace(/,/g,''); @@ -198,18 +207,9 @@ var rstrip = function(s, chars) { } return s; } -function repl_all(s, s1, s2) { - var idx = s.indexOf(s1); - while (idx != -1){ - s = s.replace(s1, s2); - idx = s.indexOf(s1); - } - return s; -} + function repl(s, dict) { - if(s==null)return ''; - for(key in dict) s = repl_all(s, '%('+key+')s', dict[key]); - return s; + return sprintf(s, dict); } ///// dict type @@ -247,19 +247,7 @@ function add_lists(l1, l2) { } function docstring(obj) { - var l = []; - for(key in obj) { - var v = obj[key]; - if(v!=null) { - if(typeof(v)==typeof(1)) { - l[l.length] = "'"+ key + "':" + (v + ''); - } else { - v = v+''; // convert to string - l[l.length] = "'"+ key + "':'" + v.replace(/'/g, "\\'").replace(/\n/g, "\\n") + "'"; - } - } - } - return "{" + l.join(',') + '}'; + return JSON.stringify(obj); } function DocLink(p, doctype, name, onload) { diff --git a/js/legacy/utils/datetime.js b/js/legacy/utils/datetime.js index 0cdba40f16..1ced3d94af 100644 --- a/js/legacy/utils/datetime.js +++ b/js/legacy/utils/datetime.js @@ -174,7 +174,7 @@ wn.datetime = { global_date_format: function(d) { if(d.substr) d = this.str_to_obj(d); - return d.getDate() + ' ' + month_list_full[d.getMonth()] + ' ' + d.getFullYear(); + return nth(d.getDate()) + ' ' + month_list_full[d.getMonth()] + ' ' + d.getFullYear(); }, get_today: function() { @@ -252,9 +252,12 @@ wn.datetime.time_to_hhmm = function(hh,mm,am) { // long ago the date represents. function prettyDate(time){ if(!time) return '' - var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ").replace(/\.[0-9]*/, "")), - diff = (((new Date()).getTime() - date.getTime()) / 1000), - day_diff = Math.floor(diff / 86400); + var date = time; + if(typeof(time)=="string") + date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ").replace(/\.[0-9]*/, "")); + + var diff = (((new Date()).getTime() - date.getTime()) / 1000), + day_diff = Math.floor(diff / 86400); if ( isNaN(day_diff) || day_diff < 0 ) return ''; diff --git a/js/wn/ui/listing.js b/js/wn/ui/listing.js index cd5352fd22..9aceea4295 100644 --- a/js/wn/ui/listing.js +++ b/js/wn/ui/listing.js @@ -152,7 +152,7 @@ wn.widgets.Listing = function(opts) { this.start += m; // refreh more button - if(r.values.length > this.page_length) $ds(this.more_button_area); + if(r.values.length >= this.page_length) $ds(this.more_button_area); } else { if(this.start==0) { diff --git a/py/core/doctype/page/page.py b/py/core/doctype/page/page.py index 4f44e8105d..f4d218bc48 100644 --- a/py/core/doctype/page/page.py +++ b/py/core/doctype/page/page.py @@ -34,34 +34,17 @@ class DocType: """ from webnotes.utils import cint if (self.doc.name and self.doc.name.startswith('New Page')) or not self.doc.name: - self.doc.name = self.doc.page_name.lower().replace('"','').replace("'",'').replace(' ', '-')[:20] + self.doc.name = self.doc.page_name.lower().replace('"','').replace("'",'').\ + replace(' ', '-')[:20] if webnotes.conn.exists('Page',self.doc.name): - cnt = webnotes.conn.sql('select name from tabPage where name like "%s-%%" order by name desc limit 1' % self.doc.name) + cnt = webnotes.conn.sql("""select name from tabPage + where name like "%s-%%" order by name desc limit 1""" % self.doc.name) if cnt: cnt = cint(cnt[0][0].split('-')[-1]) + 1 else: cnt = 1 self.doc.name += '-' + str(cnt) - def onload(self): - """ - loads html from file before passing - """ - import os - from webnotes.modules import get_module_path, scrub - - # load content - if not self.doc.module: - return - - try: - file = open(os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name) + '.html'), 'r') - self.doc.content = file.read() or '' - file.close() - except IOError, e: # no file / permission - if e.args[0]!=2: - raise e - def validate(self): """ Update $image tags @@ -90,8 +73,29 @@ class DocType: import os export_to_files(record_list=[['Page', self.doc.name]]) - if self.doc.write_content and self.doc.content: - file = open(os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name), scrub(self.doc.name) + '.html'), 'w') - file.write(self.doc.content) - file.close() + # write files + path = os.path.join(get_module_path(self.doc.module), 'page', scrub(self.doc.name), scrub(self.doc.name)) + + # html + if not os.path.exists(path + '.html'): + with open(path + '.html', 'w') as f: + f.write("""
+ × +

Activity

+
""" % self.doc.title) + + # js + if not os.path.exists(path + '.js'): + with open(path + '.js', 'w') as f: + f.write("""wn.pages['%s'].onload = function(wrapper) { }""" % self.doc.name) + + # py + if not os.path.exists(path + '.py'): + with open(path + '.py', 'w') as f: + f.write("""import webnotes""") + + # css + if not os.path.exists(path + '.css'): + with open(path + '.css', 'w') as f: + pass diff --git a/py/webnotes/__init__.py b/py/webnotes/__init__.py index c8cb0c48cb..9f41e0a730 100644 --- a/py/webnotes/__init__.py +++ b/py/webnotes/__init__.py @@ -212,7 +212,17 @@ def whitelist(allow_guest=False): return innerfn -def clear_cache(): +def clear_cache(user=None): """clear boot cache""" from webnotes.session_cache import clear - clear() + clear(user) + +def get_roles(): + """get roles of current user""" + if session['user']=='Guest': + return ['Guest'] + + roles = [r[0] for r in conn.sql("""select distinct role from tabUserRole + where parent=%s and role!='All'""", session['user'])] + + return roles + ['All'] diff --git a/py/webnotes/model/import_docs.py b/py/webnotes/model/import_docs.py index ffa7dc8697..af47f03c80 100644 --- a/py/webnotes/model/import_docs.py +++ b/py/webnotes/model/import_docs.py @@ -383,7 +383,7 @@ class CSVImport: def convert_csv_data_into_list(self,csv_data): st_list = [] for s in csv_data: - st_list.append([unicode(d, 'utf-8').strip() for d in s]) + st_list.append([d.strip() for d in s]) return st_list # Get Template method