Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

games button removed; game signals disabled #555

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 60 additions & 59 deletions adaptive_hockey_federation/games/signals.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
from django.db.models.signals import post_save
from django.dispatch import receiver

from games.models import Game, GamePlayer, GameTeam

from main.models import Player, Team


@receiver(post_save, sender=Game, dispatch_uid="unique_signal")
def create_game_teams(sender, instance, created, **kwargs):
"""
Сигнал для автоматического создания GameTeam при создании Game.

Для последующего использования сигнала при обновлении объекта Game
реализовано удаление старых GameTeam, которые ссылались на этот Game.
"""
queryset_teams = list(
map(lambda x: Team.objects.get(id=x), instance.teams),
)
GameTeam.objects.filter(game=instance).delete()
for team in queryset_teams:
game_team = GameTeam(
id=team.id,
name=team.name,
discipline_name=team.discipline_name.name,
game=instance,
)
game_team.players = Player.objects.filter(
team=team,
)
game_team.save()

# TODO необходимо пересмотреть логику создания объекта игры,
# конкретно изменение
# номеров игроков. Оно должно происходить до того
# как объект игры попадёт в бд.
# TODO отправлять видео на распознавание до изменения номеров игроков
# нелогично.
# if created and instance.video_link:
# send_game_video_to_process(instance.id)


@receiver(post_save, sender=GameTeam, dispatch_uid="unique_signal")
def create_game_players(sender, instance, created, **kwargs):
"""Сигнал для автоматического создания GamePlayer при создании GameTeam."""
if created:
queryset_players = instance.players
all_players = []
for player in queryset_players:
game_player = GamePlayer(
id=player.id,
name=player.name,
last_name=player.surname,
patronymic=player.patronymic,
number=player.number,
game_team=instance,
)
all_players.append(game_player)
GamePlayer.objects.bulk_create(all_players)
# from django.db.models.signals import post_save
# from django.dispatch import receiver

# from games.models import Game, GamePlayer, GameTeam

# from main.models import Player, Team


# @receiver(post_save, sender=Game, dispatch_uid="unique_signal")
# def create_game_teams(sender, instance, created, **kwargs):
# """
# Сигнал для автоматического создания GameTeam при создании Game.

# Для последующего использования сигнала при обновлении объекта Game
# реализовано удаление старых GameTeam, которые ссылались на этот Game.
# """
# queryset_teams = list(
# map(lambda x: Team.objects.get(id=x), instance.teams),
# )
# GameTeam.objects.filter(game=instance).delete()
# for team in queryset_teams:
# game_team = GameTeam(
# id=team.id,
# name=team.name,
# discipline_name=team.discipline_name.name,
# game=instance,
# )
# game_team.players = Player.objects.filter(
# team=team,
# )
# game_team.save()

# # TODO необходимо пересмотреть логику создания объекта игры,
# # конкретно изменение
# # номеров игроков. Оно должно происходить до того
# # как объект игры попадёт в бд.
# # TODO отправлять видео на распознавание до изменения номеров игроков
# # нелогично.
# # if created and instance.video_link:
# # send_game_video_to_process(instance.id)


# @receiver(post_save, sender=GameTeam, dispatch_uid="unique_signal")
# def create_game_players(sender, instance, created, **kwargs):
# """Сигнал для автоматического создания
# GamePlayer при создании GameTeam."""
# if created:
# queryset_players = instance.players
# all_players = []
# for player in queryset_players:
# game_player = GamePlayer(
# id=player.id,
# name=player.name,
# last_name=player.surname,
# patronymic=player.patronymic,
# number=player.number,
# game_team=instance,
# )
# all_players.append(game_player)
# GamePlayer.objects.bulk_create(all_players)
122 changes: 61 additions & 61 deletions adaptive_hockey_federation/templates/base/drawer.html
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
{% if not request.user.is_moderator %}
<aside id="container__fluid" class="aside-navbar">
<div class="navbar-container">
<ul class="navigate">
<div class="py-5 logo-zone">
<div class="col-auto flex justify-end">
<span class="logo-img">
<img src="https://paraicehockey.ru/wp-content/uploads/2022/02/FAH_q.png" width="100" height="100">
</span>
</div>
<div class="col text-white flex justify-start">
Мир хоккея<br>для особенных<br>детей
</div>
</div>
{% if not request.user.is_agent %}
<li class="nav-item py-2 list-group">
{% url 'main:players' as url_name %}{% include "base/button.html" with name="Игроки" %}
</li>
<li class="nav-item py-2">
{% url 'users:users' as url_name %}{% include "base/button.html" with name="Пользователи" %}
</li>
{% endif %}
<li class="nav-item py-2">
{% url 'main:teams' as url_name %}{% include "base/button.html" with name="Команды" %}
</li>
{% if not request.user.is_agent %}
<li class="nav-item py-2">
{% url 'main:staffs' as url_name %}{% include "base/button.html" with name="Персонал команд" %}
</li>
{% endif %}
<li class="nav-item py-2">
{% url 'competitions:competitions' as url_name %}{% include "base/button.html" with name="Соревнования" %}
</li>
{% if not request.user.is_agent %}
<li class="nav-item py-2">
{% url 'analytics:analytics' as url_name %}{% include "base/button.html" with name="Аналитика" %}
</li>
{% endif %}
{% if request.user.is_admin %}
<li class="nav-item py-2">
{% url 'unloads:unloads' as url_name %}{% include "base/button.html" with name="Выгрузки" %}
</li>
{% endif %}
{% if not request.user.is_agent %}
<li class="nav-item py-2">
{% url 'games:games' as url_name %}{% include "base/button.html" with name="Игры" %}
</li>
{% endif %}
</ul>
<button
onclick="toggle_visibility(false);"
class="nav-button"
type="button"
aria-controls="staticBackdrop"
aria-expanded="true"
>
{% include "base/triangle.html" %}
</button>
</div>
</aside>
{% endif %}
{% if not request.user.is_moderator %}
<aside id="container__fluid" class="aside-navbar">
<div class="navbar-container">
<ul class="navigate">
<div class="py-5 logo-zone">
<div class="col-auto flex justify-end">
<span class="logo-img">
<img src="https://paraicehockey.ru/wp-content/uploads/2022/02/FAH_q.png" width="100" height="100">
</span>
</div>
<div class="col text-white flex justify-start">
Мир хоккея<br>для особенных<br>детей
</div>
</div>
{% if not request.user.is_agent %}
<li class="nav-item py-2 list-group">
{% url 'main:players' as url_name %}{% include "base/button.html" with name="Игроки" %}
</li>
<li class="nav-item py-2">
{% url 'users:users' as url_name %}{% include "base/button.html" with name="Пользователи" %}
</li>
{% endif %}
<li class="nav-item py-2">
{% url 'main:teams' as url_name %}{% include "base/button.html" with name="Команды" %}
</li>
{% if not request.user.is_agent %}
<li class="nav-item py-2">
{% url 'main:staffs' as url_name %}{% include "base/button.html" with name="Персонал команд" %}
</li>
{% endif %}
<li class="nav-item py-2">
{% url 'competitions:competitions' as url_name %}{% include "base/button.html" with name="Соревнования" %}
</li>
{% if not request.user.is_agent %}
<li class="nav-item py-2">
{% url 'analytics:analytics' as url_name %}{% include "base/button.html" with name="Аналитика" %}
</li>
{% endif %}
{% if request.user.is_admin %}
<li class="nav-item py-2">
{% url 'unloads:unloads' as url_name %}{% include "base/button.html" with name="Выгрузки" %}
</li>
{% endif %}
{% comment %} {% if not request.user.is_agent %}
<li class="nav-item py-2">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверно можно сейчас и удалить все что касается игр. а в остальном мержим

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все сделал, давайте мерджить

{% url 'games:games' as url_name %}{% include "base/button.html" with name="Игры" %}
</li>
{% endif %} {% endcomment %}
</ul>
<button
onclick="toggle_visibility(false);"
class="nav-button"
type="button"
aria-controls="staticBackdrop"
aria-expanded="true"
>
{% include "base/triangle.html" %}
</button>
</div>
</aside>
{% endif %}
Loading