-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make dead senators show more info, specifically by making the senator's portrait, list item and details show former faction and titles. After death, senators are now considered to remain "in" the faction that they were in when they died - which is a bit weird but easier than making a new model to represent the former allegiance of dead senators.
- Loading branch information
Showing
17 changed files
with
161 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
backend/rorapp/migrations/0036_add_senator_death_step_remove_senator_alive.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated by Django 4.2.2 on 2023-10-08 13:55 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def convert_alive_to_senator_death(apps, schema_editor): | ||
Senator = apps.get_model('rorapp', 'Senator') | ||
dead_senators = Senator.objects.filter(alive=False) | ||
|
||
ActionLog = apps.get_model('rorapp', 'ActionLog') | ||
death_action_logs = ActionLog.objects.filter(type='face_mortality') | ||
|
||
for dead_action_log in death_action_logs: | ||
if (dead_action_log.data is None): | ||
continue | ||
dead_senator_id = dead_action_log.data.get('senator') | ||
if (dead_senator_id is None): | ||
continue | ||
dead_senator = dead_senators.get(id=dead_senator_id) | ||
dead_senator.death_step = dead_action_log.step | ||
dead_senator.save() | ||
|
||
|
||
def convert_senator_death_to_alive(apps, schema_editor): | ||
Senator = apps.get_model('rorapp', 'Senator') | ||
dead_senators = Senator.objects.filter(death_step__isnull=False) | ||
dead_senators.update(alive=False) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rorapp', '0035_alter_faction_game_alter_player_game_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='senator', | ||
name='death_step', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='rorapp.step'), | ||
), | ||
migrations.RunPython(convert_alive_to_senator_death, convert_senator_death_to_alive), | ||
migrations.RemoveField( | ||
model_name='senator', | ||
name='alive', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 4.2.2 on 2023-10-08 13:55 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def set_dead_senators_faction(apps, schema_editor): | ||
Senator = apps.get_model('rorapp', 'Senator') | ||
dead_senators = Senator.objects.filter(death_step__isnull=False) | ||
|
||
ActionLog = apps.get_model('rorapp', 'ActionLog') | ||
death_action_logs = ActionLog.objects.filter(type='face_mortality') | ||
|
||
for dead_action_log in death_action_logs: | ||
if (dead_action_log.data is None): | ||
continue | ||
dead_senator_id = dead_action_log.data.get('senator') | ||
if (dead_senator_id is None): | ||
continue | ||
dead_senator = dead_senators.get(id=dead_senator_id) | ||
dead_senator.faction = dead_action_log.faction | ||
dead_senator.save() | ||
|
||
|
||
def unset_dead_senators_faction(apps, schema_editor): | ||
Senator = apps.get_model('rorapp', 'Senator') | ||
dead_senators = Senator.objects.filter(death_step__isnull=False) | ||
dead_senators.update(faction=None) | ||
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('rorapp', '0036_add_senator_death_step_remove_senator_alive'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(set_dead_senators_faction, unset_dead_senators_faction), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ class Meta: | |
'name', | ||
'game', | ||
'faction', | ||
'alive', | ||
'death_step', | ||
'code', | ||
'generation', | ||
'rank', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.