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

This commit is contained in:
Anand Doshi 2011-08-25 17:08:45 +05:30
commit fbc26eeaed
11 changed files with 256 additions and 579 deletions

View file

@ -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,15 +107,32 @@
# 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
@ -181,7 +141,6 @@
'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,13 +199,23 @@
# DocField
{
'doctype': 'DocField',
'fieldname': 'occupation',
'fieldtype': 'Column Break',
'oldfieldtype': 'Column Break',
'permlevel': 1,
'width': '50%'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'email',
'fieldtype': 'Data',
'idx': 15,
'label': 'Designation',
'oldfieldname': 'occupation',
'hidden': 0,
'label': 'Email',
'oldfieldname': 'email',
'oldfieldtype': 'Data',
'permlevel': 0,
'reqd': 1,
'search_index': 0
},
@ -286,36 +224,49 @@
'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,151 +293,28 @@
'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
{
'colour': 'White:FFF',
@ -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
}
]

View file

@ -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',

View file

@ -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)
ip = ip.replace(",", "\n").split('\n')
ip = [i.strip() for i in ip]
if not ip_list:
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'
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
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
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
# --------------

View file

@ -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)
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):

View file

@ -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

View file

@ -131,7 +131,10 @@ class POP3Mailbox:
num = len(self.pop.list()[1])
for m in range(num):
msg = self.pop.retr(m+1)
try:
self.process_message(IncomingMail('\n'.join(msg[1])))
except:
pass
self.pop.dele(m+1)
self.pop.quit()

View file

@ -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');}}
@ -256,18 +257,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='<textarea class="code_text" readonly=1>'+val+'</textarea>';}}
_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='<div>'+label+'</div>';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<this.head_row.cells.length;i++){var c=this.head_row.cells[i];if(label&&(c.label==label||c.cur_label==label)){if(show){var w=c.orig_width;this.head_tab.style.width=(this.total_width+cint(w))+'px';this.tab.style.width=(this.total_width+cint(w))+'px';}else{var w='0px';this.head_tab.style.width=(this.total_width-cint(c.orig_width))+'px';this.tab.style.width=(this.total_width-cint(c.orig_width))+'px';}
$w(c,w);if(this.tab){for(var j=0;j<this.tab.rows.length;j++){var cell=this.tab.rows[j].cells[i];$w(cell,w);if(show){$ds(cell.div);cell.div.style.padding='2px';}
else{$dh(cell.div);cell.div.style.padding='0px';}}}
break;}}}
_f.Grid.prototype.append_row=function(idx,docname){if(!idx)idx=this.tab.rows.length;var row=this.tab.insertRow(idx);row.docname=docname;if(idx%2)var odd=true;else var odd=false;var me=this;for(var i=0;i<this.head_row.cells.length;i++){var cell=row.insertCell(i);var hc=this.head_row.cells[i];$w(cell,hc.style.width);cell.row=row;cell.grid=this;cell.className='grid_cell';cell.div=$a(cell,'div','grid_cell_div');if(this.row_height){cell.div.style.height=this.row_height;}
_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';}
var col=this.head_row.insertCell(idx);col.doctype=doctype;col.fieldname=fieldname;col.fieldtype=fieldtype;col.innerHTML='<div>'+label+'</div>';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<len;i++){w+=cint(this.head_row.cells[i].style.width);}
this.head_tab.style.width=w+'px';this.tab.style.width=w+'px';}
_f.Grid.prototype.set_column_disp=function(fieldname,show){var cidx=this.col_idx_by_name[fieldname];if(!cidx){msgprint('Trying to hide unknown column: '+fieldname);return;}
var disp=show?'table-cell':'none';this.head_row.cells[cidx].style.display=disp;for(var i=0,len=this.tab.rows.length;i<len;i++){var cell=this.tab.rows[i].cells[cidx];cell.style.display=disp;}
this.reset_table_width();}
_f.Grid.prototype.append_row=function(idx,docname){if(!idx)idx=this.tab.rows.length;var row=this.tab.insertRow(idx);row.docname=docname;if(idx%2)var odd=true;else var odd=false;var me=this;for(var i=0;i<this.head_row.cells.length;i++){var cell=row.insertCell(i);var hc=this.head_row.cells[i];cell.style.width=hc.style.width;cell.row=row;cell.grid=this;cell.className='grid_cell';cell.div=$a(cell,'div','grid_cell_div');if(this.row_height){cell.div.style.height=this.row_height;}
cell.div.cell=cell;cell.div.onclick=function(e){me.cell_click(this.cell,e);}
if(odd){$bg(cell,this.alt_row_bg);cell.is_odd=1;cell.div.style.border='2px solid '+this.alt_row_bg;}else $bg(cell,'#FFF');if(!hc.fieldname)cell.div.style.cursor='default';}
this.set_ht();return row;}
@ -299,7 +303,7 @@ return;if(!_f.cur_grid_cell)return;if(_f.cur_grid_cell.grid!=this)return;var ri=
_f.Grid.prototype.make_template=function(hc){hc.template=make_field(get_field(hc.doctype,hc.fieldname),hc.doctype,'',this.field.frm,true);hc.template.grid=this;}
_f.Grid.prototype.append_rows=function(n){for(var i=0;i<n;i++)this.append_row();}
_f.Grid.prototype.truncate_rows=function(n){for(var i=0;i<n;i++)this.tab.deleteRow(this.tab.rows.length-1);}
_f.Grid.prototype.set_data=function(data){this.cell_deselect();this.tab.style.width=this.total_width+'px';this.head_tab.style.width=this.total_width+'px';if(data.length>this.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<this.tab.rows.length)
this.truncate_rows(this.tab.rows.length-data.length);for(var ridx=0;ridx<data.length;ridx++){this.refresh_row(ridx,data[ridx]);}
if(this.can_add_rows&&this.make_newrow){this.make_newrow();}
@ -315,8 +319,7 @@ $td(t,0,0).isactive=1;$td(t,0,1).isactive=1;l.isactive=1;div.isactive=1;img.isac
_f.FormGrid.prototype.make_buttons=function(){var me=this;this.tbar_btns={};this.tbar_btns['Del']=this.make_tbar_link($td(this.tbar_tab,0,0),'Del',function(){me.delete_row();},'ic-round_minus');this.tbar_btns['Ins']=this.make_tbar_link($td(this.tbar_tab,0,1),'Ins',function(){me.insert_row();},'ic-round_plus');this.tbar_btns['Up']=this.make_tbar_link($td(this.tbar_tab,0,2),'Up',function(){me.move_row(true);},'ic-arrow_top');this.tbar_btns['Dn']=this.make_tbar_link($td(this.tbar_tab,0,3),'Dn',function(){me.move_row(false);},'ic-arrow_bottom');for(var i in this.btns)
this.btns[i].isactive=true;}
_f.FormGrid.prototype.make_columns=function(){var gl=fields_list[this.field.df.options];if(!gl){alert('Table details not found "'+this.field.df.options+'"');}
gl.sort(function(a,b){return a.idx-b.idx});var p=this.field.perm;for(var i=0;i<gl.length;i++){if(p[this.field.df.permlevel]&&p[this.field.df.permlevel][READ]&&(!gl[i].hidden)){this.insert_column(this.field.df.options,gl[i].fieldname,gl[i].fieldtype,gl[i].label,gl[i].width,gl[i].options,this.field.perm,gl[i].reqd);}}
for(var i=0;i<this.head_row.cells.length;i++){var c=this.head_row.cells[i];$w(c,cint(cint(c.style.width)/this.total_width*100)+'%')}}
gl.sort(function(a,b){return a.idx-b.idx});var p=this.field.perm;for(var i=0;i<gl.length;i++){if(p[this.field.df.permlevel]&&p[this.field.df.permlevel][READ]&&(!gl[i].hidden)){this.insert_column(this.field.df.options,gl[i].fieldname,gl[i].fieldtype,gl[i].label,gl[i].width,gl[i].options,this.field.perm,gl[i].reqd);}}}
_f.FormGrid.prototype.set_column_label=function(fieldname,label){for(var i=0;i<this.head_row.cells.length;i++){var c=this.head_row.cells[i];if(c.fieldname==fieldname){c.innerHTML='<div class="grid_head_div">'+label+'</div>';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<docset.length;i++){locals[this.doctype][docset[i].name].idx=i+1;data[data.length]=docset[i].name;}
this.set_data(data);}

View file

@ -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();

View file

@ -71,12 +71,6 @@ _f.FormGrid.prototype.make_columns = function() {
this.insert_column(this.field.df.options, gl[i].fieldname, gl[i].fieldtype, gl[i].label, gl[i].width, gl[i].options, this.field.perm, gl[i].reqd);
}
}
// set width as percent
for(var i=0;i<this.head_row.cells.length; i++) {
var c = this.head_row.cells[i];
$w(c,cint(cint(c.style.width) / this.total_width * 100)+'%')
}
}
_f.FormGrid.prototype.set_column_label = function(fieldname, label) {

View file

@ -5,6 +5,7 @@ _f.Grid = function(parent) { }
_f.Grid.prototype.init = function(parent, row_height) {
this.col_idx_by_name = {}
this.alt_row_bg = '#F2F2FF';
this.row_height = row_height;
@ -14,11 +15,10 @@ _f.Grid.prototype.init = function(parent, row_height) {
// Sr No
this.insert_column('', '', 'Int', 'Sr', '50px', '', [1,0,0]);
this.total_width = 50;
if(this.oninit)this.oninit();
keypress_observers.push(this)
keypress_observers.push(this);
}
_f.Grid.prototype.make_ui = function(parent) {
@ -62,8 +62,10 @@ _f.Grid.prototype.hide = function() {
_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';
if(!width)width = '140px';
if((width+'').slice(-2)!='px') {
width= width + 'px';
}
var col = this.head_row.insertCell(idx);
col.doctype = doctype; // for report (fields may be from diff doctypes)
@ -74,43 +76,42 @@ _f.Grid.prototype.insert_column = function(doctype, fieldname, fieldtype, label,
if(reqd)
col.childNodes[0].style.color = "#D22";
this.total_width += cint(width);
$w(col, width);
col.orig_width = col.style.width;
col.style.width = width;
col.options = options;
col.perm = perm;
this.col_idx_by_name[fieldname] = idx;
}
_f.Grid.prototype.set_column_disp = function(label, show) {
//alert(label);
for(var i=0; i<this.head_row.cells.length; i++) {
var c = this.head_row.cells[i];
if(label && (c.label == label || c.cur_label == label)) {
//alert(c.orig_width);
if(show) {
var w = c.orig_width;
this.head_tab.style.width = (this.total_width + cint(w)) + 'px';
this.tab.style.width = (this.total_width + cint(w)) + 'px';
} else {
var w = '0px';
this.head_tab.style.width = (this.total_width - cint(c.orig_width)) + 'px';
this.tab.style.width = (this.total_width - cint(c.orig_width)) + 'px';
_f.Grid.prototype.reset_table_width = function() {
var w = 0;
for(var i=0, len=this.head_row.cells.length; i<len; i++) {
w += cint(this.head_row.cells[i].style.width);
}
$w(c, w);
// change width of table too
if(this.tab) {
for(var j=0; j<this.tab.rows.length; j++) {
var cell = this.tab.rows[j].cells[i];
$w(cell, w);
if(show) { $ds(cell.div); cell.div.style.padding = '2px'; }
else { $dh(cell.div); cell.div.style.padding = '0px'; }
this.head_tab.style.width = w + 'px';
this.tab.style.width = w + 'px';
}
_f.Grid.prototype.set_column_disp = function(fieldname, show) {
var cidx = this.col_idx_by_name[fieldname];
if(!cidx) {
msgprint('Trying to hide unknown column: ' + fieldname);
return;
}
break;
}
var disp = show ? 'table-cell' : 'none';
// head
this.head_row.cells[cidx].style.display = disp;
// body
for(var i=0, len=this.tab.rows.length; i<len; i++) {
var cell = this.tab.rows[i].cells[cidx];
cell.style.display = disp;
}
// reset table width
this.reset_table_width();
}
_f.Grid.prototype.append_row = function(idx, docname) {
@ -125,7 +126,7 @@ _f.Grid.prototype.append_row = function(idx, docname) {
for(var i=0; i<this.head_row.cells.length; i++){
var cell = row.insertCell(i);
var hc = this.head_row.cells[i];
$w(cell, hc.style.width);
cell.style.width = hc.style.width;
cell.row = row;
cell.grid = this;
cell.className = 'grid_cell';
@ -394,8 +395,7 @@ _f.Grid.prototype.set_data = function(data) {
this.cell_deselect();
// set table widths
this.tab.style.width = this.total_width + 'px';
this.head_tab.style.width = this.total_width + 'px';
this.reset_table_width();
// append if reqd
if(data.length > this.tab.rows.length)

View file

@ -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<sl.length; i++) {
this.dt.add_sort_option(sl[i][0], sl[i][1]);
}