From 89abceaa0d17bbdded3472946c2eb25024679b64 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 25 Aug 2011 11:34:01 +0530 Subject: [PATCH 1/4] added ability to show / hide columns --- cgi-bin/webnotes/utils/email_lib/receive.py | 5 +- js/form.compressed.js | 26 +++---- js/widgets/form/form_grid.js | 6 -- js/widgets/form/grid.js | 77 +++++++++++---------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/cgi-bin/webnotes/utils/email_lib/receive.py b/cgi-bin/webnotes/utils/email_lib/receive.py index 73d5e66c8c..d6cc347998 100644 --- a/cgi-bin/webnotes/utils/email_lib/receive.py +++ b/cgi-bin/webnotes/utils/email_lib/receive.py @@ -131,7 +131,10 @@ class POP3Mailbox: num = len(self.pop.list()[1]) for m in range(num): msg = self.pop.retr(m+1) - self.process_message(IncomingMail('\n'.join(msg[1]))) + try: + self.process_message(IncomingMail('\n'.join(msg[1]))) + except: + pass self.pop.dele(m+1) self.pop.quit() diff --git a/js/form.compressed.js b/js/form.compressed.js index 64ea3993ac..d4c58ca5b8 100644 --- a/js/form.compressed.js +++ b/js/form.compressed.js @@ -256,18 +256,21 @@ _f.CodeField.prototype.init_editor=function(){var me=this;this.editor=tinymce.ge _f.CodeField.prototype.set_disp=function(val){$y(this.disp_area,{width:'90%'}) if(this.df.fieldtype=='Text Editor'){this.disp_area.innerHTML=val;}else{this.disp_area.innerHTML='';}} _f.cur_grid_cell=null;_f.Grid=function(parent){} -_f.Grid.prototype.init=function(parent,row_height){this.alt_row_bg='#F2F2FF';this.row_height=row_height;if(!row_height)this.row_height='26px';this.make_ui(parent);this.insert_column('','','Int','Sr','50px','',[1,0,0]);this.total_width=50;if(this.oninit)this.oninit();keypress_observers.push(this)} +_f.Grid.prototype.init=function(parent,row_height){this.col_idx_by_name={} +this.alt_row_bg='#F2F2FF';this.row_height=row_height;if(!row_height)this.row_height='26px';this.make_ui(parent);this.insert_column('','','Int','Sr','50px','',[1,0,0]);if(this.oninit)this.oninit();keypress_observers.push(this);} _f.Grid.prototype.make_ui=function(parent){var ht=make_table($a(parent,'div'),1,2,'100%',['60%','40%']);this.main_title=$td(ht,0,0);this.main_title.className='columnHeading';$td(ht,0,1).style.textAlign='right';this.tbar_div=$a($td(ht,0,1),'div','grid_tbarlinks');if(isIE)$y(this.tbar_div,{width:'200px'});this.tbar_tab=make_table(this.tbar_div,1,4,'100%',['25%','25%','25%','25%']);this.wrapper=$a(parent,'div','grid_wrapper');$h(this.wrapper,cint(screen.width*0.5)+'px');this.head_wrapper=$a(this.wrapper,'div','grid_head_wrapper');this.head_tab=$a(this.head_wrapper,'table','grid_head_table');this.head_row=this.head_tab.insertRow(0);this.tab_wrapper=$a(this.wrapper,'div','grid_tab_wrapper');this.tab=$a(this.tab_wrapper,'table','grid_table');var me=this;this.wrapper.onscroll=function(){me.head_wrapper.style.top=me.wrapper.scrollTop+'px';}} _f.Grid.prototype.show=function(){if(this.can_add_rows){$ds(this.tbar_div);}else{$dh(this.tbar_div);} $ds(this.wrapper);} _f.Grid.prototype.hide=function(){$dh(this.wrapper);$dh(this.tbar_div);} -_f.Grid.prototype.insert_column=function(doctype,fieldname,fieldtype,label,width,options,perm,reqd){var idx=this.head_row.cells.length;if(!width)width='100px';var col=this.head_row.insertCell(idx);col.doctype=doctype;col.fieldname=fieldname;col.fieldtype=fieldtype;col.innerHTML='
'+label+'
';col.label=label;if(reqd) -col.childNodes[0].style.color="#D22";this.total_width+=cint(width);$w(col,width);col.orig_width=col.style.width;col.options=options;col.perm=perm;} -_f.Grid.prototype.set_column_disp=function(label,show){for(var i=0;i'+label+'';col.label=label;if(reqd) +col.childNodes[0].style.color="#D22";col.style.width=width;col.options=options;col.perm=perm;this.col_idx_by_name[fieldname]=idx;} +_f.Grid.prototype.reset_table_width=function(){var w=0;for(var i=0,len=this.head_row.cells.length;ithis.tab.rows.length) +_f.Grid.prototype.set_data=function(data){this.cell_deselect();this.reset_table_width();if(data.length>this.tab.rows.length) this.append_rows(data.length-this.tab.rows.length);if(data.length'+label+'';c.cur_label=label;break;}}} _f.FormGrid.prototype.refresh=function(){var docset=getchildren(this.doctype,this.field.frm.docname,this.field.df.fieldname,this.field.frm.doctype);var data=[];for(var i=0;i this.tab.rows.length) From bdeecb59fe31b564b54765b26c2cf7e6ee228a10 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 25 Aug 2011 11:38:02 +0530 Subject: [PATCH 2/4] removed msgprint --- js/form.compressed.js | 2 +- js/widgets/form/grid.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/js/form.compressed.js b/js/form.compressed.js index d4c58ca5b8..c6f5ff2489 100644 --- a/js/form.compressed.js +++ b/js/form.compressed.js @@ -263,7 +263,7 @@ _f.Grid.prototype.show=function(){if(this.can_add_rows){$ds(this.tbar_div);}else $ds(this.wrapper);} _f.Grid.prototype.hide=function(){$dh(this.wrapper);$dh(this.tbar_div);} _f.Grid.prototype.insert_column=function(doctype,fieldname,fieldtype,label,width,options,perm,reqd){var idx=this.head_row.cells.length;if(!width)width='140px';if((width+'').slice(-2)!='px'){width=width+'px';} -msgprint(width);var col=this.head_row.insertCell(idx);col.doctype=doctype;col.fieldname=fieldname;col.fieldtype=fieldtype;col.innerHTML='
'+label+'
';col.label=label;if(reqd) +var col=this.head_row.insertCell(idx);col.doctype=doctype;col.fieldname=fieldname;col.fieldtype=fieldtype;col.innerHTML='
'+label+'
';col.label=label;if(reqd) col.childNodes[0].style.color="#D22";col.style.width=width;col.options=options;col.perm=perm;this.col_idx_by_name[fieldname]=idx;} _f.Grid.prototype.reset_table_width=function(){var w=0;for(var i=0,len=this.head_row.cells.length;i Date: Thu, 25 Aug 2011 15:08:52 +0530 Subject: [PATCH 3/4] feature to restrict ip, by hours, cleanup of profile doctype --- cgi-bin/core/doctype/profile/profile.txt | 556 ++++-------------- .../search_criteria/search_criteria.txt | 74 +-- cgi-bin/webnotes/auth.py | 41 +- cgi-bin/webnotes/db.py | 11 +- cgi-bin/webnotes/model/utils.py | 24 +- js/widgets/report_builder/report_builder.js | 8 +- 6 files changed, 193 insertions(+), 521 deletions(-) diff --git a/cgi-bin/core/doctype/profile/profile.txt b/cgi-bin/core/doctype/profile/profile.txt index fd5cd3722f..3f117123e0 100644 --- a/cgi-bin/core/doctype/profile/profile.txt +++ b/cgi-bin/core/doctype/profile/profile.txt @@ -5,25 +5,22 @@ { 'creation': '2009-05-12 11:19:11', 'docstatus': 0, - 'modified': '2010-12-21 11:07:20', - 'modified_by': 'sneha@webnotestech.com', + 'modified': '2011-08-25 14:02:26', + 'modified_by': 'Administrator', 'owner': 'Administrator' }, # These values are common for all DocType { - '_last_update': '1303708853', + '_last_update': '1311340897', 'allow_attach': 1, 'allow_copy': 0, 'allow_email': 0, 'allow_print': 0, - 'client_script': 'cur_frm.cscript[\'Change Password\']= function(doc, cdt, cdn) {\n var error = false;\n if ((!doc.new_password)||(!doc.retype_new_password)){\n alert("Both fields are required!");\n error = true;\n }\n if (doc.new_password.length<4) {\n alert("Password must be atleast 4 characters long");\n error = true;\n }\n if(doc.new_password!=doc.retype_new_password) {\n alert("Passwords must match");\n error = true;\n }\n if(!/[A-Z]/.test(doc.new_password) || !/[0-9]/.test(doc.new_password) || !/[\\W_]/.test(doc.new_password)) {\n msgprint(\'New password must contain atleast 1 capital letter, 1 numeric and 1 special character.\');\n error = true;\n doc.new_password = \'\';\n refresh_field(\'new_password\');\n }\n if(!error) {\n cur_frm.runscript(\'update_password\', \'\', function(r,t) {\n\tdoc.new_password = \'\';\n\tdoc.retype_new_password = \'\';\n refresh_many([\'new_password\',\'retype_new_password\']);\n });\n }\n}\n\ncur_frm.cscript.validate = function(doc, cdt, cdn) {\n doc.new_password = \'\';\n doc.retype_new_password = \'\';\n}', 'colour': 'White:FFF', 'doctype': 'DocType', 'hide_heading': 0, 'hide_toolbar': 0, - 'idx': 0, - 'in_create': 1, 'issingle': 0, 'istable': 0, 'max_attachments': 1, @@ -31,10 +28,9 @@ 'name': '__common__', 'print_outline': 'Yes', 'read_only': 0, - 'section_style': 'Tray', - 'server_code_error': ' ', + 'search_fields': 'first_name, last_name', 'show_in_menu': 0, - 'version': 25 + 'version': 32 }, # These values are common for all DocField @@ -69,7 +65,6 @@ 'create': 1, 'doctype': 'DocPerm', 'execute': 0, - 'idx': 1, 'permlevel': 0, 'role': 'Administrator', 'submit': 0 @@ -79,7 +74,6 @@ { 'create': 1, 'doctype': 'DocPerm', - 'idx': 2, 'permlevel': 0, 'role': 'System Manager' }, @@ -87,7 +81,6 @@ # DocPerm { 'doctype': 'DocPerm', - 'idx': 3, 'permlevel': 1, 'role': 'Administrator' }, @@ -95,67 +88,17 @@ # DocPerm { 'doctype': 'DocPerm', - 'idx': 4, 'match': 'owner', 'permlevel': 0, 'role': 'All' }, - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Section Break', - 'hidden': 0, - 'idx': 1, - 'label': 'Details', - 'oldfieldtype': 'Section Break', - 'permlevel': 0, - 'reqd': 0, - 'search_index': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Column Break', - 'hidden': 0, - 'idx': 2, - 'label': 'Picture', - 'oldfieldtype': 'Column Break', - 'permlevel': 0, - 'reqd': 0, - 'search_index': 0, - 'width': '50%' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Image', - 'idx': 3, - 'label': 'Profile Picture', - 'oldfieldtype': 'Image', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Column Break', - 'idx': 4, - 'label': 'Contact', - 'oldfieldtype': 'Column Break', - 'permlevel': 0, - 'width': '50%' - }, - # DocField { 'default': '1', 'doctype': 'DocField', 'fieldname': 'enabled', 'fieldtype': 'Check', - 'idx': 5, 'label': 'Enabled', 'oldfieldname': 'enabled', 'oldfieldtype': 'Check', @@ -164,24 +107,40 @@ # DocField { - 'default': '1', 'doctype': 'DocField', - 'fieldname': 'send_email_invite', + 'fieldname': 'password', + 'fieldtype': 'Password', + 'label': 'Password', + 'permlevel': 1, + 'hidden': 1 + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'registered', 'fieldtype': 'Check', - 'idx': 6, - 'label': 'Send Email Invite', - 'oldfieldname': 'send_email_invite', - 'oldfieldtype': 'Check', - 'permlevel': 1 + 'label': 'Registered', + 'permlevel': 0, + 'hidden': 1 }, + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'unsubscribed', + 'fieldtype': 'Check', + 'label': 'Unsubscribed', + 'permlevel': 0, + 'hidden': 1 + }, + # DocField { 'doctype': 'DocField', 'fieldname': 'recent_documents', 'fieldtype': 'Text', 'hidden': 1, - 'idx': 8, 'label': 'Recent Documents', 'oldfieldname': 'recent_documents', 'oldfieldtype': 'Text', @@ -195,7 +154,6 @@ 'doctype': 'DocField', 'fieldname': 'first_name', 'fieldtype': 'Data', - 'idx': 9, 'label': 'First Name', 'oldfieldname': 'first_name', 'oldfieldtype': 'Data', @@ -208,7 +166,6 @@ 'doctype': 'DocField', 'fieldname': 'middle_name', 'fieldtype': 'Data', - 'idx': 10, 'label': 'Middle Name (Optional)', 'oldfieldname': 'middle_name', 'oldfieldtype': 'Data', @@ -220,46 +177,17 @@ 'doctype': 'DocField', 'fieldname': 'last_name', 'fieldtype': 'Data', - 'idx': 11, 'label': 'Last Name', 'oldfieldname': 'last_name', 'oldfieldtype': 'Data', 'permlevel': 0 }, - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'email', - 'fieldtype': 'Data', - 'hidden': 0, - 'idx': 12, - 'label': 'Email', - 'oldfieldname': 'email', - 'oldfieldtype': 'Data', - 'permlevel': 0, - 'reqd': 1, - 'search_index': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'birth_date', - 'fieldtype': 'Date', - 'idx': 13, - 'label': 'Birth Date', - 'oldfieldname': 'birth_date', - 'oldfieldtype': 'Date', - 'permlevel': 0 - }, - # DocField { 'doctype': 'DocField', 'fieldname': 'gender', 'fieldtype': 'Select', - 'idx': 14, 'label': 'Gender', 'oldfieldname': 'gender', 'oldfieldtype': 'Select', @@ -271,51 +199,74 @@ # DocField { 'doctype': 'DocField', - 'fieldname': 'occupation', - 'fieldtype': 'Data', - 'idx': 15, - 'label': 'Designation', - 'oldfieldname': 'occupation', - 'oldfieldtype': 'Data', - 'permlevel': 0, - 'search_index': 0 + 'fieldtype': 'Column Break', + 'oldfieldtype': 'Column Break', + 'permlevel': 1, + 'width': '50%' }, + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'email', + 'fieldtype': 'Data', + 'hidden': 0, + 'label': 'Email', + 'oldfieldname': 'email', + 'oldfieldtype': 'Data', + 'permlevel': 0, + 'reqd': 1, + 'search_index': 0 + }, + # DocField { 'doctype': 'DocField', 'fieldname': 'bio', 'fieldtype': 'Text', - 'idx': 16, 'label': 'Bio', 'oldfieldname': 'bio', 'oldfieldtype': 'Text', 'permlevel': 0, - 'search_index': 0 + 'search_index': 0, + 'hidden': 1 }, + # DocField { 'doctype': 'DocField', 'fieldname': 'interests', 'fieldtype': 'Text', - 'idx': 17, 'label': 'Interests', 'oldfieldname': 'interests', 'oldfieldtype': 'Text', + 'permlevel': 0, + 'hidden': 1 + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'birth_date', + 'fieldtype': 'Date', + 'label': 'Birth Date', + 'oldfieldname': 'birth_date', + 'oldfieldtype': 'Date', 'permlevel': 0 }, + # DocField { 'doctype': 'DocField', 'fieldname': 'activities', 'fieldtype': 'Text', - 'idx': 18, 'label': 'Activities', 'oldfieldname': 'activities', 'oldfieldtype': 'Text', - 'permlevel': 0 + 'permlevel': 0, + 'hidden': 1 }, # DocField @@ -323,7 +274,6 @@ 'doctype': 'DocField', 'fieldname': 'messanger_status', 'fieldtype': 'Data', - 'idx': 19, 'label': 'Messanger Status', 'oldfieldname': 'messanger_status', 'oldfieldtype': 'Data', @@ -331,60 +281,11 @@ 'search_index': 0 }, - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'home_phone', - 'fieldtype': 'Data', - 'idx': 20, - 'label': 'Home Phone', - 'oldfieldname': 'home_phone', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'office_phone', - 'fieldtype': 'Data', - 'idx': 21, - 'label': 'Office Phone', - 'oldfieldname': 'office_phone', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'extension', - 'fieldtype': 'Data', - 'idx': 22, - 'label': 'Extension', - 'oldfieldname': 'extension', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'cell_no', - 'fieldtype': 'Data', - 'idx': 23, - 'label': 'Cell No', - 'oldfieldname': 'cell_no', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - # DocField { 'doctype': 'DocField', 'fieldname': 'user_type', 'fieldtype': 'Select', - 'idx': 24, 'label': 'User Type', 'oldfieldname': 'user_type', 'oldfieldtype': 'Select', @@ -392,150 +293,27 @@ 'permlevel': 0 }, - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'last_login', - 'fieldtype': 'Read Only', - 'hidden': 0, - 'idx': 25, - 'label': 'Last Login', - 'oldfieldname': 'last_login', - 'oldfieldtype': 'Read Only', - 'permlevel': 0, - 'reqd': 0, - 'search_index': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'last_ip', - 'fieldtype': 'Read Only', - 'idx': 26, - 'label': 'Last IP', - 'oldfieldname': 'last_ip', - 'oldfieldtype': 'Read Only', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Section Break', - 'idx': 27, - 'label': 'Address', - 'oldfieldtype': 'Section Break', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'line_1', - 'fieldtype': 'Data', - 'idx': 28, - 'label': 'Line 1', - 'oldfieldname': 'line_1', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'line_2', - 'fieldtype': 'Data', - 'idx': 29, - 'label': 'Line 2', - 'oldfieldname': 'line_2', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'city', - 'fieldtype': 'Data', - 'idx': 30, - 'label': 'City / Town', - 'oldfieldname': 'city', - 'oldfieldtype': 'Data', - 'permlevel': 0, - 'reqd': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'district', - 'fieldtype': 'Data', - 'idx': 31, - 'label': 'District', - 'oldfieldname': 'district', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'state', - 'fieldtype': 'Data', - 'idx': 32, - 'label': 'State', - 'oldfieldname': 'state', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'country', - 'fieldtype': 'Data', - 'idx': 33, - 'label': 'Country', - 'oldfieldname': 'country', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'pin', - 'fieldtype': 'Data', - 'idx': 34, - 'label': 'Pin', - 'oldfieldname': 'pin', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Section Break', - 'idx': 35, - 'label': 'User Role', - 'oldfieldtype': 'Section Break', - 'permlevel': 1 - }, # DocField { 'doctype': 'DocField', 'fieldtype': 'Section Break', 'hidden': 0, - 'idx': 36, - 'label': 'Roles', 'oldfieldtype': 'Section Break', 'permlevel': 1, 'reqd': 0, 'search_index': 0 }, + + # DocField + { + 'doctype': 'DocField', + 'fieldtype': 'Column Break', + 'label': 'Roles', + 'oldfieldtype': 'Column Break', + 'permlevel': 1, + 'width': '50%' + }, # DocField { @@ -545,7 +323,6 @@ 'fieldname': 'userroles', 'fieldtype': 'Table', 'hidden': 0, - 'idx': 37, 'label': 'User Roles', 'oldfieldname': 'userroles', 'oldfieldtype': 'Table', @@ -558,10 +335,9 @@ # DocField { 'doctype': 'DocField', - 'fieldtype': 'Section Break', - 'idx': 38, + 'fieldtype': 'Column Break', 'label': 'System Defaults', - 'oldfieldtype': 'Section Break', + 'oldfieldtype': 'Column Break', 'permlevel': 1, 'width': '50%' }, @@ -574,7 +350,6 @@ 'fieldname': 'defaults', 'fieldtype': 'Table', 'hidden': 0, - 'idx': 39, 'label': 'Defaults', 'oldfieldname': 'defaults', 'oldfieldtype': 'Table', @@ -588,9 +363,35 @@ { 'doctype': 'DocField', 'fieldtype': 'Section Break', - 'idx': 40, - 'label': 'Password', + 'label': 'Login Details', 'oldfieldtype': 'Section Break', + 'permlevel': 0, + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'login_before', + 'fieldtype': 'Int', + 'label': 'Login Before', + 'permlevel': 0 + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'login_after', + 'fieldtype': 'Int', + 'label': 'Login After', + 'permlevel': 0 + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'restrict_ip', + 'fieldtype': 'Data', + 'label': 'Restrict IP', 'permlevel': 0 }, @@ -598,25 +399,20 @@ { 'doctype': 'DocField', 'fieldtype': 'Column Break', - 'idx': 41, - 'label': 'Change Your Password', 'oldfieldtype': 'Column Break', - 'permlevel': 1, 'width': '50%' }, # DocField { - 'colour': 'Pink:FEF2EA', 'doctype': 'DocField', - 'fieldname': 'password', - 'fieldtype': 'Data', - 'hidden': 1, - 'idx': 42, - 'label': 'Current Password', - 'oldfieldname': 'password', - 'oldfieldtype': 'Data', - 'permlevel': 1, + 'fieldname': 'last_login', + 'fieldtype': 'Read Only', + 'hidden': 0, + 'label': 'Last Login', + 'oldfieldname': 'last_login', + 'oldfieldtype': 'Read Only', + 'permlevel': 0, 'reqd': 0, 'search_index': 0 }, @@ -624,139 +420,23 @@ # DocField { 'doctype': 'DocField', - 'fieldname': 'new_password', - 'fieldtype': 'Password', - 'idx': 43, - 'label': 'New Password', - 'oldfieldname': 'new_password', - 'oldfieldtype': 'Password', - 'permlevel': 1 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'retype_new_password', - 'fieldtype': 'Password', - 'idx': 44, - 'label': 'Retype New Password', - 'oldfieldname': 'retype_new_password', - 'oldfieldtype': 'Password', - 'permlevel': 1 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'password_last_updated', - 'fieldtype': 'Date', - 'hidden': 1, - 'idx': 45, - 'label': 'Password Last Updated', - 'oldfieldname': 'password_last_updated', - 'oldfieldtype': 'Date', - 'permlevel': 1, - 'print_hide': 1 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Button', - 'idx': 46, - 'label': 'Change Password', - 'oldfieldtype': 'Button', - 'permlevel': 1, - 'trigger': 'Client', - 'width': '120px' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Section Break', - 'idx': 47, - 'label': 'Attachment', - 'oldfieldtype': 'Section Break', - 'permlevel': 1 - }, - - # DocField - { - 'default': '0', - 'doctype': 'DocField', - 'fieldname': 'social_points', - 'fieldtype': 'Int', - 'idx': 48, - 'label': 'Social Points', - 'oldfieldname': 'social_points', - 'oldfieldtype': 'Int', + 'fieldname': 'last_ip', + 'fieldtype': 'Read Only', + 'label': 'Last IP', + 'oldfieldname': 'last_ip', + 'oldfieldtype': 'Read Only', 'permlevel': 0 }, - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'social_badge', - 'fieldtype': 'Data', - 'idx': 49, - 'label': 'Social Badge', - 'oldfieldname': 'social_badge', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'avatar', - 'fieldtype': 'Data', - 'idx': 50, - 'label': 'Avatar', - 'oldfieldname': 'avatar', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'HTML', - 'idx': 51, - 'label': 'Attachment HTML', - 'oldfieldtype': 'HTML', - 'options': 'First attachment must be the picture', - 'permlevel': 1 - }, - # DocField { 'doctype': 'DocField', 'fieldname': 'file_list', 'fieldtype': 'Text', 'hidden': 1, - 'idx': 52, 'label': 'File List', 'oldfieldname': 'file_list', 'oldfieldtype': 'Text', 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'fiscal_year', - 'fieldtype': 'Select', - 'hidden': 1, - 'idx': 53, - 'in_filter': 1, - 'label': 'Fiscal Year', - 'no_copy': 1, - 'oldfieldname': 'fiscal_year', - 'oldfieldtype': 'Select', - 'options': 'link:Fiscal Year', - 'permlevel': 0, - 'print_hide': 1, - 'report_hide': 1 - } + } ] \ No newline at end of file diff --git a/cgi-bin/core/doctype/search_criteria/search_criteria.txt b/cgi-bin/core/doctype/search_criteria/search_criteria.txt index 0a4f09e55d..a3ca3ae369 100644 --- a/cgi-bin/core/doctype/search_criteria/search_criteria.txt +++ b/cgi-bin/core/doctype/search_criteria/search_criteria.txt @@ -87,10 +87,13 @@ # DocField { 'doctype': 'DocField', - 'fieldtype': 'Section Break', - 'idx': 1, - 'label': 'Details', - 'oldfieldtype': 'Section Break', + 'fieldname': 'criteria_name', + 'fieldtype': 'Data', + 'hidden': 0, + 'idx': 5, + 'label': 'Criteria Name', + 'oldfieldname': 'criteria_name', + 'oldfieldtype': 'Data', 'permlevel': 0 }, @@ -135,41 +138,6 @@ 'search_index': 1 }, - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'criteria_name', - 'fieldtype': 'Data', - 'hidden': 0, - 'idx': 5, - 'label': 'Criteria Name', - 'oldfieldname': 'criteria_name', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'description', - 'fieldtype': 'Text', - 'idx': 6, - 'label': 'Description', - 'oldfieldname': 'description', - 'oldfieldtype': 'Text', - 'permlevel': 0, - 'width': '300px' - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldtype': 'Section Break', - 'idx': 7, - 'label': 'Query Details', - 'oldfieldtype': 'Section Break', - 'permlevel': 0 - }, # DocField { @@ -189,7 +157,7 @@ 'doctype': 'DocField', 'fieldname': 'filters', 'fieldtype': 'Text', - 'hidden': 0, + 'hidden': 1, 'idx': 9, 'label': 'Filters', 'oldfieldname': 'filters', @@ -288,32 +256,6 @@ 'permlevel': 0 }, - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'graph_series', - 'fieldtype': 'Data', - 'hidden': 0, - 'idx': 17, - 'label': 'Graph Series', - 'oldfieldname': 'graph_series', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - - # DocField - { - 'doctype': 'DocField', - 'fieldname': 'graph_values', - 'fieldtype': 'Data', - 'hidden': 0, - 'idx': 18, - 'label': 'Graph Values', - 'oldfieldname': 'graph_values', - 'oldfieldtype': 'Data', - 'permlevel': 0 - }, - # DocField { 'doctype': 'DocField', diff --git a/cgi-bin/webnotes/auth.py b/cgi-bin/webnotes/auth.py index a3f04a1a1b..6858151560 100644 --- a/cgi-bin/webnotes/auth.py +++ b/cgi-bin/webnotes/auth.py @@ -127,8 +127,9 @@ class LoginManager: # --------------------------- def post_login(self): - self.validate_ip_address() self.run_trigger() + self.validate_ip_address() + self.validate_hour() # check password # -------------- @@ -186,16 +187,38 @@ class LoginManager: # ------------- def validate_ip_address(self): - try: - ip = webnotes.conn.sql("select ip_address from tabProfile where name = '%s'" % self.user)[0][0] or '' - except: return + ip_list = webnotes.conn.get_value('Profile', self.user, 'restrict_ip', ignore=True) + + if not ip_list: + return + + ip_list = ip_list.replace(",", "\n").split('\n') + ip_list = [i.strip() for i in ip_list] + + for ip in ip_list: + if webnotes.remote_ip.startswith(ip): + return - ip = ip.replace(",", "\n").split('\n') - ip = [i.strip() for i in ip] + webnotes.msgprint('Not allowed from this IP Address', raise_exception=1) + + def validate_hour(self): + """ + check if user is logging in during restricted hours + """ + login_before = int(webnotes.conn.get_value('Profile', self.user, 'login_before', ignore=True) or 0) + login_after = int(webnotes.conn.get_value('Profile', self.user, 'login_after', ignore=True) or 0) + + if not (login_before or login_after): + return - if ret and ip: - if not (webnotes.remote_ip.startswith(ip[0]) or (webnotes.remote_ip in ip)): - raise Exception, 'Not allowed from this IP Address' + from webnotes.utils import now_datetime + current_hour = int(now_datetime().strftime('%H')) + + if login_before and current_hour > login_before: + webnotes.msgprint('Not allowed to login after restricted hour', raise_exception=1) + + if login_after and current_hour < login_after: + webnotes.msgprint('Not allowed to login before restricted hour', raise_exception=1) # login as guest # -------------- diff --git a/cgi-bin/webnotes/db.py b/cgi-bin/webnotes/db.py index 45837a2051..f288714d47 100644 --- a/cgi-bin/webnotes/db.py +++ b/cgi-bin/webnotes/db.py @@ -255,7 +255,7 @@ class Database: # ====================================================================================== # get a single value from a record - def get_value(self, doctype, docname, fieldname): + def get_value(self, doctype, docname, fieldname, ignore=None): """ Get a single / multiple value from a record. @@ -266,8 +266,13 @@ class Database: if docname and (docname!=doctype or docname=='DocType'): if type(fieldname) in (list, tuple): fl = '`, `'.join(fieldname) - - r = self.sql("select `%s` from `tab%s` where name='%s'" % (fl, doctype, docname)) + try: + r = self.sql("select `%s` from `tab%s` where name='%s'" % (fl, doctype, docname)) + except Exception, e: + if e.args[0]==1054 and ignore: + return None + else: + raise e return r and (len(r[0]) > 1 and r[0] or r[0][0]) or None else: if type(fieldname) in (list, tuple): diff --git a/cgi-bin/webnotes/model/utils.py b/cgi-bin/webnotes/model/utils.py index b9892067d3..b8c45507f0 100644 --- a/cgi-bin/webnotes/model/utils.py +++ b/cgi-bin/webnotes/model/utils.py @@ -186,9 +186,11 @@ def commonify_doclist(doclist, with_comments=1): c[k] = doclist[0][k] return c - def strip_common(d): + def strip_common_and_idx(d): for k in common_keys: if k in d: del d[k] + + if 'idx' in d: del d['idx'] return d def make_common_dicts(doclist): @@ -211,7 +213,7 @@ def commonify_doclist(doclist, with_comments=1): # make docs final = [] for d in doclist: - f = strip_common(get_diff_dict(common_dict[d['doctype']], d)) + f = strip_common_and_idx(get_diff_dict(common_dict[d['doctype']], d)) f['doctype'] = d['doctype'] # keep doctype! # strip name for child records (only an auto generated number!) @@ -228,7 +230,7 @@ def commonify_doclist(doclist, with_comments=1): d['name']='__common__' if with_comments: d['##comment'] = 'These values are common for all ' + d['doctype'] - commons.append(strip_common(d)) + commons.append(strip_common_and_idx(d)) common_values = make_common(doclist) return [common_values]+commons+final @@ -237,18 +239,32 @@ def uncommonify_doclist(dl): """ Expands an commonified doclist """ + # first one has common values common_values = dl[0] common_dict = {} final = [] + idx_dict = {} for d in dl[1:]: if 'name' in d and d['name']=='__common__': + # common for a doctype - del d['name'] common_dict[d['doctype']] = d else: + dt = d['doctype'] + if not dt in idx_dict: idx_dict[dt] = 0; d1 = common_values.copy() - d1.update(common_dict[d['doctype']]) + + # update from common and global + d1.update(common_dict[dt]) d1.update(d) + + # idx by sequence + d1['idx'] = idx_dict[dt] + + # increment idx + idx_dict[dt] += 1 + final.append(d1) return final diff --git a/js/widgets/report_builder/report_builder.js b/js/widgets/report_builder/report_builder.js index f10144bb25..379c8c6cbd 100644 --- a/js/widgets/report_builder/report_builder.js +++ b/js/widgets/report_builder/report_builder.js @@ -507,7 +507,13 @@ _r.ReportBuilder.prototype.set_sort_options = function(l) { empty_select(this.dt.sort_sel); - if(l) sl = add_lists(l, this.orig_sort_list) + if(l) sl = add_lists(l, this.orig_sort_list); + + // no sorts, add one + if(!l.length) { + l.push(['ID', 'name']) + } + for(var i=0; i Date: Thu, 25 Aug 2011 16:10:50 +0530 Subject: [PATCH 4/4] trigger form_refresh --- js/form.compressed.js | 3 ++- js/widgets/form/form.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/js/form.compressed.js b/js/form.compressed.js index c6f5ff2489..f4a7be5b96 100644 --- a/js/form.compressed.js +++ b/js/form.compressed.js @@ -121,7 +121,8 @@ if(this.docname){if(!this.check_doc_perm())return;if(!this.setup_done)this.setup if(this.doc.__islocal) this.is_editable[this.docname]=1;this.editable=this.is_editable[this.docname];if(!this.doc.__archived&&(this.editable||(!this.editable&&this.meta.istable))){if(this.print_wrapper){$dh(this.print_wrapper);$ds(this.page_layout.wrapper);} if(!this.meta.istable){this.refresh_header();this.sidebar&&this.sidebar.refresh();} -this.runclientscript('refresh');this.refresh_tabs();this.refresh_fields();this.refresh_dependency();this.refresh_footer();if(this.layout)this.layout.show();if(is_onload) +this.runclientscript('refresh');$(document).trigger('form_refresh') +this.refresh_tabs();this.refresh_fields();this.refresh_dependency();this.refresh_footer();if(this.layout)this.layout.show();if(is_onload) this.runclientscript('onload_post_render',this.doctype,this.docname);}else{this.refresh_header();if(this.print_wrapper){this.refresh_print_layout();} this.runclientscript('edit_status_changed');} if(!this.display)this.show_the_frm();if(!this.meta.in_dialog)page_body.change_to('Forms');}} diff --git a/js/widgets/form/form.js b/js/widgets/form/form.js index 0202f92e03..fd6034e83c 100644 --- a/js/widgets/form/form.js +++ b/js/widgets/form/form.js @@ -622,6 +622,11 @@ _f.Frm.prototype.refresh = function(docname) { // call trigger this.runclientscript('refresh'); + // trigger global trigger + // to use this + // $(docuemnt).bind('form_refresh', function() { }) + $(document).trigger('form_refresh') + // tabs this.refresh_tabs();