Browse Source

redid file system naming, fixed bug that did not clear roles on 'clear cache'

version-14
Rushabh Mehta 13 years ago
parent
commit
cb7d2e0b80
11 changed files with 63 additions and 50 deletions
  1. +1
    -0
      css/legacy/bootstrap-buttons.css
  2. +7
    -7
      py/core/doctype/file_data/file_data.py
  3. +5
    -3
      py/webnotes/auth.py
  4. +4
    -11
      py/webnotes/db.py
  5. +3
    -1
      py/webnotes/install_lib/db_init.py
  6. +6
    -1
      py/webnotes/install_lib/install.py
  7. +25
    -2
      py/webnotes/model/doc.py
  8. +2
    -2
      py/webnotes/profile.py
  9. +8
    -15
      py/webnotes/session_cache.py
  10. +0
    -7
      py/webnotes/utils/__init__.py
  11. +2
    -1
      py/webnotes/widgets/auto_master.py

+ 1
- 0
css/legacy/bootstrap-buttons.css View File

@@ -196,4 +196,5 @@ button.btn::-moz-focus-inner, input[type=submit].btn::-moz-focus-inner {
-moz-opacity: 0.4;
opacity: 0.4;
cursor: pointer;
font-weight: bold;
}

+ 7
- 7
py/core/doctype/file_data/file_data.py View File

@@ -28,13 +28,13 @@ class DocType():
other_list = webnotes.conn.sql("""select name from `tabFile Data`
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
self.doc.file_name = parts[0] + '-' + new_id + '.' + '.'.join(parts[1:])


+ 5
- 3
py/webnotes/auth.py View File

@@ -65,7 +65,7 @@ class HTTPRequest:
if webnotes.session['data'].get('profile'):
webnotes.user.load_from_session(webnotes.session['data']['profile'])
else:
webnotes.user.load_profile()
webnotes.user.load_profile()

# set database login
# ------------------
@@ -318,7 +318,8 @@ class Session:
r=None
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:
if e.args[0]==1054:
self.add_status_column()
@@ -344,7 +345,8 @@ class Session:
webnotes.response['session_status'] = 'Logged Out'
raise Exception, 'Logged Out'
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:
webnotes.login_manager.login_as_guest()
self.start()


+ 4
- 11
py/webnotes/db.py View File

@@ -64,7 +64,8 @@ class Database:
Connect to a database
"""
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()
def use(self, db_name):
@@ -119,7 +120,7 @@ class Database:
"""
* Execute a `query`, with given `values`
* 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
self.check_transaction_status(query)
@@ -168,8 +169,6 @@ class Database:
# ======================================================================================

def convert_to_simple_type(self, v, formatted=0):
try: import decimal # for decimal Python 2.5 onwards
except: pass
import datetime
from webnotes.utils import formatdate, fmt_money

@@ -193,12 +192,6 @@ class Database:
# long
elif type(v)==long:
v=int(v)

# decimal
try:
if type(v)==decimal.Decimal:
v=float(v)
except: pass
# convert to strings... (if formatted)
if formatted:
@@ -309,7 +302,7 @@ class Database:
defkey=%s and parent = "Control Panel" """, key):
# update
self.sql("""update `tabDefaultValue` set defvalue="%s"
self.sql("""update `tabDefaultValue` set defvalue=%s
where parent = "Control Panel" and defkey=%s""", (val, key))
else:
from webnotes.model.doc import Document


+ 3
- 1
py/webnotes/install_lib/db_init.py View File

@@ -94,7 +94,9 @@ class DatabaseInstance:
def create_doctypecache(self):
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 `__SessionCache` (user VARCHAR(120), country VARCHAR(120), cache LONGTEXT)
""")



+ 6
- 1
py/webnotes/install_lib/install.py View File

@@ -42,7 +42,12 @@ class Installer:

import webnotes
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
webnotes.conn.begin()


+ 25
- 2
py/webnotes/model/doc.py View File

@@ -244,7 +244,7 @@ class Document:
# Insert
# ---------------------------------------------------------------------------
def _makenew(self, autoname, istable, case='', make_autoname=1):
def insert(self, autoname, istable, case='', make_autoname=1):
# set name
if make_autoname:
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 = 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 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:
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._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
# ---------------------------------------------------------------------------



+ 2
- 2
py/webnotes/profile.py View File

@@ -15,7 +15,7 @@ class Profile:
self.can_get_report = []
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 = []
for t in res:
if t[0]: self.roles.append(t[0])
@@ -32,7 +32,7 @@ class Profile:
"""
if self.roles:
return self.roles
return self._load_roles()
def get_allow_list(self, key):


+ 8
- 15
py/webnotes/session_cache.py View File

@@ -13,16 +13,14 @@ def clear():

def clear_cache(user=''):
"""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():
"""get session boot info"""
@@ -70,8 +68,3 @@ def add_to_cache(sd, country):

# make new
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()

+ 0
- 7
py/webnotes/utils/__init__.py View File

@@ -327,9 +327,6 @@ def parse_val(v):
"""
import datetime
try: import decimal # for decimal Python 2.5 (?)
except: pass

if type(v)==datetime.date:
v = str(v)
elif type(v)==datetime.timedelta:
@@ -338,10 +335,6 @@ def parse_val(v):
v = str(v)
elif type(v)==long: v=int(v)

try:
if type(v)==decimal.Decimal: v=float(v)
except: pass

return v
# ==============================================================================


+ 2
- 1
py/webnotes/widgets/auto_master.py View File

@@ -26,7 +26,8 @@ def get_master_fields(dt):
webnotes.session['data']['auto_masters'] = {}
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
return webnotes.session['data']['auto_masters'][dt]


Loading…
Cancel
Save