Skip to content

Commit

Permalink
fix: Scoreboard issue with new levels (#1584)
Browse files Browse the repository at this point in the history
* fix: Scoreboard issue with new levels

* Improve test

* Merge branch 'master' into fix_scoreboard_new_eps

* Merge master

* Merge branch 'master' into fix_scoreboard_new_eps

* Merge branch 'master' into fix_scoreboard_new_eps
  • Loading branch information
faucomte97 authored Feb 15, 2024
1 parent 0a47277 commit 8839c85
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 82 deletions.
5 changes: 4 additions & 1 deletion game/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def __init__(self, *args, **kwargs):
# Each tuple in choices has two elements, id and name of each level
# First element is the actual value set on the model
# Second element is the string displayed on the dropdown menu
episodes_choices = ((episode.id, episode.name) for episode in Episode.objects.all())
episodes_choices = (
(episode.id, episode.name)
for episode in Episode.objects.filter(in_development=False)
)
self.fields["episodes"] = forms.MultipleChoiceField(
choices=itertools.chain(episodes_choices),
widget=forms.CheckboxSelectMultiple(),
Expand Down
30 changes: 30 additions & 0 deletions game/migrations/0089_episodes_in_development.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.apps.registry import Apps
from django.db import migrations


def mark_episodes_in_development(apps: Apps, *args):
Episode = apps.get_model("game", "Episode")

for i in range(13, 16):
episode = Episode.objects.get(pk=i)
episode.in_development = True
episode.save()


def unmark_episodes_in_development(apps: Apps, *args):
Episode = apps.get_model("game", "Episode")

for i in range(13, 16):
episode = Episode.objects.get(pk=i)
episode.in_development = False
episode.save()


class Migration(migrations.Migration):
dependencies = [("game", "0088_rename_episodes")]
operations = [
migrations.RunPython(
mark_episodes_in_development,
reverse_code=unmark_episodes_in_development,
)
]
Loading

0 comments on commit 8839c85

Please sign in to comment.