fix config

This commit is contained in:
j 2011-09-16 18:45:25 +02:00
parent 131fe30a58
commit 6a6ba425bb
3 changed files with 33 additions and 18 deletions

View file

@ -23,6 +23,21 @@ class Page(models.Model):
RUN_RELOADER = True RUN_RELOADER = True
def load_config():
with open(settings.SITE_CONFIG) as f:
config = json.load(f)
config['site']['id'] = settings.SITEID
config['site']['name'] = settings.SITENAME
config['site']['sectionName'] = settings.SITENAME
config['site']['url'] = settings.URL
config['keys'] = {}
for key in config['itemKeys']:
config['keys'][key['id']] = key
settings.CONFIG = config
def reloader_thread(): def reloader_thread():
_config_mtime = 0 _config_mtime = 0
while RUN_RELOADER: while RUN_RELOADER:
@ -31,21 +46,8 @@ def reloader_thread():
if _win: if _win:
mtime -= stat.st_ctime mtime -= stat.st_ctime
if mtime > _config_mtime: if mtime > _config_mtime:
with open(settings.SITE_CONFIG) as f: load_config()
config = json.load(f)
config['site']['id'] = settings.SITEID
config['site']['name'] = settings.SITENAME
config['site']['sectionName'] = settings.SITENAME
config['site']['url'] = settings.URL
config['keys'] = {}
for key in config['itemKeys']:
config['keys'][key['id']] = key
settings.CONFIG = config
_config_mtime = mtime _config_mtime = mtime
time.sleep(1) time.sleep(1)
thread.start_new_thread(reloader_thread, ()) thread.start_new_thread(reloader_thread, ())

View file

@ -45,7 +45,7 @@ def parseCondition(condition):
else: else:
return q return q
key_type = settings.config['keys'].get(k, {'type':'string'}).get('type') key_type = settings.CONFIG['keys'].get(k, {'type':'string'}).get('type')
if isinstance(key_type, list): if isinstance(key_type, list):
key_type = key_type[0] key_type = key_type[0]
key_type = { key_type = {
@ -247,11 +247,11 @@ class ItemManager(Manager):
#anonymous can only see public items #anonymous can only see public items
if user.is_anonymous(): if user.is_anonymous():
allowed_level = settings.config['capabilities']['canSeeItem']['guest'] allowed_level = settings.CONFIG['capabilities']['canSeeItem']['guest']
qs = qs.filter(level__lte=allowed_level) qs = qs.filter(level__lte=allowed_level)
#users can see public items, there own items and items of there groups #users can see public items, there own items and items of there groups
else: else:
allowed_level = settings.config['capabilities']['canSeeItem'][user.get_profile().get_level()] allowed_level = settings.CONFIG['capabilities']['canSeeItem'][user.get_profile().get_level()]
qs = qs.filter(Q(level__lte=allowed_level)|Q(user=user)|Q(groups__in=user.groups.all())) qs = qs.filter(Q(level__lte=allowed_level)|Q(user=user)|Q(groups__in=user.groups.all()))
#admins can see all available items #admins can see all available items
return qs return qs

View file

@ -120,9 +120,9 @@ INSTALLED_APPS = (
'devserver', 'devserver',
# 'south', # 'south',
'djcelery', 'djcelery',
'app',
'annotation', 'annotation',
'app',
'archive', 'archive',
'event', 'event',
'item', 'item',
@ -245,3 +245,16 @@ except NameError:
except IOError: except IOError:
Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE) Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)
from ox.utils import json
with open(SITE_CONFIG) as f:
CONFIG = json.load(f)
CONFIG['site']['id'] = SITEID
CONFIG['site']['name'] = SITENAME
CONFIG['site']['sectionName'] = SITENAME
CONFIG['site']['url'] = URL
CONFIG['keys'] = {}
for key in CONFIG['itemKeys']:
CONFIG['keys'][key['id']] = key