@@ -196,4 +196,5 @@ button.btn::-moz-focus-inner, input[type=submit].btn::-moz-focus-inner { | |||||
-moz-opacity: 0.4; | -moz-opacity: 0.4; | ||||
opacity: 0.4; | opacity: 0.4; | ||||
cursor: pointer; | cursor: pointer; | ||||
font-weight: bold; | |||||
} | } |
@@ -28,13 +28,13 @@ class DocType(): | |||||
other_list = webnotes.conn.sql("""select name from `tabFile Data` | other_list = webnotes.conn.sql("""select name from `tabFile Data` | ||||
where name like '%s-%%.%s' order by name desc""" % (parts[0], '.'.join(parts[1:]))) | where name like '%s-%%.%s' order by name desc""" % (parts[0], '.'.join(parts[1:]))) | ||||
if other_list: | |||||
last_name = other_list[0][0] | |||||
from webnotes.utils import cint | |||||
new_id = str(cint(last_name.split('.')[0].split('-')[-1]) + 1) | |||||
else: | |||||
new_id = '1' | |||||
if other_list: | |||||
last_name = other_list[0][0] | |||||
from webnotes.utils import cint | |||||
new_id = str(cint(last_name.split('.')[0].split('-')[-1]) + 1) | |||||
else: | |||||
new_id = '1' | |||||
# new name | # new name | ||||
self.doc.file_name = parts[0] + '-' + new_id + '.' + '.'.join(parts[1:]) | self.doc.file_name = parts[0] + '-' + new_id + '.' + '.'.join(parts[1:]) | ||||
@@ -65,7 +65,7 @@ class HTTPRequest: | |||||
if webnotes.session['data'].get('profile'): | if webnotes.session['data'].get('profile'): | ||||
webnotes.user.load_from_session(webnotes.session['data']['profile']) | webnotes.user.load_from_session(webnotes.session['data']['profile']) | ||||
else: | else: | ||||
webnotes.user.load_profile() | |||||
webnotes.user.load_profile() | |||||
# set database login | # set database login | ||||
# ------------------ | # ------------------ | ||||
@@ -318,7 +318,8 @@ class Session: | |||||
r=None | r=None | ||||
try: | try: | ||||
r = webnotes.conn.sql("select user, sessiondata, status from tabSessions where sid='%s'" % self.sid) | |||||
r = webnotes.conn.sql("""select user, sessiondata, status from | |||||
tabSessions where sid='%s'""" % self.sid) | |||||
except Exception, e: | except Exception, e: | ||||
if e.args[0]==1054: | if e.args[0]==1054: | ||||
self.add_status_column() | self.add_status_column() | ||||
@@ -344,7 +345,8 @@ class Session: | |||||
webnotes.response['session_status'] = 'Logged Out' | webnotes.response['session_status'] = 'Logged Out' | ||||
raise Exception, 'Logged Out' | raise Exception, 'Logged Out' | ||||
else: | else: | ||||
self.data = {'data':eval(r[1]), 'user':r[0], 'sid': self.sid} | |||||
self.data = {'data': (r[1] and eval(r[1]) or {}), | |||||
'user':r[0], 'sid': self.sid} | |||||
else: | else: | ||||
webnotes.login_manager.login_as_guest() | webnotes.login_manager.login_as_guest() | ||||
self.start() | self.start() | ||||
@@ -64,7 +64,8 @@ class Database: | |||||
Connect to a database | Connect to a database | ||||
""" | """ | ||||
self._conn = MySQLdb.connect(user=self.user, host=self.host, passwd=self.password) | self._conn = MySQLdb.connect(user=self.user, host=self.host, passwd=self.password) | ||||
self._conn.set_character_set('utf8') | |||||
self._conn.converter[246]=float | |||||
self._conn.set_character_set('utf8') | |||||
self._cursor = self._conn.cursor() | self._cursor = self._conn.cursor() | ||||
def use(self, db_name): | def use(self, db_name): | ||||
@@ -119,7 +120,7 @@ class Database: | |||||
""" | """ | ||||
* Execute a `query`, with given `values` | * Execute a `query`, with given `values` | ||||
* returns as a dictionary if as_dict = 1 | * returns as a dictionary if as_dict = 1 | ||||
* returns as a list of lists (with cleaned up dates and decimals) if as_list = 1 | |||||
* returns as a list of lists (with cleaned up dates) if as_list = 1 | |||||
""" | """ | ||||
# in transaction validations | # in transaction validations | ||||
self.check_transaction_status(query) | self.check_transaction_status(query) | ||||
@@ -168,8 +169,6 @@ class Database: | |||||
# ====================================================================================== | # ====================================================================================== | ||||
def convert_to_simple_type(self, v, formatted=0): | def convert_to_simple_type(self, v, formatted=0): | ||||
try: import decimal # for decimal Python 2.5 onwards | |||||
except: pass | |||||
import datetime | import datetime | ||||
from webnotes.utils import formatdate, fmt_money | from webnotes.utils import formatdate, fmt_money | ||||
@@ -193,12 +192,6 @@ class Database: | |||||
# long | # long | ||||
elif type(v)==long: | elif type(v)==long: | ||||
v=int(v) | v=int(v) | ||||
# decimal | |||||
try: | |||||
if type(v)==decimal.Decimal: | |||||
v=float(v) | |||||
except: pass | |||||
# convert to strings... (if formatted) | # convert to strings... (if formatted) | ||||
if formatted: | if formatted: | ||||
@@ -309,7 +302,7 @@ class Database: | |||||
defkey=%s and parent = "Control Panel" """, key): | defkey=%s and parent = "Control Panel" """, key): | ||||
# update | # update | ||||
self.sql("""update `tabDefaultValue` set defvalue="%s" | |||||
self.sql("""update `tabDefaultValue` set defvalue=%s | |||||
where parent = "Control Panel" and defkey=%s""", (val, key)) | where parent = "Control Panel" and defkey=%s""", (val, key)) | ||||
else: | else: | ||||
from webnotes.model.doc import Document | from webnotes.model.doc import Document | ||||
@@ -94,7 +94,9 @@ class DatabaseInstance: | |||||
def create_doctypecache(self): | def create_doctypecache(self): | ||||
self.conn.sql("DROP TABLE IF EXISTS `__DocTypeCache`") | self.conn.sql("DROP TABLE IF EXISTS `__DocTypeCache`") | ||||
self.conn.sql("create table `__DocTypeCache` (name VARCHAR(120), modified DATETIME, content TEXT, server_code_compiled TEXT)") | self.conn.sql("create table `__DocTypeCache` (name VARCHAR(120), modified DATETIME, content TEXT, server_code_compiled TEXT)") | ||||
self.conn.sql(""" | |||||
create table `__SessionCache` (user VARCHAR(120), country VARCHAR(120), cache LONGTEXT) | |||||
""") | |||||
@@ -42,7 +42,12 @@ class Installer: | |||||
import webnotes | import webnotes | ||||
self.dbman.drop_table('__DocTypeCache') | self.dbman.drop_table('__DocTypeCache') | ||||
webnotes.conn.sql("create table `__DocTypeCache` (name VARCHAR(120), modified DATETIME, content TEXT, server_code_compiled TEXT)") | |||||
webnotes.conn.sql("""create table `__DocTypeCache` | |||||
(name VARCHAR(120), modified DATETIME, content TEXT, server_code_compiled TEXT)""") | |||||
self.dbman.drop_table('__SessionCache') | |||||
webnotes.conn.sq.("""create table `__SessionCache` | |||||
(user VARCHAR(120), country VARCHAR(120), cache LONGTEXT)""") | |||||
# set the basic passwords | # set the basic passwords | ||||
webnotes.conn.begin() | webnotes.conn.begin() | ||||
@@ -244,7 +244,7 @@ class Document: | |||||
# Insert | # Insert | ||||
# --------------------------------------------------------------------------- | # --------------------------------------------------------------------------- | ||||
def _makenew(self, autoname, istable, case='', make_autoname=1): | |||||
def insert(self, autoname, istable, case='', make_autoname=1): | |||||
# set name | # set name | ||||
if make_autoname: | if make_autoname: | ||||
self._set_name(autoname, istable) | self._set_name(autoname, istable) | ||||
@@ -371,9 +371,14 @@ class Document: | |||||
res = webnotes.model.meta.get_dt_values(self.doctype, 'autoname, issingle, istable, name_case', as_dict=1) | res = webnotes.model.meta.get_dt_values(self.doctype, 'autoname, issingle, istable, name_case', as_dict=1) | ||||
res = res and res[0] or {} | res = res and res[0] or {} | ||||
# add missing parentinfo (if reqd) | |||||
if self.parent and not (self.parenttype and self.parentfield): | |||||
self.update_parentinfo() | |||||
# if required, make new | # if required, make new | ||||
if new or (not new and self.fields.get('__islocal')) and (not res.get('issingle')): | if new or (not new and self.fields.get('__islocal')) and (not res.get('issingle')): | ||||
r = self._makenew(res.get('autoname'), res.get('istable'), res.get('name_case'), make_autoname) | |||||
r = self.insert(res.get('autoname'), res.get('istable'), res.get('name_case'), \ | |||||
make_autoname) | |||||
if r: | if r: | ||||
return r | return r | ||||
@@ -381,6 +386,24 @@ class Document: | |||||
self._update_values(res.get('issingle'), check_links and self.make_link_list() or {}, ignore_fields) | self._update_values(res.get('issingle'), check_links and self.make_link_list() or {}, ignore_fields) | ||||
self._clear_temp_fields() | self._clear_temp_fields() | ||||
def update_parentinfo(self): | |||||
"""update parent type and parent field, if not explicitly specified""" | |||||
tmp = webnotes.conn.sql("""select parent, fieldname from tabDocField | |||||
where fieldtype='Table' and options=%s""", self.doctype) | |||||
if len(tmp)==0: | |||||
raise Exception, 'Incomplete parent info in child table (%s, %s)' \ | |||||
% (self.doctype, self.fields.get('name', '[new]')) | |||||
elif len(tmp)>1: | |||||
raise Exception, 'Ambiguous parent info (%s, %s)' \ | |||||
% (self.doctype, self.fields.get('name', '[new]')) | |||||
else: | |||||
self.parenttype = tmp[0][0] | |||||
self.parentfield = tmp[0][1] | |||||
# check permissions | # check permissions | ||||
# --------------------------------------------------------------------------- | # --------------------------------------------------------------------------- | ||||
@@ -15,7 +15,7 @@ class Profile: | |||||
self.can_get_report = [] | self.can_get_report = [] | ||||
def _load_roles(self): | def _load_roles(self): | ||||
res = webnotes.conn.sql('select role from tabUserRole where parent = "%s"' % self.name) | |||||
res = webnotes.conn.sql('select role from tabUserRole where parent = %s', self.name) | |||||
self.roles = [] | self.roles = [] | ||||
for t in res: | for t in res: | ||||
if t[0]: self.roles.append(t[0]) | if t[0]: self.roles.append(t[0]) | ||||
@@ -32,7 +32,7 @@ class Profile: | |||||
""" | """ | ||||
if self.roles: | if self.roles: | ||||
return self.roles | return self.roles | ||||
return self._load_roles() | return self._load_roles() | ||||
def get_allow_list(self, key): | def get_allow_list(self, key): | ||||
@@ -13,16 +13,14 @@ def clear(): | |||||
def clear_cache(user=''): | def clear_cache(user=''): | ||||
"""clear cache""" | """clear cache""" | ||||
try: | |||||
if user: | |||||
webnotes.conn.sql("delete from __SessionCache where user=%s", user) | |||||
else: | |||||
webnotes.conn.sql("delete from __SessionCache") | |||||
except Exception, e: | |||||
if e.args[0]==1146: | |||||
make_cache_table() | |||||
else: | |||||
raise e | |||||
if user: | |||||
webnotes.conn.sql("delete from __SessionCache where user=%s", user) | |||||
webnotes.conn.sql("update tabSessions set sessiondata=NULL where user=%s", user) | |||||
else: | |||||
webnotes.conn.sql("delete from __SessionCache") | |||||
webnotes.conn.sql("update tabSessions set sessiondata=NULL") | |||||
webnotes.session['data'] = {} | |||||
def get(): | def get(): | ||||
"""get session boot info""" | """get session boot info""" | ||||
@@ -70,8 +68,3 @@ def add_to_cache(sd, country): | |||||
# make new | # make new | ||||
webnotes.conn.sql("insert into `__SessionCache` (user, country, cache) VALUES (%s, %s, %s)", (webnotes.session['user'], country, str(sd))) | webnotes.conn.sql("insert into `__SessionCache` (user, country, cache) VALUES (%s, %s, %s)", (webnotes.session['user'], country, str(sd))) | ||||
def make_cache_table(): | |||||
webnotes.conn.commit() | |||||
webnotes.conn.sql("create table `__SessionCache` (user VARCHAR(120), country VARCHAR(120), cache LONGTEXT)") | |||||
webnotes.conn.begin() |
@@ -327,9 +327,6 @@ def parse_val(v): | |||||
""" | """ | ||||
import datetime | import datetime | ||||
try: import decimal # for decimal Python 2.5 (?) | |||||
except: pass | |||||
if type(v)==datetime.date: | if type(v)==datetime.date: | ||||
v = str(v) | v = str(v) | ||||
elif type(v)==datetime.timedelta: | elif type(v)==datetime.timedelta: | ||||
@@ -338,10 +335,6 @@ def parse_val(v): | |||||
v = str(v) | v = str(v) | ||||
elif type(v)==long: v=int(v) | elif type(v)==long: v=int(v) | ||||
try: | |||||
if type(v)==decimal.Decimal: v=float(v) | |||||
except: pass | |||||
return v | return v | ||||
# ============================================================================== | # ============================================================================== | ||||
@@ -26,7 +26,8 @@ def get_master_fields(dt): | |||||
webnotes.session['data']['auto_masters'] = {} | webnotes.session['data']['auto_masters'] = {} | ||||
if webnotes.session['data']['auto_masters'].get(dt, None)==None: | if webnotes.session['data']['auto_masters'].get(dt, None)==None: | ||||
fl = webnotes.conn.sql("select fieldname from tabDocField where fieldtype='Data' and options='Suggest' and parent=%s", dt) | |||||
fl = webnotes.conn.sql("select fieldname from tabDocField where fieldtype='Data' \ | |||||
and options='Suggest' and parent=%s", dt) | |||||
webnotes.session['data']['auto_masters'][dt] = fl | webnotes.session['data']['auto_masters'][dt] = fl | ||||
return webnotes.session['data']['auto_masters'][dt] | return webnotes.session['data']['auto_masters'][dt] | ||||