I've been meaning to do this for a while as well. Break CommChannel and CommChannelMessage out into a separate app. I had them lumped in with objects/models.py due to some funkage with the admin site registering that is now resolved.
NOTE: You will need to syncdb and re-create any channels you may have had. Sorry for the inconvenience, we're still early enough in development where breakages like this may happen once in a blue moon.
This commit is contained in:
parent
42f11b208b
commit
9f86a4c586
6 changed files with 7 additions and 115 deletions
|
|
@ -3,10 +3,8 @@ Comsys functions.
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.utils import simplejson
|
from django.utils import simplejson
|
||||||
|
from src.channels.models import CommChannel, CommChannelMessage
|
||||||
from src.objects.models import CommChannel, CommChannelMessage
|
|
||||||
from src import session_mgr
|
from src import session_mgr
|
||||||
from src import ansi
|
from src import ansi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -212,6 +212,7 @@ INSTALLED_APPS = (
|
||||||
'django.contrib.flatpages',
|
'django.contrib.flatpages',
|
||||||
'src.config',
|
'src.config',
|
||||||
'src.objects',
|
'src.objects',
|
||||||
|
'src.channels',
|
||||||
'src.imc2',
|
'src.imc2',
|
||||||
'src.helpsys',
|
'src.helpsys',
|
||||||
'src.genperms',
|
'src.genperms',
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from src.objects.models import CommChannel
|
from src.channels.models import CommChannel
|
||||||
|
|
||||||
class IMC2ChannelMapping(models.Model):
|
class IMC2ChannelMapping(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from src.objects.models import Attribute, Object, CommChannel, CommChannelMessage
|
from src.objects.models import Attribute, Object
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
class AttributeAdmin(admin.ModelAdmin):
|
class AttributeAdmin(admin.ModelAdmin):
|
||||||
|
|
@ -12,11 +12,3 @@ class ObjectAdmin(admin.ModelAdmin):
|
||||||
search_fields = ['name']
|
search_fields = ['name']
|
||||||
save_on_top = True
|
save_on_top = True
|
||||||
admin.site.register(Object, ObjectAdmin)
|
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)
|
|
||||||
|
|
@ -970,105 +970,5 @@ class Object(models.Model):
|
||||||
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 CommChannel(models.Model):
|
|
||||||
"""
|
|
||||||
The CommChannel class represents a comsys channel in the vein of MUX/MUSH.
|
|
||||||
"""
|
|
||||||
name = models.CharField(max_length=255)
|
|
||||||
ansi_name = models.CharField(max_length=255)
|
|
||||||
owner = models.ForeignKey(Object, related_name="chan_owner")
|
|
||||||
description = models.CharField(max_length=80, blank=True, null=True)
|
|
||||||
is_joined_by_default = models.BooleanField(default=False)
|
|
||||||
req_grp = models.ManyToManyField(Group, blank=True, null=True)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "%s" % (self.name,)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ['-name']
|
|
||||||
permissions = (
|
|
||||||
('emit_commchannel', 'May @cemit over channels.'),
|
|
||||||
('channel_admin', 'May administer comm channels.')
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
"""
|
|
||||||
Returns a channel's name.
|
|
||||||
"""
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def get_header(self):
|
|
||||||
"""
|
|
||||||
Returns the channel's header text, or what is shown before each channel
|
|
||||||
message.
|
|
||||||
"""
|
|
||||||
return parse_ansi(self.ansi_name)
|
|
||||||
|
|
||||||
def get_owner(self):
|
|
||||||
"""
|
|
||||||
Returns a channels' owner.
|
|
||||||
"""
|
|
||||||
return self.owner
|
|
||||||
|
|
||||||
def set_name(self, new_name):
|
|
||||||
"""
|
|
||||||
Rename a channel
|
|
||||||
"""
|
|
||||||
self.name = parse_ansi(new_name, strip_ansi=True)
|
|
||||||
self.header = "[%s]" % (parse_ansi(new_name),)
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
def set_header(self, new_header):
|
|
||||||
"""
|
|
||||||
Sets a channel's header text.
|
|
||||||
"""
|
|
||||||
self.header = parse_ansi(new_header)
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
def set_owner(self, new_owner):
|
|
||||||
"""
|
|
||||||
Sets a channel's owner.
|
|
||||||
"""
|
|
||||||
self.owner = new_owner
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
def controlled_by(self, pobject):
|
|
||||||
"""
|
|
||||||
Use this to see if another object controls the channel. This is means
|
|
||||||
that the specified object either owns the channel or has special
|
|
||||||
permissions to control it.
|
|
||||||
|
|
||||||
pobject: (Object) Player object to check for control.
|
|
||||||
"""
|
|
||||||
if pobject.is_superuser():
|
|
||||||
return True
|
|
||||||
|
|
||||||
if self.owner and self.owner.id == pobject.id:
|
|
||||||
# If said object owns the target, then give it the green.
|
|
||||||
return True
|
|
||||||
|
|
||||||
# They've failed to meet any of the above conditions.
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_default_chan_alias(self):
|
|
||||||
"""
|
|
||||||
Returns a default channel alias for the channel if none is provided.
|
|
||||||
"""
|
|
||||||
return self.name[:3].lower()
|
|
||||||
|
|
||||||
class CommChannelMessage(models.Model):
|
|
||||||
"""
|
|
||||||
A single logged channel message.
|
|
||||||
"""
|
|
||||||
channel = models.ForeignKey(CommChannel, related_name="msg_channel")
|
|
||||||
message = models.CharField(max_length=255)
|
|
||||||
date_sent = models.DateTimeField(editable=False, auto_now_add=True)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "%s: %s" % (self.sender.name, self.message)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ['-date_sent']
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|
@ -7,7 +7,8 @@ import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from twisted.conch.telnet import StatefulTelnetProtocol
|
from twisted.conch.telnet import StatefulTelnetProtocol
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from src.objects.models import Object, CommChannel
|
from src.objects.models import Object
|
||||||
|
from src.channels.models import CommChannel
|
||||||
from src.config.models import ConnectScreen, ConfigValue
|
from src.config.models import ConnectScreen, ConfigValue
|
||||||
from util import functions_general
|
from util import functions_general
|
||||||
import src.comsys
|
import src.comsys
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue