load config at once
This commit is contained in:
parent
70f1cb8b3e
commit
a404c3fe89
@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
openslides.system.admin
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Register app for admin site.
|
||||
|
||||
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
||||
:license: GNU GPL, see LICENSE for more details.
|
||||
"""
|
||||
|
||||
from django.contrib import admin
|
||||
from system.models import ConfigStore
|
||||
|
||||
admin.site.register(ConfigStore)
|
@ -33,7 +33,7 @@ class ConfigStore(models.Model):
|
||||
value = models.CharField(max_length=100)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.id
|
||||
return self.key
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'config'
|
||||
@ -43,10 +43,20 @@ class ConfigStore(models.Model):
|
||||
|
||||
|
||||
class Config(object):
|
||||
def load_config(self):
|
||||
self.config = {}
|
||||
for key, value in ConfigStore.objects.all().values_list():
|
||||
self.config[key] = loads(str(value))
|
||||
|
||||
def __getitem__(self, key):
|
||||
try:
|
||||
return loads(str(ConfigStore.objects.get(pk=key).value))
|
||||
except ConfigStore.DoesNotExist:
|
||||
self.config
|
||||
except AttributeError:
|
||||
self.load_config()
|
||||
try:
|
||||
return self.config[key]
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
return DEFAULT_DATA[key]
|
||||
except KeyError:
|
||||
@ -54,11 +64,12 @@ class Config(object):
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
try:
|
||||
c = ConfigStore.objects.get(pk=key)
|
||||
c = self.config.get(pk=key)
|
||||
except ConfigStore.DoesNotExist:
|
||||
c = ConfigStore(pk=key)
|
||||
c.value = dumps(value)
|
||||
c.save()
|
||||
self.config[key] = value
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user