do not chach site.json

This commit is contained in:
j 2011-01-14 14:32:48 +00:00
parent bbaa947384
commit b73c86e5bf
7 changed files with 24 additions and 41 deletions

View file

@ -23,9 +23,10 @@ class SiteSettings(models.Model):
def __unicode__(self): def __unicode__(self):
return self.key return self.key
with open(os.path.join(settings.PROJECT_ROOT, 'templates', 'site.json')) as f: def site_config():
site_config = json.load(f) with open(os.path.join(settings.PROJECT_ROOT, 'templates', 'site.json')) as f:
site_config['keys'] = {} site_config = json.load(f)
for key in site_config['sortKeys']: site_config['keys'] = {}
site_config['keys'][key['id']] = key for key in site_config['sortKeys']:
site_config['keys'][key['id']] = key
return site_config

View file

@ -34,7 +34,7 @@ def parseCondition(condition):
else: else:
exclude = False 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 = { key_type = {
'title': 'string', 'title': 'string',
'person': 'string', 'person': 'string',

View file

@ -304,7 +304,7 @@ class Item(models.Model):
} }
item.update(self.external_data) item.update(self.external_data)
item.update(self.data) item.update(self.data)
for key in site_config['keys'].keys(): for key in site_config()['keys'].keys():
if key not in item: if key not in item:
value = self.get(key) value = self.get(key)
#also get values from sort table, i.e. numberof values #also get values from sort table, i.e. numberof values
@ -416,7 +416,7 @@ class Item(models.Model):
'modified', 'modified',
'popularity' 'popularity'
) )
for key in site_config['sortKeys']: for key in site_config()['sortKeys']:
name = key['id'] name = key['id']
source = key.get('key', name) source = key.get('key', name)
field_type = key['type'] field_type = key['type']
@ -763,11 +763,12 @@ class Item(models.Model):
Item.facet_keys = [] Item.facet_keys = []
Item.person_keys = [] Item.person_keys = []
for key in site_config['findKeys']: config = site_config()
for key in config['findKeys']:
name = key['id'] 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) 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) Item.person_keys.append(name)
class ItemFind(models.Model): class ItemFind(models.Model):
@ -792,7 +793,7 @@ attrs = {
'__module__': 'item.models', '__module__': 'item.models',
'item': models.OneToOneField('Item', related_name='sort', primary_key=True), '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 = key['id']
name = {'id': 'itemId'}.get(name, name) name = {'id': 'itemId'}.get(name, name)
field_type = key['type'] field_type = key['type']

View file

@ -238,7 +238,8 @@ def autocomplete(request):
data['range'] = [0, 10] data['range'] = [0, 10]
op = data.get('operator', '') 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 qs = models.Item.objects.filter(available=True) #does this need more limiting? user etc
if data['value']: if data['value']:
if op == '': if op == '':
@ -247,7 +248,7 @@ def autocomplete(request):
qs = qs.filter(find__key=data['key'], find__value__istartswith=data['value']) qs = qs.filter(find__key=data['key'], find__value__istartswith=data['value'])
elif op == '$': elif op == '$':
qs = qs.filter(find__key=data['key'], find__value__iendswith=data['value']) 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]] qs = qs[data['range'][0]:data['range'][1]]
response = json_response({}) response = json_response({})
response['data']['items'] = [i.get(data['key']) for i in qs] response['data']['items'] = [i.get(data['key']) for i in qs]

View file

@ -31,11 +31,12 @@ class UserProfile(models.Model):
def get_ui(self): def get_ui(self):
ui = {} ui = {}
ui.update(site_config['user']['ui']) config = site_config()
ui.update(config['user']['ui'])
ui.update(self.ui) ui.update(self.ui)
if not 'lists' in ui: if not 'lists' in ui:
ui['lists'] = {} ui['lists'] = {}
ui['lists'][''] = site_config['uiDefaults']['list'] ui['lists'][''] = config['uiDefaults']['list']
def add(lists, section): def add(lists, section):
ids = [] ids = []

View file

@ -101,7 +101,7 @@ def signout(request):
response = json_response(text='logged out') response = json_response(text='logged out')
logout(request) logout(request)
response['data']['user'] = site_config['user'] response['data']['user'] = site_config()['user']
return render_to_json_response(response) return render_to_json_response(response)
actions.register(signout, cache=False) actions.register(signout, cache=False)

View file

@ -35,27 +35,6 @@ var pandora = new Ox.App({
$.browser.safari && Ox.theme('modern'); $.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 load() {
$(function() { $(function() {
@ -2623,7 +2602,7 @@ var pandora = new Ox.App({
type: data.id == 'new' ? 'static' : 'smart' type: data.id == 'new' ? 'static' : 'smart'
}, function(result) { }, function(result) {
id = result.data.id; 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) URL.set('?find=list:' + id)
Ox.Request.emptyCache(); // fixme: remove Ox.Request.emptyCache(); // fixme: remove
$list.reloadList().bindEvent({load: load}); $list.reloadList().bindEvent({load: load});
@ -3031,7 +3010,7 @@ var pandora = new Ox.App({
$list.resizeColumn(i == 1 ? 'id' : 'name', width - 88); $list.resizeColumn(i == 1 ? 'id' : 'name', width - 88);
} }
if (!app.user.ui.showSection[id]) { if (!app.user.ui.showSection[id]) {
//app.$ui.section[i].update(); app.$ui.section[i].update();
} }
}); });
} }