From 26a804ca1f1081fdccae50c5f4ebf54dd429e973 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 1 Oct 2023 10:49:42 +0200 Subject: [PATCH] Fixes in SubscriptionHandler; return subs ordered by pk. --- evennia/comms/comms.py | 3 +-- evennia/comms/models.py | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index 9791e5a930..7e370b23f1 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -7,7 +7,6 @@ import re from django.contrib.contenttypes.models import ContentType from django.urls import reverse from django.utils.text import slugify - from evennia.comms.managers import ChannelManager from evennia.comms.models import ChannelDB from evennia.typeclasses.models import TypeclassBase @@ -188,7 +187,7 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase): # display listening subscribers in bold 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 ] ) diff --git a/evennia/comms/models.py b/evennia/comms/models.py index ec6037f23f..80dfa69d79 100644 --- a/evennia/comms/models.py +++ b/evennia/comms/models.py @@ -21,7 +21,6 @@ necessary to easily be able to delete connections on the fly). from django.conf import settings from django.db import models from django.utils import timezone - from evennia.comms import managers from evennia.locks.lockhandler import LockHandler from evennia.typeclasses.models import TypedObject @@ -104,8 +103,10 @@ class Msg(SharedMemoryModel): null=True, blank=True, db_index=True, - help_text="Identifier for single external sender, for use with senders " - "not represented by a regular database model.", + help_text=( + "Identifier for single external sender, for use with senders " + "not represented by a regular database model." + ), ) db_receivers_accounts = models.ManyToManyField( @@ -137,8 +138,10 @@ class Msg(SharedMemoryModel): null=True, blank=True, db_index=True, - help_text="Identifier for single external receiver, for use with recievers " - "not represented by a regular database model.", + help_text=( + "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 @@ -167,8 +170,10 @@ class Msg(SharedMemoryModel): db_tags = models.ManyToManyField( Tag, blank=True, - help_text="tags on this message. Tags are simple string markers to " - "identify, group and alias messages.", + help_text=( + "tags on this message. Tags are simple string markers to " + "identify, group and alias messages." + ), ) # Database manager @@ -518,7 +523,7 @@ class TempMsg: # ------------------------------------------------------------ -class SubscriptionHandler(object): +class SubscriptionHandler: """ This handler manages subscriptions to the channel and hides away which type of entity is @@ -540,13 +545,13 @@ class SubscriptionHandler(object): def _recache(self): self._cache = { 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 } self._cache.update( { 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 } )