Finally got around to creating admin.py files for all of the apps. This will prevent some really weird import errors and fixes an issue with the Attribute model's admin display. May also cut resource usage slightly for MUD server instances. Needs more testing!

This commit is contained in:
Greg Taylor 2009-04-17 03:08:18 +00:00
parent 1da2179ee6
commit 573d1b6e88
9 changed files with 49 additions and 62 deletions

15
src/config/admin.py Normal file
View file

@ -0,0 +1,15 @@
from src.config.models import CommandAlias, ConfigValue, ConnectScreen
from django.contrib import admin
class CommandAliasAdmin(admin.ModelAdmin):
list_display = ('user_input', 'equiv_command')
admin.site.register(CommandAlias, CommandAliasAdmin)
class ConfigValueAdmin(admin.ModelAdmin):
list_display = ('conf_key', 'conf_value')
admin.site.register(ConfigValue, ConfigValueAdmin)
class ConnectScreenAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'is_active')
list_display_links = ('id', 'name')
admin.site.register(ConnectScreen, ConnectScreenAdmin)

View file

@ -1,5 +1,4 @@
from django.db import models from django.db import models
from django.contrib import admin
from src.config.managers.commandalias import CommandAliasManager from src.config.managers.commandalias import CommandAliasManager
from src.config.managers.configvalue import ConfigValueManager from src.config.managers.configvalue import ConfigValueManager
from src.config.managers.connectscreen import ConnectScreenManager from src.config.managers.connectscreen import ConnectScreenManager
@ -17,13 +16,6 @@ class CommandAlias(models.Model):
class Meta: class Meta:
verbose_name_plural = "Command aliases" verbose_name_plural = "Command aliases"
ordering = ['user_input'] ordering = ['user_input']
class CommandAliasAdmin(admin.ModelAdmin):
list_display = ('user_input', 'equiv_command')
pass
# This is causing an error for some reason
#admin.site.register(CommandAlias, CommandAliasAdmin)
admin.site.register(CommandAlias)
class ConfigValue(models.Model): class ConfigValue(models.Model):
""" """
@ -36,10 +28,6 @@ class ConfigValue(models.Model):
def __unicode__(self): def __unicode__(self):
return "%s" % self.conf_key return "%s" % self.conf_key
class ConfigValueAdmin(admin.ModelAdmin):
list_display = ('conf_key', 'conf_value')
admin.site.register(ConfigValue, ConfigValueAdmin)
class ConnectScreen(models.Model): class ConnectScreen(models.Model):
""" """
@ -50,9 +38,4 @@ class ConnectScreen(models.Model):
text = models.TextField(help_text="The text for the connect screen. Color codes and substitutions are evaluated.") 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") is_active = models.BooleanField(default=1, help_text="Only active connect screens are placed in the rotation")
objects = ConnectScreenManager() objects = ConnectScreenManager()
class ConnectScreenAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'is_active')
list_display_links = ('id', 'name')
admin.site.register(ConnectScreen, ConnectScreenAdmin)

9
src/helpsys/admin.py Normal file
View file

@ -0,0 +1,9 @@
from django.contrib import admin
from src.helpsys.models import HelpEntry
class HelpEntryAdmin(admin.ModelAdmin):
list_display = ('id', 'topicname', 'staff_only')
list_display_links = ('id', 'topicname')
list_filter = ('staff_only',)
search_fields = ['topicname', 'entrytext']
admin.site.register(HelpEntry, HelpEntryAdmin)

View file

@ -2,9 +2,8 @@
Models for the help system. Models for the help system.
""" """
from django.db import models from django.db import models
from django.contrib import admin
from src import ansi from src import ansi
from src.helpsys.managers.helpentry import HelpEntryManager from src.helpsys.managers import HelpEntryManager
class HelpEntry(models.Model): class HelpEntry(models.Model):
""" """
@ -33,11 +32,4 @@ class HelpEntry(models.Model):
""" """
Gets the entry text for in-game viewing. Gets the entry text for in-game viewing.
""" """
return ansi.parse_ansi(self.entrytext) return ansi.parse_ansi(self.entrytext)
class HelpEntryAdmin(admin.ModelAdmin):
list_display = ('id', 'topicname', 'staff_only')
list_display_links = ('id', 'topicname')
list_filter = ('staff_only',)
search_fields = ['topicname', 'entrytext']
admin.site.register(HelpEntry, HelpEntryAdmin)

22
src/objects/admin.py Normal file
View file

@ -0,0 +1,22 @@
from src.objects.models import Attribute, Object, CommChannel, CommChannelMessage
from django.contrib import admin
class AttributeAdmin(admin.ModelAdmin):
list_display = ('attr_object', 'attr_name', 'attr_value',)
search_fields = ['attr_name']
admin.site.register(Attribute, AttributeAdmin)
class ObjectAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'type', 'date_created')
list_filter = ('type',)
search_fields = ['name']
save_on_top = True
admin.site.register(Object, ObjectAdmin)
class CommChannelAdmin(admin.ModelAdmin):
list_display = ('name', 'owner')
admin.site.register(CommChannel, CommChannelAdmin)
class CommChannelMessageAdmin(admin.ModelAdmin):
list_display = ('channel', 'message')
admin.site.register(CommChannelMessage, CommChannelMessageAdmin)

View file

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

View file

@ -4,10 +4,8 @@ This is where all of the crucial, core object models reside.
import re import re
from django.db import models from django.db import models
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.contrib import admin
from django.conf import settings from django.conf import settings
from src.objects.util import object as util_object from src.objects.util import object as util_object
from src.objects.managers.commchannel import CommChannelManager
from src.objects.managers.object import ObjectManager from src.objects.managers.object import ObjectManager
from src.objects.managers.attribute import AttributeManager from src.objects.managers.attribute import AttributeManager
from src.config.models import ConfigValue from src.config.models import ConfigValue
@ -88,11 +86,6 @@ class Attribute(models.Model):
ANSITable.ansi["normal"], ANSITable.ansi["normal"],
self.get_value()) self.get_value())
class AttributeAdmin(admin.ModelAdmin):
list_display = ('attr_object', 'attr_name', 'attr_value',)
search_fields = ['attr_name']
admin.site.register(Attribute, AttributeAdmin)
class Object(models.Model): class Object(models.Model):
""" """
The Object class is very generic representation of a THING, PLAYER, EXIT, The Object class is very generic representation of a THING, PLAYER, EXIT,
@ -976,13 +969,6 @@ class Object(models.Model):
# about tuple index types. Bleh. # about tuple index types. Bleh.
otype = int(self.type) otype = int(self.type)
return defines_global.OBJECT_TYPES[otype][1][0] return defines_global.OBJECT_TYPES[otype][1][0]
class ObjectAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'type', 'date_created')
list_filter = ('type',)
search_fields = ['name']
save_on_top = True
admin.site.register(Object, ObjectAdmin)
class CommChannel(models.Model): class CommChannel(models.Model):
""" """
@ -994,8 +980,6 @@ class CommChannel(models.Model):
description = models.CharField(max_length=80, blank=True, null=True) description = models.CharField(max_length=80, blank=True, null=True)
is_joined_by_default = models.BooleanField(default=False) is_joined_by_default = models.BooleanField(default=False)
req_grp = models.ManyToManyField(Group, blank=True, null=True) req_grp = models.ManyToManyField(Group, blank=True, null=True)
objects = CommChannelManager()
def __str__(self): def __str__(self):
return "%s" % (self.name,) return "%s" % (self.name,)
@ -1072,10 +1056,6 @@ class CommChannel(models.Model):
""" """
return self.name[:3].lower() return self.name[:3].lower()
class CommChannelAdmin(admin.ModelAdmin):
list_display = ('name', 'owner')
admin.site.register(CommChannel, CommChannelAdmin)
class CommChannelMessage(models.Model): class CommChannelMessage(models.Model):
""" """
A single logged channel message. A single logged channel message.
@ -1083,18 +1063,12 @@ class CommChannelMessage(models.Model):
channel = models.ForeignKey(CommChannel, related_name="msg_channel") channel = models.ForeignKey(CommChannel, related_name="msg_channel")
message = models.CharField(max_length=255) message = models.CharField(max_length=255)
date_sent = models.DateTimeField(editable=False, auto_now_add=True) date_sent = models.DateTimeField(editable=False, auto_now_add=True)
objects = CommChannelManager()
def __str__(self): def __str__(self):
return "%s: %s" % (self.sender.name, self.message) return "%s: %s" % (self.sender.name, self.message)
class Meta: class Meta:
ordering = ['-date_sent'] ordering = ['-date_sent']
class CommChannelMessageAdmin(admin.ModelAdmin):
list_display = ('channel', 'message')
admin.site.register(CommChannelMessage, CommChannelMessageAdmin)
# Deferred imports are poopy. This will require some thought to fix. # Deferred imports are poopy. This will require some thought to fix.
from src import cmdhandler from src import cmdhandler