From ffe9a563e052206409c1d2bfb6e840453115639b Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sat, 14 Jun 2008 03:15:41 +0000 Subject: [PATCH] Removing mixins.py, as it's not in use. We now have a separate ConnectScreen model under the config app to store connect screens. ConfigValue's value fields are now CharFields instead of TextFields for the sake of efficiency and sanity. It is strongly recommended that you reset your config app and syncdb to load the fixture. --- apps/config/fixtures/initial_data.json | 2 +- apps/config/models.py | 28 ++++++++++++++++++++++++++ gameconf.py | 3 ++- mixins.py | 22 -------------------- session.py | 9 ++++++--- 5 files changed, 37 insertions(+), 27 deletions(-) delete mode 100644 mixins.py diff --git a/apps/config/fixtures/initial_data.json b/apps/config/fixtures/initial_data.json index bdb3d2ff64..b6d659975e 100644 --- a/apps/config/fixtures/initial_data.json +++ b/apps/config/fixtures/initial_data.json @@ -1 +1 @@ -[{"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"}}, {"pk": 8, "model": "config.configvalue", "fields": {"conf_value": "\n%ch%cb==================================================================%cn\n Welcome to Evennia! Please type one of the following to begin:\n\n If you have an existing account, connect to it by typing:\n %chconnect %cn\n If you need to create an account, type (without the <>'s):\n %chcreate \"\" %cn\n%ch%cb==================================================================%cn\n", "conf_key": "connect_screen"}}] +[{"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 %cn\r\n If you need to create an account, type (without the <>'s):\r\n %chcreate \"\" %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"}}] diff --git a/apps/config/models.py b/apps/config/models.py index 81413c2f97..044be567fc 100755 --- a/apps/config/models.py +++ b/apps/config/models.py @@ -24,3 +24,31 @@ class ConfigValue(models.Model): class Admin: list_display = ('conf_key', 'conf_value',) + +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 + +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") + + # Custom manager + objects = ConnectScreenManager() + + class Admin: + list_display = ('id', 'name', 'is_active') diff --git a/gameconf.py b/gameconf.py index 786973fca8..b6aced9a93 100644 --- a/gameconf.py +++ b/gameconf.py @@ -1,7 +1,7 @@ import os from traceback import format_exc -from apps.config.models import ConfigValue +from apps.config.models import ConfigValue, ConnectScreen import functions_general """ Handle the setting/retrieving of server config directives. @@ -31,3 +31,4 @@ def set_configvalue(configname, newvalue): conf = ConfigValue.objects.get(conf_key=configname) conf.conf_value = newvalue conf.save() + diff --git a/mixins.py b/mixins.py deleted file mode 100644 index 4d254d14d4..0000000000 --- a/mixins.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -The ReloadMixin class is meant as an example, but should work -for basic purposes as a mixin inheritance. -""" -class ReloadMixin(): - """ - This class is a generic reload mixin providing the two - methods required to cache and reload an object. - """ - def cache(self, reloader, do_save=True): - if do_save: - if self.save and callable(self.save): - self.save() - else: - raise ValueError("This object does not have a save function, you must pass do_save=False for this object type.") - - reloader.cache_object(self) - - def reload(self, cache): - for key, value in cache.iteritems(): - if self.__dict__[key] != value: - self.__dict__[key] = value diff --git a/session.py b/session.py index 222542e71e..34ff1d2ffa 100755 --- a/session.py +++ b/session.py @@ -4,9 +4,11 @@ import cPickle as pickle from twisted.conch.telnet import StatefulTelnetProtocol -import cmdhandler -from apps.objects.models import Object from django.contrib.auth.models import User + +from apps.objects.models import Object +from apps.config.models import ConnectScreen +import cmdhandler import functions_db import functions_general import session_mgr @@ -121,7 +123,8 @@ class SessionProtocol(StatefulTelnetProtocol): """ Show the banner screen. Grab from the 'connect_screen' config directive. """ - buffer = ansi.parse_ansi(gameconf.get_configvalue('connect_screen')) + screen = ConnectScreen.objects.get_random_connect_screen() + buffer = ansi.parse_ansi(screen.connect_screen_text) self.msg(buffer) def is_loggedin(self):