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)
|
value = models.CharField(max_length=100)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.id
|
return self.key
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = 'config'
|
verbose_name = 'config'
|
||||||
@ -43,22 +43,33 @@ class ConfigStore(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Config(object):
|
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):
|
def __getitem__(self, key):
|
||||||
try:
|
try:
|
||||||
return loads(str(ConfigStore.objects.get(pk=key).value))
|
self.config
|
||||||
except ConfigStore.DoesNotExist:
|
except AttributeError:
|
||||||
try:
|
self.load_config()
|
||||||
return DEFAULT_DATA[key]
|
try:
|
||||||
except KeyError:
|
return self.config[key]
|
||||||
return None
|
except KeyError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
return DEFAULT_DATA[key]
|
||||||
|
except KeyError:
|
||||||
|
return None
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
try:
|
try:
|
||||||
c = ConfigStore.objects.get(pk=key)
|
c = self.config.get(pk=key)
|
||||||
except ConfigStore.DoesNotExist:
|
except ConfigStore.DoesNotExist:
|
||||||
c = ConfigStore(pk=key)
|
c = ConfigStore(pk=key)
|
||||||
c.value = dumps(value)
|
c.value = dumps(value)
|
||||||
c.save()
|
c.save()
|
||||||
|
self.config[key] = value
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user