From 6a6ba425bbaeaf2e1fbe7a8d3d08c21f21a6be93 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 16 Sep 2011 18:45:25 +0200 Subject: [PATCH 1/3] fix config --- pandora/app/models.py | 30 ++++++++++++++++-------------- pandora/item/managers.py | 6 +++--- pandora/settings.py | 15 ++++++++++++++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/pandora/app/models.py b/pandora/app/models.py index b0c5f8a7..d9f3ac40 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 67d7b03a..beffc51c 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 3307483e..c1f4658f 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 + From e2a6c8a663732d33502ca84b485c4ea8c8d79ae2 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 16 Sep 2011 13:17:49 -0400 Subject: [PATCH 2/3] anon does not have a profile --- pandora/item/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 361f0452..468d5f37 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -128,7 +128,8 @@ class Item(models.Model): #while metadata is updated, files are set to rendered=False rendered = models.BooleanField(default=False, db_index=True) - level = models.IntegerField(default=False, db_index=True) + #should be set based on user + level = models.IntegerField(default=4, db_index=True) itemId = models.CharField(max_length=128, unique=True, blank=True) oxdbId = models.CharField(max_length=42, unique=True, blank=True, null=True) @@ -162,7 +163,11 @@ class Item(models.Model): return default def access(self, user): - allowed_level = settings.CONFIG['capabilities']['canSeeItem'][user.get_profile().get_level()] + if user.is_anonymous(): + level = 'guest' + else: + level = user.get_profile().get_level() + allowed_level = settings.CONFIG['capabilities']['canSeeItem'][level] if self.level < allowed_level: return True elif user.is_authenticated() and \ From ef344bee2642e0ef23dc592b14a3ce5f8e57d30c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 16 Sep 2011 19:22:14 +0200 Subject: [PATCH 3/3] gunicorn workaound --- pandora/urls.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandora/urls.py b/pandora/urls.py index e962204d..fe53cc5b 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -7,6 +7,9 @@ from ox.django.http import HttpFileResponse from django.conf import settings +#gunicorn has issues with settings.CONFIG otherwise +import app.models + # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover()