The first of many re-arrangements. Eliminated gameconf in favor of using the manager on ConfigValue. Moved some commands while I was at it. There are going to be crash bugs that need to be found and worked out.

This commit is contained in:
Greg Taylor 2008-06-15 17:21:02 +00:00
parent 8a1204ce76
commit d620f3b1f0
17 changed files with 216 additions and 200 deletions

View file

@ -1,8 +1,32 @@
"""
Custom manager for ConfigValue objects.
"""
from traceback import format_exc
from django.db import models
import functions_log
class ConfigValueManager(models.Manager):
pass
def get_configvalue(self, configname):
"""
Retrieve a configuration value.
"""
try:
return self.get(conf_key__iexact=configname).conf_value
except self.model.DoesNotExist:
functions_log.log_errmsg("Unable to get config value for %s (does not exist):\n%s" % (
configname, (format_exc())))
def set_configvalue(self, configname, newvalue):
"""
Sets a configuration value with the specified name.
Returns the new value for the directive.
"""
try:
conf = self.get(conf_key=configname)
conf.conf_value = newvalue
conf.save()
# We'll do this instead of conf.conf_value, might save a DB query.
return newvalue
except self.model.DoesNotExist:
functions_log.log_errmsg("Unable to set config value for %s (does not exist):\n%s" % (
configname, (format_exc())))

View file

@ -32,6 +32,9 @@ class ConfigValue(models.Model):
class Admin:
list_display = ('conf_key', 'conf_value',)
def __str__(self):
return "%s" % self.conf_key
class ConnectScreen(models.Model):
"""
Stores connect screens. The admins may have only one or multiple, which

View file

@ -5,8 +5,8 @@ from django.contrib.auth.models import User, Group
import scripthandler
import defines_global
import gameconf
import ansi
from apps.config.models import ConfigValue
from apps.objects.managers.commchannel import CommChannelManager
from apps.objects.managers.object import ObjectManager
@ -439,7 +439,7 @@ class Object(models.Model):
# Gather up everything, other than exits and going/garbage, that is under
# the belief this is its location.
objs = self.obj_location.filter(type__in=[1,2,3])
default_home_id = gameconf.get_configvalue('default_home')
default_home_id = ConfigValue.objects.get_configvalue('default_home')
try:
default_home = Object.objects.get(id=default_home_id)
except: