Create parallel Player/Account fields and copy all
This commit is contained in:
parent
ee0e9cc053
commit
63c96de443
10 changed files with 226 additions and 2 deletions
51
evennia/comms/migrations/0013_auto_20170705_1726.py
Normal file
51
evennia/comms/migrations/0013_auto_20170705_1726.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-07-05 17:26
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounts', '0002_copy_player_to_account'),
|
||||||
|
('comms', '0012_merge_20170617_2017'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='channeldb',
|
||||||
|
name='db_account_subscriptions',
|
||||||
|
field=models.ManyToManyField(blank=True, db_index=True, related_name='account_subscription_set', to='accounts.AccountDB', verbose_name=b'account subscriptions'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='msg',
|
||||||
|
name='db_hide_from_accounts',
|
||||||
|
field=models.ManyToManyField(blank=True, related_name='hide_from_accounts_set', to='accounts.AccountDB'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='msg',
|
||||||
|
name='db_receivers_accounts',
|
||||||
|
field=models.ManyToManyField(blank=True, help_text=b'account receivers', related_name='receiver_account_set', to='accounts.AccountDB'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='msg',
|
||||||
|
name='db_sender_accounts',
|
||||||
|
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_account_set', to='accounts.AccountDB', verbose_name=b'sender(account)'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='channeldb',
|
||||||
|
name='db_object_subscriptions',
|
||||||
|
field=models.ManyToManyField(blank=True, db_index=True, related_name='object_subscription_set', to='objects.ObjectDB', verbose_name=b'object subscriptions'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='msg',
|
||||||
|
name='db_receivers_scripts',
|
||||||
|
field=models.ManyToManyField(blank=True, help_text=b'script_receivers', related_name='receiver_script_set', to='scripts.ScriptDB'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='msg',
|
||||||
|
name='db_sender_scripts',
|
||||||
|
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_script_set', to='scripts.ScriptDB', verbose_name=b'sender(script)'),
|
||||||
|
),
|
||||||
|
]
|
||||||
43
evennia/comms/migrations/0014_auto_20170705_1736.py
Normal file
43
evennia/comms/migrations/0014_auto_20170705_1736.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-07-05 17:36
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def forwards(apps, schema_editor):
|
||||||
|
|
||||||
|
try:
|
||||||
|
apps.get_model('players', 'PlayerDB')
|
||||||
|
except LookupError:
|
||||||
|
return
|
||||||
|
AccountDB = apps.get_model('accounts', 'AccountDB')
|
||||||
|
|
||||||
|
Msg = apps.get_model('comms', 'Msg')
|
||||||
|
for msg in Msg.objects.all():
|
||||||
|
for player in msg.db_sender_players.all():
|
||||||
|
account = AccountDB.objects.get(id=player.id)
|
||||||
|
msg.db_sender_accounts.add(account)
|
||||||
|
for player in msg.db_receivers_players.all():
|
||||||
|
account = AccountDB.objects.get(id=player.id)
|
||||||
|
msg.db_receivers_accounts.add(account)
|
||||||
|
for player in msg.db_hide_from_players.all():
|
||||||
|
account = AccountDB.objects.get(id=player.id)
|
||||||
|
msg.db_hide_from_accounts.add(account)
|
||||||
|
|
||||||
|
ChannelDB = apps.get_model('comms', 'ChannelDB')
|
||||||
|
for channel in ChannelDB.objects.all():
|
||||||
|
for player in channel.db_subscriptions.all():
|
||||||
|
account = AccountDB.objects.get(id=player.id)
|
||||||
|
channel.db_account_subscriptions.add(account)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('comms', '0013_auto_20170705_1726'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(forwards)
|
||||||
|
]
|
||||||
|
|
@ -80,8 +80,12 @@ class Msg(SharedMemoryModel):
|
||||||
# Sender is either a player, an object or an external sender, like
|
# Sender is either a player, an object or an external sender, like
|
||||||
# an IRC channel; normally there is only one, but if co-modification of
|
# an IRC channel; normally there is only one, but if co-modification of
|
||||||
# a message is allowed, there may be more than one "author"
|
# a message is allowed, there may be more than one "author"
|
||||||
|
# TODO Player-Account
|
||||||
db_sender_players = models.ManyToManyField("players.PlayerDB", related_name='sender_player_set',
|
db_sender_players = models.ManyToManyField("players.PlayerDB", related_name='sender_player_set',
|
||||||
blank=True, verbose_name='sender(player)', db_index=True)
|
blank=True, verbose_name='sender(player)', db_index=True)
|
||||||
|
db_sender_accounts = models.ManyToManyField("accounts.AccountDB", related_name='sender_account_set',
|
||||||
|
blank=True, verbose_name='sender(account)', db_index=True)
|
||||||
|
|
||||||
db_sender_objects = models.ManyToManyField("objects.ObjectDB", related_name='sender_object_set',
|
db_sender_objects = models.ManyToManyField("objects.ObjectDB", related_name='sender_object_set',
|
||||||
blank=True, verbose_name='sender(object)', db_index=True)
|
blank=True, verbose_name='sender(object)', db_index=True)
|
||||||
db_sender_scripts = models.ManyToManyField("scripts.ScriptDB", related_name='sender_script_set',
|
db_sender_scripts = models.ManyToManyField("scripts.ScriptDB", related_name='sender_script_set',
|
||||||
|
|
@ -92,8 +96,12 @@ class Msg(SharedMemoryModel):
|
||||||
# The destination objects of this message. Stored as a
|
# The destination objects of this message. Stored as a
|
||||||
# comma-separated string of object dbrefs. Can be defined along
|
# comma-separated string of object dbrefs. Can be defined along
|
||||||
# with channels below.
|
# with channels below.
|
||||||
|
# TODO Player-Account
|
||||||
db_receivers_players = models.ManyToManyField('players.PlayerDB', related_name='receiver_player_set',
|
db_receivers_players = models.ManyToManyField('players.PlayerDB', related_name='receiver_player_set',
|
||||||
blank=True, help_text="player receivers")
|
blank=True, help_text="player receivers")
|
||||||
|
db_receivers_accounts = models.ManyToManyField('accounts.AccountDB', related_name='receiver_account_set',
|
||||||
|
blank=True, help_text="account receivers")
|
||||||
|
|
||||||
db_receivers_objects = models.ManyToManyField('objects.ObjectDB', related_name='receiver_object_set',
|
db_receivers_objects = models.ManyToManyField('objects.ObjectDB', related_name='receiver_object_set',
|
||||||
blank=True, help_text="object receivers")
|
blank=True, help_text="object receivers")
|
||||||
db_receivers_scripts = models.ManyToManyField('scripts.ScriptDB', related_name='receiver_script_set',
|
db_receivers_scripts = models.ManyToManyField('scripts.ScriptDB', related_name='receiver_script_set',
|
||||||
|
|
@ -114,6 +122,8 @@ class Msg(SharedMemoryModel):
|
||||||
|
|
||||||
# these can be used to filter/hide a given message from supplied objects/players/channels
|
# these can be used to filter/hide a given message from supplied objects/players/channels
|
||||||
db_hide_from_players = models.ManyToManyField("players.PlayerDB", related_name='hide_from_players_set', blank=True)
|
db_hide_from_players = models.ManyToManyField("players.PlayerDB", related_name='hide_from_players_set', blank=True)
|
||||||
|
db_hide_from_accounts = models.ManyToManyField("accounts.AccountDB", related_name='hide_from_accounts_set', blank=True)
|
||||||
|
|
||||||
db_hide_from_objects = models.ManyToManyField("objects.ObjectDB", related_name='hide_from_objects_set', blank=True)
|
db_hide_from_objects = models.ManyToManyField("objects.ObjectDB", related_name='hide_from_objects_set', blank=True)
|
||||||
db_hide_from_channels = models.ManyToManyField("ChannelDB", related_name='hide_from_channels_set', blank=True)
|
db_hide_from_channels = models.ManyToManyField("ChannelDB", related_name='hide_from_channels_set', blank=True)
|
||||||
|
|
||||||
|
|
@ -605,11 +615,14 @@ class ChannelDB(TypedObject):
|
||||||
- db_object_subscriptions: The Object subscriptions.
|
- db_object_subscriptions: The Object subscriptions.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# TODO Player-Account
|
||||||
db_subscriptions = models.ManyToManyField("players.PlayerDB",
|
db_subscriptions = models.ManyToManyField("players.PlayerDB",
|
||||||
related_name="subscription_set", blank=True, verbose_name='subscriptions', db_index=True)
|
related_name="subscription_set", blank=True, verbose_name='subscriptions', db_index=True)
|
||||||
|
db_account_subscriptions = models.ManyToManyField("accounts.AccountDB",
|
||||||
|
related_name="account_subscription_set", blank=True, verbose_name='account subscriptions', db_index=True)
|
||||||
|
|
||||||
db_object_subscriptions = models.ManyToManyField("objects.ObjectDB",
|
db_object_subscriptions = models.ManyToManyField("objects.ObjectDB",
|
||||||
related_name="object_subscription_set", blank=True, verbose_name='subscriptions', db_index=True)
|
related_name="object_subscription_set", blank=True, verbose_name='object subscriptions', db_index=True)
|
||||||
|
|
||||||
# Database manager
|
# Database manager
|
||||||
objects = managers.ChannelDBManager()
|
objects = managers.ChannelDBManager()
|
||||||
|
|
|
||||||
22
evennia/objects/migrations/0007_objectdb_db_account.py
Normal file
22
evennia/objects/migrations/0007_objectdb_db_account.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-07-05 17:27
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounts', '0002_copy_player_to_account'),
|
||||||
|
('objects', '0006_auto_20170606_1731'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='objectdb',
|
||||||
|
name='db_account',
|
||||||
|
field=models.ForeignKey(help_text=b'an Account connected to this object, if any.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.AccountDB', verbose_name=b'account'),
|
||||||
|
),
|
||||||
|
]
|
||||||
32
evennia/objects/migrations/0008_auto_20170705_1736.py
Normal file
32
evennia/objects/migrations/0008_auto_20170705_1736.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-07-05 17:36
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def forwards(apps, schema_editor):
|
||||||
|
|
||||||
|
try:
|
||||||
|
apps.get_model('players', 'PlayerDB')
|
||||||
|
except LookupError:
|
||||||
|
return
|
||||||
|
AccountDB = apps.get_model('accounts', 'AccountDB')
|
||||||
|
ObjectDB = apps.get_model('objects', 'ObjectDB')
|
||||||
|
|
||||||
|
for object in ObjectDB.objects.all():
|
||||||
|
player = object.db_player
|
||||||
|
if player:
|
||||||
|
account = AccountDB.objects.get(id=player.id)
|
||||||
|
object.db_account = account
|
||||||
|
object.save(update_fields=['db_account'])
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('objects', '0007_objectdb_db_account'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(forwards)
|
||||||
|
]
|
||||||
|
|
@ -170,8 +170,12 @@ class ObjectDB(TypedObject):
|
||||||
# will automatically save and cache the data more efficiently.
|
# will automatically save and cache the data more efficiently.
|
||||||
|
|
||||||
# If this is a character object, the player is connected here.
|
# If this is a character object, the player is connected here.
|
||||||
|
# TODO Player-Account
|
||||||
db_player = models.ForeignKey("players.PlayerDB", null=True, verbose_name='player', on_delete=models.SET_NULL,
|
db_player = models.ForeignKey("players.PlayerDB", null=True, verbose_name='player', on_delete=models.SET_NULL,
|
||||||
help_text='a Player connected to this object, if any.')
|
help_text='a Player connected to this object, if any.')
|
||||||
|
db_account = models.ForeignKey("accounts.AccountDB", null=True, verbose_name='account', on_delete=models.SET_NULL,
|
||||||
|
help_text='an Account connected to this object, if any.')
|
||||||
|
|
||||||
# the session id associated with this player, if any
|
# the session id associated with this player, if any
|
||||||
db_sessid = models.CharField(null=True, max_length=32, validators=[validate_comma_separated_integer_list],
|
db_sessid = models.CharField(null=True, max_length=32, validators=[validate_comma_separated_integer_list],
|
||||||
verbose_name="session id",
|
verbose_name="session id",
|
||||||
|
|
|
||||||
22
evennia/scripts/migrations/0009_scriptdb_db_account.py
Normal file
22
evennia/scripts/migrations/0009_scriptdb_db_account.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-07-05 17:27
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('accounts', '0002_copy_player_to_account'),
|
||||||
|
('scripts', '0008_auto_20170606_1731'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='scriptdb',
|
||||||
|
name='db_account',
|
||||||
|
field=models.ForeignKey(blank=True, help_text=b'the account to store this script on (should not be set if db_obj is set)', null=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.AccountDB', verbose_name=b'scripted account'),
|
||||||
|
),
|
||||||
|
]
|
||||||
33
evennia/scripts/migrations/0010_auto_20170705_1736.py
Normal file
33
evennia/scripts/migrations/0010_auto_20170705_1736.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-07-05 17:36
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def forwards(apps, schema_editor):
|
||||||
|
|
||||||
|
try:
|
||||||
|
apps.get_model('players', 'PlayerDB')
|
||||||
|
except LookupError:
|
||||||
|
return
|
||||||
|
AccountDB = apps.get_model('accounts', 'AccountDB')
|
||||||
|
ScriptDB = apps.get_model('scripts', 'ScriptDB')
|
||||||
|
|
||||||
|
for script in ScriptDB.objects.all():
|
||||||
|
player = script.db_player
|
||||||
|
if player:
|
||||||
|
account = AccountDB.objects.get(id=player.id)
|
||||||
|
script.db_account = account
|
||||||
|
script.save(update_fields=['db_account'])
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('scripts', '0009_scriptdb_db_account'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(forwards)
|
||||||
|
]
|
||||||
|
|
@ -86,8 +86,12 @@ class ScriptDB(TypedObject):
|
||||||
# A reference to the database object affected by this Script, if any.
|
# A reference to the database object affected by this Script, if any.
|
||||||
db_obj = models.ForeignKey("objects.ObjectDB", null=True, blank=True, verbose_name='scripted object',
|
db_obj = models.ForeignKey("objects.ObjectDB", null=True, blank=True, verbose_name='scripted object',
|
||||||
help_text='the object to store this script on, if not a global script.')
|
help_text='the object to store this script on, if not a global script.')
|
||||||
|
# TODO Player-Account
|
||||||
db_player = models.ForeignKey("players.PlayerDB", null=True, blank=True, verbose_name="scripted player",
|
db_player = models.ForeignKey("players.PlayerDB", null=True, blank=True, verbose_name="scripted player",
|
||||||
help_text='the player to store this script on (should not be set if obj is set)')
|
help_text='the player to store this script on (should not be set if obj is set)')
|
||||||
|
db_account = models.ForeignKey("accounts.AccountDB", null=True, blank=True, verbose_name="scripted account",
|
||||||
|
help_text='the account to store this script on (should not be set if db_obj is set)')
|
||||||
|
|
||||||
# how often to run Script (secs). -1 means there is no timer
|
# how often to run Script (secs). -1 means there is no timer
|
||||||
db_interval = models.IntegerField('interval', default=-1, help_text='how often to repeat script, in seconds. -1 means off.')
|
db_interval = models.IntegerField('interval', default=-1, help_text='how often to repeat script, in seconds. -1 means off.')
|
||||||
# start script right away or wait interval seconds first
|
# start script right away or wait interval seconds first
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ class SharedMemoryManager(Manager):
|
||||||
if key.endswith('__exact'):
|
if key.endswith('__exact'):
|
||||||
key = key[:-len('__exact')]
|
key = key[:-len('__exact')]
|
||||||
if key in ('pk', self.model._meta.pk.attname):
|
if key in ('pk', self.model._meta.pk.attname):
|
||||||
inst = self.model.get_cached_instance(kwargs[items[0]])
|
|
||||||
try:
|
try:
|
||||||
|
inst = self.model.get_cached_instance(kwargs[items[0]])
|
||||||
# we got the item from cache, but if this is a fk, check it's ours
|
# we got the item from cache, but if this is a fk, check it's ours
|
||||||
if getattr(inst, str(self.field).split(".")[-1]) != self.instance:
|
if getattr(inst, str(self.field).split(".")[-1]) != self.instance:
|
||||||
inst = None
|
inst = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue