Skip to content

Commit

Permalink
fix: fix created_by migration field (#1713)
Browse files Browse the repository at this point in the history
* :(

* fix: fix migrations

* fix: if statement

* YES

* this should work
  • Loading branch information
KamilPawel committed Oct 13, 2022
1 parent 8e84d07 commit 3ceedb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 6 additions & 2 deletions aimmo/migrations/0030_update_created_by.py
Expand Up @@ -5,8 +5,12 @@
def populate_created_by(apps, schema_editor):
Game = apps.get_model("aimmo", "Game")
db_alias = schema_editor.connection.alias
games = Game.objects.using(db_alias).filter(created_by=None).exclude(owner=None)
[Game.objects.using(db_alias).filter(id=game.id).update(created_by=game.owner.new_teacher) for game in games]
games = Game.objects.using(db_alias).filter(created_by=None).exclude(owner=None, owner__is_active=False)
[
Game.objects.using(db_alias).filter(id=game.id).update(created_by=game.owner.new_teacher)
for game in games
if hasattr(game.owner, "new_teacher")
]


class Migration(migrations.Migration):
Expand Down
11 changes: 7 additions & 4 deletions aimmo/templatetags/players_utils.py
@@ -1,18 +1,21 @@
from aimmo.models import Game
from django import template

from common.permissions import logged_in_as_student, logged_in_as_teacher
from common.permissions import logged_in_as_teacher

register = template.Library()


def get_user_playable_games(context, base_url):
# Only called by teacher to create games table
user = context.request.user
teacher = user.new_teacher
if logged_in_as_teacher(user):
playable_games = Game.objects.filter(owner=user, is_archived=False).union(
Game.objects.filter(game_class__teacher__school=user.userprofile.teacher.school, is_archived=False),
)
playable_games = list(Game.objects.filter(owner=user, is_archived=False))
if teacher.is_admin:
playable_games += list(
Game.objects.filter(game_class__teacher__school=teacher.school, is_archived=False).exclude(owner=user)
)
else:
playable_games = Game.objects.none()
return {
Expand Down

0 comments on commit 3ceedb0

Please sign in to comment.