Merge with develop and fix merge conflicts

This commit is contained in:
Griatch 2018-10-01 20:58:16 +02:00
commit 72f4fedcbe
148 changed files with 20005 additions and 2718 deletions

View file

@ -53,12 +53,13 @@ class ChannelAdmin(admin.ModelAdmin):
list_display = ('id', 'db_key', 'db_lock_storage', "subscriptions")
list_display_links = ("id", 'db_key')
ordering = ["db_key"]
search_fields = ['id', 'db_key', 'db_aliases']
search_fields = ['id', 'db_key', 'db_tags__db_key']
save_as = True
save_on_top = True
list_select_related = True
raw_id_fields = ('db_object_subscriptions', 'db_account_subscriptions',)
fieldsets = (
(None, {'fields': (('db_key',), 'db_lock_storage', 'db_subscriptions')}),
(None, {'fields': (('db_key',), 'db_lock_storage', 'db_account_subscriptions', 'db_object_subscriptions')}),
)
def subscriptions(self, obj):
@ -69,7 +70,7 @@ class ChannelAdmin(admin.ModelAdmin):
obj (Channel): The channel to get subs from.
"""
return ", ".join([str(sub) for sub in obj.db_subscriptions.all()])
return ", ".join([str(sub) for sub in obj.subscriptions.all()])
def save_model(self, request, obj, form, change):
"""

View file

@ -159,7 +159,7 @@ class ChannelHandler(object):
"""
The ChannelHandler manages all active in-game channels and
dynamically creates channel commands for users so that they can
just give the channek's key or alias to write to it. Whenever a
just give the channel's key or alias to write to it. Whenever a
new channel is created in the database, the update() method on
this handler must be called to sync it with the database (this is
done automatically if creating the channel with

View file

@ -26,6 +26,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
the hooks called by this method.
"""
self.basetype_setup()
self.at_channel_creation()
self.attributes.add("log_file", "channel_%s.log" % self.key)
if hasattr(self, "_createdict"):
@ -46,11 +47,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
if cdict.get("desc"):
self.attributes.add("desc", cdict["desc"])
def at_channel_creation(self):
"""
Called once, when the channel is first created.
"""
def basetype_setup(self):
# delayed import of the channelhandler
global _CHANNEL_HANDLER
if not _CHANNEL_HANDLER:
@ -58,6 +55,15 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
# register ourselves with the channelhandler.
_CHANNEL_HANDLER.add(self)
self.locks.add("send:all();listen:all();control:perm(Admin)")
def at_channel_creation(self):
"""
Called once, when the channel is first created.
"""
pass
# helper methods, for easy overloading
def has_connection(self, subscriber):
@ -91,7 +97,8 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
@property
def wholist(self):
subs = self.subscriptions.all()
listening = [ob for ob in subs if ob.is_connected and ob not in self.mutelist]
muted = list(self.mutelist)
listening = [ob for ob in subs if ob.is_connected and ob not in muted]
if subs:
# display listening subscribers in bold
string = ", ".join([account.key if account not in listening else "|w%s|n" % account.key for account in subs])

View file

@ -355,15 +355,16 @@ class ChannelDBManager(TypedObjectManager):
channel (Channel or None): A channel match.
"""
# first check the channel key
channels = self.filter(db_key__iexact=channelkey)
if not channels:
# also check aliases
channels = [channel for channel in self.all()
if channelkey in channel.aliases.all()]
if channels:
return channels[0]
return None
dbref = self.dbref(channelkey)
if dbref:
try:
return self.get(id=dbref)
except self.model.DoesNotExist:
pass
results = self.filter(Q(db_key__iexact=channelkey) |
Q(db_tags__db_tagtype__iexact="alias",
db_tags__db_key__iexact=channelkey)).distinct()
return results[0] if results else None
def get_subscriptions(self, subscriber):
"""
@ -393,26 +394,20 @@ class ChannelDBManager(TypedObjectManager):
case sensitive) match.
"""
channels = []
if not ostring:
return channels
try:
# try an id match first
dbref = int(ostring.strip('#'))
channels = self.filter(id=dbref)
except Exception:
# Usually because we couldn't convert to int - not a dbref
pass
if not channels:
# no id match. Search on the key.
if exact:
channels = self.filter(db_key__iexact=ostring)
else:
channels = self.filter(db_key__icontains=ostring)
if not channels:
# still no match. Search by alias.
channels = [channel for channel in self.all()
if ostring.lower() in [a.lower for a in channel.aliases.all()]]
dbref = self.dbref(ostring)
if dbref:
try:
return self.get(id=dbref)
except self.model.DoesNotExist:
pass
if exact:
channels = self.filter(Q(db_key__iexact=ostring) |
Q(db_tags__db_tagtype__iexact="alias",
db_tags__db_key__iexact=ostring)).distinct()
else:
channels = self.filter(Q(db_key__icontains=ostring) |
Q(db_tags__db_tagtype__iexact="alias",
db_tags__db_key__icontains=ostring)).distinct()
return channels
# back-compatibility alias
channel_search = search_channel

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-25 17:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('comms', '0015_auto_20170706_2041'),
]
operations = [
migrations.RemoveField(
model_name='channeldb',
name='db_subscriptions',
),
migrations.AlterField(
model_name='msg',
name='db_message',
field=models.TextField(verbose_name=b'message'),
),
]

View file

@ -107,7 +107,7 @@ class Msg(SharedMemoryModel):
# it, or as a separate store for the mail subject line maybe.
db_header = models.TextField('header', null=True, blank=True)
# the message body itself
db_message = models.TextField('messsage')
db_message = models.TextField('message')
# send date
db_date_created = models.DateTimeField('date sent', editable=False, auto_now_add=True, db_index=True)
# lock storage
@ -584,9 +584,7 @@ class SubscriptionHandler(object):
for obj in self.all():
from django.core.exceptions import ObjectDoesNotExist
try:
if hasattr(obj, 'account'):
if not obj.account:
continue
if hasattr(obj, 'account') and obj.account:
obj = obj.account
if not obj.is_connected:
continue