From 6f0d76b5c5d15878e96e49abd5eb5f0a36af2857 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 14 Jan 2011 14:32:48 +0000 Subject: [PATCH] do not chach site.json --- pandora/app/models.py | 13 +++++++------ pandora/item/managers.py | 2 +- pandora/item/models.py | 13 +++++++------ pandora/item/views.py | 5 +++-- pandora/user/models.py | 5 +++-- pandora/user/views.py | 2 +- static/js/pandora.js | 25 ++----------------------- 7 files changed, 24 insertions(+), 41 deletions(-) diff --git a/pandora/app/models.py b/pandora/app/models.py index dd0198668..e406d0ef2 100644 --- a/pandora/app/models.py +++ b/pandora/app/models.py @@ -23,9 +23,10 @@ class SiteSettings(models.Model): def __unicode__(self): return self.key -with open(os.path.join(settings.PROJECT_ROOT, 'templates', 'site.json')) as f: - site_config = json.load(f) - site_config['keys'] = {} - for key in site_config['sortKeys']: - site_config['keys'][key['id']] = key - +def site_config(): + with open(os.path.join(settings.PROJECT_ROOT, 'templates', 'site.json')) as f: + site_config = json.load(f) + site_config['keys'] = {} + for key in site_config['sortKeys']: + site_config['keys'][key['id']] = key + return site_config diff --git a/pandora/item/managers.py b/pandora/item/managers.py index 9739b507a..216bee6b6 100644 --- a/pandora/item/managers.py +++ b/pandora/item/managers.py @@ -34,7 +34,7 @@ def parseCondition(condition): else: exclude = False - key_type = models.site_config['keys'].get(k, {'type':'string'}).get('type') + key_type = models.site_config()['keys'].get(k, {'type':'string'}).get('type') key_type = { 'title': 'string', 'person': 'string', diff --git a/pandora/item/models.py b/pandora/item/models.py index 741feda23..c9c03ebc8 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -304,7 +304,7 @@ class Item(models.Model): } item.update(self.external_data) item.update(self.data) - for key in site_config['keys'].keys(): + for key in site_config()['keys'].keys(): if key not in item: value = self.get(key) #also get values from sort table, i.e. numberof values @@ -416,7 +416,7 @@ class Item(models.Model): 'modified', 'popularity' ) - for key in site_config['sortKeys']: + for key in site_config()['sortKeys']: name = key['id'] source = key.get('key', name) field_type = key['type'] @@ -763,11 +763,12 @@ class Item(models.Model): Item.facet_keys = [] Item.person_keys = [] -for key in site_config['findKeys']: +config = site_config() +for key in config['findKeys']: name = key['id'] - if key.get('autocomplete', False) and not site_config['keys'].get(name, {'type': None})['type'] == 'title': + if key.get('autocomplete', False) and not config['keys'].get(name, {'type': None})['type'] == 'title': Item.facet_keys.append(name) - if name in site_config['keys'] and site_config['keys'][name]['type'] == 'person': + if name in config['keys'] and config['keys'][name]['type'] == 'person': Item.person_keys.append(name) class ItemFind(models.Model): @@ -792,7 +793,7 @@ attrs = { '__module__': 'item.models', 'item': models.OneToOneField('Item', related_name='sort', primary_key=True), } -for key in site_config['sortKeys']: +for key in config['sortKeys']: name = key['id'] name = {'id': 'itemId'}.get(name, name) field_type = key['type'] diff --git a/pandora/item/views.py b/pandora/item/views.py index a3600f2c6..98404a2c8 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -238,7 +238,8 @@ def autocomplete(request): data['range'] = [0, 10] op = data.get('operator', '') - if models.site_config['keys'][data['key']]['type'] == 'title': + site_config = models.site_config() + if site_config['keys'][data['key']]['type'] == 'title': qs = models.Item.objects.filter(available=True) #does this need more limiting? user etc if data['value']: if op == '': @@ -247,7 +248,7 @@ def autocomplete(request): qs = qs.filter(find__key=data['key'], find__value__istartswith=data['value']) elif op == '$': qs = qs.filter(find__key=data['key'], find__value__iendswith=data['value']) - qs = qs.order_by('-sort__%s'%models.site_config['keys'][data['key']]['autocompleteSortKey']) + qs = qs.order_by('-sort__%s'%site_config['keys'][data['key']]['autocompleteSortKey']) qs = qs[data['range'][0]:data['range'][1]] response = json_response({}) response['data']['items'] = [i.get(data['key']) for i in qs] diff --git a/pandora/user/models.py b/pandora/user/models.py index 2a8d1aa66..7ecad533d 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -31,11 +31,12 @@ class UserProfile(models.Model): def get_ui(self): ui = {} - ui.update(site_config['user']['ui']) + config = site_config() + ui.update(config['user']['ui']) ui.update(self.ui) if not 'lists' in ui: ui['lists'] = {} - ui['lists'][''] = site_config['uiDefaults']['list'] + ui['lists'][''] = config['uiDefaults']['list'] def add(lists, section): ids = [] diff --git a/pandora/user/views.py b/pandora/user/views.py index 7a98d7001..6f9b2dd80 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -101,7 +101,7 @@ def signout(request): response = json_response(text='logged out') logout(request) - response['data']['user'] = site_config['user'] + response['data']['user'] = site_config()['user'] return render_to_json_response(response) actions.register(signout, cache=False) diff --git a/static/js/pandora.js b/static/js/pandora.js index a699b8fd6..5f6634ea2 100755 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -35,27 +35,6 @@ var pandora = new Ox.App({ $.browser.safari && Ox.theme('modern'); } - // fixme: remove - app.uiDefaults = { - "list": { - "columns": ["id", "title", "director", "country", "year", "language", "runtime", "genre"], - "listView": "icons", - "selected": [], - "sort": [ - {"key": "director", "operator": ""} - ] - } - } - // fixme: remove - app.user.ui.showSection = { - "my": true, - "public": true, - "featured": true - } - - // $.each(pandora.afterLaunch, function(i, f) { f(); }); - - function load() { $(function() { @@ -2623,7 +2602,7 @@ var pandora = new Ox.App({ type: data.id == 'new' ? 'static' : 'smart' }, function(result) { id = result.data.id; - app.user.ui.lists[id] = app.uiDefaults.list; + app.user.ui.lists[id] = app.config.uiDefaults.list; URL.set('?find=list:' + id) Ox.Request.emptyCache(); // fixme: remove $list.reloadList().bindEvent({load: load}); @@ -3031,7 +3010,7 @@ var pandora = new Ox.App({ $list.resizeColumn(i == 1 ? 'id' : 'name', width - 88); } if (!app.user.ui.showSection[id]) { - //app.$ui.section[i].update(); + app.$ui.section[i].update(); } }); }