# Generated by Django 2.2.12 on 2020-07-06 15:15

from django.db import migrations
from games.models import GAME_STATUS

def grant_historical_exp_rewards(apps, schema_editor):
    # We can't import the models directly as it may be a newer
    # version than this migration expects. We use the historical version.
    Game = apps.get_model('games', 'Game')
    ExperienceReward = apps.get_model('characters', 'ExperienceReward')
    for game in Game.objects.all():
        if game.status == GAME_STATUS[6][0] or game.status == GAME_STATUS[2][0] or game.status == GAME_STATUS[3][0]:
            time = game.end_time
            exp_reward = ExperienceReward(
                created_time= time,
                rewarded_player=game.gm,
            )
            exp_reward.save()
            game.gm_experience_reward = exp_reward
            game.save()
            for game_attendance in game.game_attendance_set.all():
                if game_attendance.attending_character:
                    player = game_attendance.attending_character.player
                else:
                    player = game_attendance.game_invite.invited_player
                exp_reward = ExperienceReward(
                    created_time= time,
                    rewarded_character=game_attendance.attending_character,
                    rewarded_player=player,
                )
                exp_reward.save()
                game_attendance.experience_reward = exp_reward
                game_attendance.save()

class Migration(migrations.Migration):

    dependencies = [
        ('games', '0015_auto_20200711_1900'),
    ]

    operations = [
        migrations.RunPython(grant_historical_exp_rewards),
    ]

# Generated by Django 2.2.12 on 2020-07-06 15:15

from django.db import migrations
from games.models import GAME_STATUS

def grant_historical_exp_rewards(apps, schema_editor):
    # We can't import the models directly as it may be a newer
    # version than this migration expects. We use the historical version.
    Game = apps.get_model('games', 'Game')
    ExperienceReward = apps.get_model('characters', 'ExperienceReward')
    for game in Game.objects.all():
        if game.status == GAME_STATUS[6][0] or game.status == GAME_STATUS[2][0] or game.status == GAME_STATUS[3][0]:
            time = game.end_time
            exp_reward = ExperienceReward(
                created_time= time,
                rewarded_player=game.gm,
            )
            exp_reward.save()
            game.gm_experience_reward = exp_reward
            game.save()
            for game_attendance in game.game_attendance_set.all():
                if game_attendance.attending_character:
                    player = game_attendance.attending_character.player
                else:
                    player = game_attendance.game_invite.invited_player
                exp_reward = ExperienceReward(
                    created_time= time,
                    rewarded_character=game_attendance.attending_character,
                    rewarded_player=player,
                )
                exp_reward.save()
                game_attendance.experience_reward = exp_reward
                game_attendance.save()

class Migration(migrations.Migration):

    dependencies = [
        ('games', '0015_auto_20200711_1900'),
    ]

    operations = [
        migrations.RunPython(grant_historical_exp_rewards),
    ]

# Generated by Django 2.2.12 on 2020-07-06 15:15 # We can't import the models directly as it may be a newer # version than this migration expects. We use the historical version.