Fixes in SubscriptionHandler; return subs ordered by pk.

This commit is contained in:
Griatch 2023-10-01 10:49:42 +02:00 committed by holl0wstar
parent e28f9dd3c4
commit 26a804ca1f
2 changed files with 16 additions and 12 deletions

View file

@ -7,7 +7,6 @@ import re
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.urls import reverse from django.urls import reverse
from django.utils.text import slugify from django.utils.text import slugify
from evennia.comms.managers import ChannelManager from evennia.comms.managers import ChannelManager
from evennia.comms.models import ChannelDB from evennia.comms.models import ChannelDB
from evennia.typeclasses.models import TypeclassBase from evennia.typeclasses.models import TypeclassBase
@ -188,7 +187,7 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase):
# display listening subscribers in bold # display listening subscribers in bold
string = ", ".join( string = ", ".join(
[ [
account.key if account not in listening else "|w%s|n" % account.key account.key if account not in listening else f"|w{account.key}|n"
for account in subs for account in subs
] ]
) )

View file

@ -21,7 +21,6 @@ necessary to easily be able to delete connections on the fly).
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from evennia.comms import managers from evennia.comms import managers
from evennia.locks.lockhandler import LockHandler from evennia.locks.lockhandler import LockHandler
from evennia.typeclasses.models import TypedObject from evennia.typeclasses.models import TypedObject
@ -104,8 +103,10 @@ class Msg(SharedMemoryModel):
null=True, null=True,
blank=True, blank=True,
db_index=True, db_index=True,
help_text="Identifier for single external sender, for use with senders " help_text=(
"not represented by a regular database model.", "Identifier for single external sender, for use with senders "
"not represented by a regular database model."
),
) )
db_receivers_accounts = models.ManyToManyField( db_receivers_accounts = models.ManyToManyField(
@ -137,8 +138,10 @@ class Msg(SharedMemoryModel):
null=True, null=True,
blank=True, blank=True,
db_index=True, db_index=True,
help_text="Identifier for single external receiver, for use with recievers " help_text=(
"not represented by a regular database model.", "Identifier for single external receiver, for use with recievers "
"not represented by a regular database model."
),
) )
# header could be used for meta-info about the message if your system needs # header could be used for meta-info about the message if your system needs
@ -167,8 +170,10 @@ class Msg(SharedMemoryModel):
db_tags = models.ManyToManyField( db_tags = models.ManyToManyField(
Tag, Tag,
blank=True, blank=True,
help_text="tags on this message. Tags are simple string markers to " help_text=(
"identify, group and alias messages.", "tags on this message. Tags are simple string markers to "
"identify, group and alias messages."
),
) )
# Database manager # Database manager
@ -518,7 +523,7 @@ class TempMsg:
# ------------------------------------------------------------ # ------------------------------------------------------------
class SubscriptionHandler(object): class SubscriptionHandler:
""" """
This handler manages subscriptions to the This handler manages subscriptions to the
channel and hides away which type of entity is channel and hides away which type of entity is
@ -540,13 +545,13 @@ class SubscriptionHandler(object):
def _recache(self): def _recache(self):
self._cache = { self._cache = {
account: True account: True
for account in self.obj.db_account_subscriptions.all() for account in self.obj.db_account_subscriptions.all().order_by("pk")
if hasattr(account, "pk") and account.pk if hasattr(account, "pk") and account.pk
} }
self._cache.update( self._cache.update(
{ {
obj: True obj: True
for obj in self.obj.db_object_subscriptions.all() for obj in self.obj.db_object_subscriptions.all().order_by("pk")
if hasattr(obj, "pk") and obj.pk if hasattr(obj, "pk") and obj.pk
} }
) )