Skip to content

Commit

Permalink
fix: added a migration fix (#1387)
Browse files Browse the repository at this point in the history
* fix: added a migration fix

* merge

* please work

* fixing tests by fixing migration

* fixing prev_leve l test failing

* removing print statements

* removed infinite while loop

* removed Q, uncommented rev code and added isnull filter
  • Loading branch information
KamilPawel authored Dec 5, 2022
1 parent 7d9fc81 commit b8aa2a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
26 changes: 15 additions & 11 deletions game/migrations/0077_alter_level_next_level.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Generated by Django 3.2.16 on 2022-12-01 10:49

from django.db import migrations, models
import django.db.models.deletion

Expand All @@ -9,22 +8,27 @@ def add_next_level_to_last_levels(apps, schema_editor):
Level = apps.get_model("game", "Level")
db_alias = schema_editor.connection.alias
Level_Object_Wrapper = Level.objects.using(db_alias)
levels = Level_Object_Wrapper.filter(next_level=None).exclude(name="109")
levels = Level_Object_Wrapper.filter(
episode__isnull=False,
next_level=None,
).exclude(name="109")
for level in levels:
next_level_update = Level_Object_Wrapper.get(
name=(str(int(level.name) + 1))
)
Level_Object_Wrapper.filter(name=level.name).update(
next_level=next_level_update
)
level.next_level = Level_Object_Wrapper.filter(
name=int(level.name) + 1, episode__isnull=False
)[0]
level.save()

def remove_next_level_to_last_levels(apps, schema_editor):
Level = apps.get_model("game", "Level")
db_alias = schema_editor.connection.alias
Level_Object_Wrapper = Level.objects.using(db_alias)
Level_Object_Wrapper.filter(
name__in=["12", "18", "28", "32", "43", "50", "60", "67", "79", "91"]
).update(next_level=None)
levels = Level_Object_Wrapper.filter(
episode__isnull=False,
name__in=["12", "18", "28", "32", "43", "50", "60", "67", "79", "91"],
)
for level in levels:
level.next_level = None
level.save()

dependencies = [
("game", "0076_level_locked_for_class"),
Expand Down
9 changes: 7 additions & 2 deletions game/views/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ def _prev_level_url(level, user, night_mode):
if not user.is_anonymous and hasattr(user.userprofile, "student"):
student = user.userprofile.student
klass = student.class_field
while klass in prev_level.locked_for_class.all() and int(prev_level.name) > 1:
prev_level = prev_level.prev_level.all()[0]

is_prev_level_locked = klass in prev_level.locked_for_class.all()
if is_prev_level_locked:
while is_prev_level_locked and int(prev_level.name) > 1:
prev_level = prev_level.prev_level.all()[0]
is_prev_level_locked = klass in prev_level.locked_for_class.all()

return _level_url(prev_level, night_mode)


Expand Down

0 comments on commit b8aa2a1

Please sign in to comment.