diff --git a/pandora/app/models.py b/pandora/app/models.py index b0c5f8a7e..d9f3ac40a 100644 --- a/pandora/app/models.py +++ b/pandora/app/models.py @@ -23,6 +23,21 @@ class Page(models.Model): 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(): _config_mtime = 0 while RUN_RELOADER: @@ -31,21 +46,8 @@ def reloader_thread(): if _win: mtime -= stat.st_ctime if mtime > _config_mtime: - 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 + load_config() _config_mtime = mtime time.sleep(1) thread.start_new_thread(reloader_thread, ()) - diff --git a/pandora/item/managers.py b/pandora/item/managers.py index 67d7b03a8..beffc51c4 100644 --- a/pandora/item/managers.py +++ b/pandora/item/managers.py @@ -45,7 +45,7 @@ def parseCondition(condition): else: 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): key_type = key_type[0] key_type = { @@ -247,11 +247,11 @@ class ItemManager(Manager): #anonymous can only see public items 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) #users can see public items, there own items and items of there groups 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())) #admins can see all available items return qs diff --git a/pandora/settings.py b/pandora/settings.py index 3307483ee..c1f4658fa 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -120,9 +120,9 @@ INSTALLED_APPS = ( 'devserver', # 'south', 'djcelery', + 'app', 'annotation', - 'app', 'archive', 'event', 'item', @@ -245,3 +245,16 @@ except NameError: except IOError: 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 +