pickle config-values to save complex data
This commit is contained in:
parent
114a68b120
commit
7174e93988
@ -9,6 +9,7 @@
|
|||||||
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
||||||
:license: GNU GPL, see LICENSE for more details.
|
:license: GNU GPL, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
from pickle import dumps, loads
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
@ -44,7 +45,7 @@ class ConfigStore(models.Model):
|
|||||||
class Config(object):
|
class Config(object):
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
try:
|
try:
|
||||||
return ConfigStore.objects.get(pk=key).value
|
return loads(str(ConfigStore.objects.get(pk=key).value))
|
||||||
except ConfigStore.DoesNotExist:
|
except ConfigStore.DoesNotExist:
|
||||||
try:
|
try:
|
||||||
return DEFAULT_DATA[key]
|
return DEFAULT_DATA[key]
|
||||||
@ -56,7 +57,8 @@ class Config(object):
|
|||||||
c = ConfigStore.objects.get(pk=key)
|
c = ConfigStore.objects.get(pk=key)
|
||||||
except ConfigStore.DoesNotExist:
|
except ConfigStore.DoesNotExist:
|
||||||
c = ConfigStore(pk=key)
|
c = ConfigStore(pk=key)
|
||||||
c.value = value
|
c.value = dumps(value)
|
||||||
c.save()
|
c.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user