-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
games button removed; game signals disabled (#555)
* games button removed; game signals disabled * games signals and button deleted * returned the signals file so that there would be no conflict during the merge * fix ruff --------- Co-authored-by: Konstantin Raikhert <raikhert13@gmail.com>
- Loading branch information
1 parent
6a2cf0b
commit a26618b
Showing
3 changed files
with
124 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class GamesConfig(AppConfig): | ||
"""Класс-конфигуратор для приложения games.""" | ||
|
||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "games" | ||
verbose_name = "Игры" | ||
|
||
def ready(self) -> None: | ||
"""Импортирование сигналов для приложения.""" | ||
import games.signals # noqa | ||
|
||
return super().ready() | ||
from django.apps import AppConfig | ||
|
||
|
||
class GamesConfig(AppConfig): | ||
"""Класс-конфигуратор для приложения games.""" | ||
|
||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "games" | ||
verbose_name = "Игры" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,59 @@ | ||
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 необходимо пересмотреть логику создания объекта игры, | ||
# конкретно изменение | ||
# номеров игроков. Оно должно происходить до того | ||
# как объект игры попадёт в бд. | ||
|
||
|
||
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,56 @@ | ||
{% 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 %} | ||
</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 %} |