Merge branch 'edge' of github.com:webnotes/wnframework into edge
This commit is contained in:
commit
539cd2b5a9
6 changed files with 38 additions and 53 deletions
|
|
@ -282,6 +282,4 @@ wn.datetime.comment_when = prettyDate;
|
|||
// globals (deprecate)
|
||||
var date = dateutil = wn.datetime;
|
||||
var get_today = wn.datetime.get_today
|
||||
var time_to_ampm = wn.datetime.time_to_ampm;
|
||||
var time_to_hhmm = wn.datetime.time_to_hhmm;
|
||||
var only_date = wn.datetime.only_date;
|
||||
|
|
|
|||
|
|
@ -238,13 +238,16 @@ def whitelist(allow_guest=False, allow_roles=[]):
|
|||
return innerfn
|
||||
|
||||
def clear_cache(user=None, doctype=None):
|
||||
"""clear boot cache"""
|
||||
"""clear cache"""
|
||||
if doctype:
|
||||
from webnotes.model.doctype import clear_cache
|
||||
clear_cache(doctype)
|
||||
elif user:
|
||||
from webnotes.sessions import clear_cache
|
||||
clear_cache(user)
|
||||
else:
|
||||
from webnotes.sessions import clear
|
||||
clear(user)
|
||||
from webnotes.sessions import clear_cache
|
||||
clear_cache()
|
||||
|
||||
def get_roles(user=None, with_standard=True):
|
||||
"""get roles of current user"""
|
||||
|
|
|
|||
|
|
@ -78,9 +78,11 @@ def get_bootinfo():
|
|||
return bootinfo
|
||||
|
||||
def load_country_and_currency(bootinfo, doclist):
|
||||
if bootinfo.control_panel.country:
|
||||
if bootinfo.control_panel.country and \
|
||||
webnotes.conn.exists("Country", bootinfo.control_panel.country):
|
||||
doclist += [webnotes.doc("Country", bootinfo.control_panel.country)]
|
||||
if bootinfo.sysdefaults.currency:
|
||||
if bootinfo.sysdefaults.currency and \
|
||||
webnotes.conn.exists("Currency", bootinfo.sysdefaults.currency):
|
||||
doclist += [webnotes.doc("Currency", bootinfo.sysdefaults.currency)]
|
||||
|
||||
def add_allowed_pages(bootinfo):
|
||||
|
|
|
|||
|
|
@ -31,38 +31,9 @@ class MClient(memcache.Client):
|
|||
|
||||
def set_value(self, key, val):
|
||||
self.set(self.n(key), val)
|
||||
self.add_to_key_list(key)
|
||||
|
||||
def get_value(self, key):
|
||||
return self.get(self.n(key))
|
||||
|
||||
def delete_value(self, key):
|
||||
self.delete(self.n(key))
|
||||
|
||||
def add_to_key_list(self, key):
|
||||
key_list = self.get_value('key_list') or []
|
||||
if key not in key_list:
|
||||
key_list.append(key)
|
||||
self.set(self.n("key_list"), key_list)
|
||||
|
||||
def delete_keys(self, startswith=None):
|
||||
"""flush keys from known key_list"""
|
||||
if not startswith:
|
||||
for key in self.get_value('key_list'):
|
||||
self.delete_value(key)
|
||||
|
||||
self.delete_value('key_list')
|
||||
else:
|
||||
deleted = []
|
||||
keys = self.get_value('key_list') or []
|
||||
for key in keys:
|
||||
if key.startswith(startswith):
|
||||
self.delete(self.n(key))
|
||||
deleted.append(key)
|
||||
|
||||
for d in deleted:
|
||||
keys.remove(d)
|
||||
|
||||
self.set_value("key_list", keys)
|
||||
# in any case, delete it explicitly
|
||||
self.delete(self.n(startswith))
|
||||
self.delete(self.n(key))
|
||||
|
|
@ -234,7 +234,7 @@ def cache_name(doctype, processed):
|
|||
suffix = ":Raw"
|
||||
return "doctype:" + doctype + suffix
|
||||
|
||||
def clear_cache(doctype):
|
||||
def clear_cache(doctype=None):
|
||||
global doctype_cache
|
||||
|
||||
def clear_single(dt):
|
||||
|
|
@ -244,12 +244,18 @@ def clear_cache(doctype):
|
|||
if doctype in doctype_cache:
|
||||
del doctype_cache[dt]
|
||||
|
||||
clear_single(doctype)
|
||||
if doctype:
|
||||
clear_single(doctype)
|
||||
|
||||
# clear all parent doctypes
|
||||
for dt in webnotes.conn.sql("""select parent from tabDocField
|
||||
where fieldtype="Table" and options=%s""", doctype):
|
||||
clear_single(dt[0])
|
||||
# clear all parent doctypes
|
||||
for dt in webnotes.conn.sql("""select parent from tabDocField
|
||||
where fieldtype="Table" and options=%s""", doctype):
|
||||
clear_single(dt[0])
|
||||
|
||||
else:
|
||||
# clear all
|
||||
for dt in webnotes.conn.sql("""select name from tabDocType"""):
|
||||
clear_single(dt[0])
|
||||
|
||||
def add_code(doctype, doclist):
|
||||
import os, conf
|
||||
|
|
|
|||
|
|
@ -31,23 +31,28 @@ import webnotes
|
|||
import conf
|
||||
import json
|
||||
from webnotes.utils import cint
|
||||
import webnotes.model.doctype
|
||||
|
||||
@webnotes.whitelist()
|
||||
def clear(user=None):
|
||||
"""clear all cache"""
|
||||
clear_cache(user)
|
||||
clear_cache(webnotes.session.user)
|
||||
webnotes.response['message'] = "Cache Cleared"
|
||||
|
||||
|
||||
def clear_cache(user=None):
|
||||
"""clear cache"""
|
||||
webnotes.cache().delete_keys("bootinfo:")
|
||||
webnotes.cache().delete_keys("doctype:")
|
||||
webnotes.cache().delete_keys("session:")
|
||||
if webnotes.session:
|
||||
webnotes.cache().delete_keys("bootinfo:" + webnotes.session.user)
|
||||
if webnotes.session.sid:
|
||||
webnotes.cache().delete_keys("session:" + webnotes.session.sid)
|
||||
cache = webnotes.cache()
|
||||
|
||||
# clear doctype cache
|
||||
webnotes.model.doctype.clear_cache()
|
||||
|
||||
if user:
|
||||
cache.delete_value("bootinfo:" + user)
|
||||
if webnotes.session and webnotes.session.sid:
|
||||
cache.delete_value("session:" + webnotes.session.sid)
|
||||
else:
|
||||
for sess in webnotes.conn.sql("""select user, sid from tabSessions""", as_dict=1):
|
||||
cache.delete_value("sesssion:" + sess.sid)
|
||||
cache.delete_value("bootinfo:" + sess.user)
|
||||
|
||||
def clear_sessions(user=None, keep_current=False):
|
||||
if not user:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue