Starting here, trunk is broken pending re-organizations. Check out the previous revision if you'd like to tinker.

This commit is contained in:
Greg Taylor 2008-12-15 04:00:25 +00:00
parent 4b25a08597
commit 837f1152c6
28 changed files with 0 additions and 0 deletions

0
src/config/__init__.py Executable file
View file

View file

@ -0,0 +1 @@
[{"pk": 1, "model": "config.connectscreen", "fields": {"is_active": 1, "name": "Default", "connect_screen_text": "%ch%cb==================================================================%cn\r\n Welcome to Evennia! Please type one of the following to begin:\r\n\r\n If you have an existing account, connect to it by typing:\r\n %chconnect <email> <password2>%cn\r\n If you need to create an account, type (without the <>'s):\r\n %chcreate \"<username>\" <email> <password>%cn\r\n%ch%cb==================================================================%cn\r\n"}}, {"pk": 9, "model": "config.commandalias", "fields": {"user_input": "@desc", "equiv_command": "@describe"}}, {"pk": 3, "model": "config.commandalias", "fields": {"user_input": "@dest", "equiv_command": "@destroy"}}, {"pk": 4, "model": "config.commandalias", "fields": {"user_input": "@nuke", "equiv_command": "@destroy"}}, {"pk": 6, "model": "config.commandalias", "fields": {"user_input": "@tel", "equiv_command": "@teleport"}}, {"pk": 2, "model": "config.commandalias", "fields": {"user_input": "ex", "equiv_command": "examine"}}, {"pk": 7, "model": "config.commandalias", "fields": {"user_input": "i", "equiv_command": "inventory"}}, {"pk": 8, "model": "config.commandalias", "fields": {"user_input": "inv", "equiv_command": "inventory"}}, {"pk": 1, "model": "config.commandalias", "fields": {"user_input": "l", "equiv_command": "look"}}, {"pk": 5, "model": "config.commandalias", "fields": {"user_input": "sa", "equiv_command": "say"}}, {"pk": 1, "model": "config.configvalue", "fields": {"conf_value": "Evennia Test Site", "conf_key": "site_name"}}, {"pk": 2, "model": "config.configvalue", "fields": {"conf_value": "2", "conf_key": "player_dbnum_start"}}, {"pk": 3, "model": "config.configvalue", "fields": {"conf_value": "Credits", "conf_key": "money_name_plural"}}, {"pk": 4, "model": "config.configvalue", "fields": {"conf_value": "Credit", "conf_key": "money_name_singular"}}, {"pk": 5, "model": "config.configvalue", "fields": {"conf_value": "0", "conf_key": "game_firstrun"}}, {"pk": 6, "model": "config.configvalue", "fields": {"conf_value": "1800", "conf_key": "idle_timeout"}}, {"pk": 7, "model": "config.configvalue", "fields": {"conf_value": "2", "conf_key": "default_home"}}]

View file

View file

@ -0,0 +1,8 @@
"""
Custom manager for CommandAlias objects.
"""
from django.db import models
class CommandAliasManager(models.Manager):
pass

View file

@ -0,0 +1,32 @@
"""
Custom manager for ConfigValue objects.
"""
from traceback import format_exc
from django.db import models
from src import logger
class ConfigValueManager(models.Manager):
def get_configvalue(self, configname):
"""
Retrieve a configuration value.
"""
try:
return self.get(conf_key__iexact=configname).conf_value
except self.model.DoesNotExist:
logger.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:
logger.log_errmsg("Unable to set config value for %s (does not exist):\n%s" % (
configname, (format_exc())))

View file

@ -0,0 +1,17 @@
"""
Custom manager for ConnectScreen objects.
"""
from django.db import models
class ConnectScreenManager(models.Manager):
def get_random_connect_screen(self):
"""
Returns a random active connect screen.
"""
try:
return self.filter(is_active=True).order_by('?')[0]
except IndexError:
new_screen = ConnectScreen(name='Default',
connect_screen_text='This is a placeholder connect screen. Remind your admin to edit it through the Admin interface.')
new_screen.save()
return new_screen

54
src/config/models.py Executable file
View file

@ -0,0 +1,54 @@
from django.db import models
from django.contrib import admin
from apps.config.managers.commandalias import CommandAliasManager
from apps.config.managers.configvalue import ConfigValueManager
from apps.config.managers.connectscreen import ConnectScreenManager
class CommandAlias(models.Model):
"""
Command aliases. If the player enters the value equal to user_input, the
command denoted by equiv_command is used instead.
"""
user_input = models.CharField(max_length=50)
equiv_command = models.CharField(max_length=50)
objects = CommandAliasManager()
class Admin:
list_display = ('user_input', 'equiv_command',)
class Meta:
verbose_name_plural = "Command aliases"
ordering = ['user_input']
admin.site.register(CommandAlias)
class ConfigValue(models.Model):
"""
Experimental new config model.
"""
conf_key = models.CharField(max_length=100)
conf_value = models.TextField()
objects = ConfigValueManager()
class Admin:
list_display = ('conf_key', 'conf_value',)
def __str__(self):
return "%s" % self.conf_key
admin.site.register(ConfigValue)
class ConnectScreen(models.Model):
"""
Stores connect screens. The admins may have only one or multiple, which
will cycle randomly.
"""
name = models.CharField(max_length=255, help_text="An optional name for this screen (for organizational purposes).", blank=True)
connect_screen_text = models.TextField(help_text="The text for the connect screen. Color codes and substitutions are evaluated.")
is_active = models.BooleanField(default=1, help_text="Only active connect screens are placed in the rotation")
objects = ConnectScreenManager()
class Admin:
list_display = ('id', 'name', 'is_active')
admin.site.register(ConnectScreen)

1
src/config/views.py Executable file
View file

@ -0,0 +1 @@
# Create your views here.