parent
19a55869a9
commit
0fe9272002
@ -1,5 +1,23 @@ |
|||||||
import re |
import re |
||||||
|
import importlib |
||||||
|
|
||||||
def is_valid_email(email): |
def is_valid_email(email): |
||||||
email_regex = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$' |
email_regex = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$' |
||||||
return re.match(email_regex, email) is not None |
return re.match(email_regex, email) is not None |
||||||
|
|
||||||
|
def build_serializer_class(source): |
||||||
|
|
||||||
|
# Remove the 's' character at the end if present |
||||||
|
if source.endswith('s'): |
||||||
|
source = source[:-1] |
||||||
|
|
||||||
|
# Capitalize words separated by a dash |
||||||
|
words = source.split('-') |
||||||
|
capitalized_words = [word[0].upper() + word[1:] for word in words] |
||||||
|
transformed_string = ''.join(capitalized_words) |
||||||
|
|
||||||
|
# Add 'Serializer' at the end |
||||||
|
transformed_string += 'Serializer' |
||||||
|
|
||||||
|
module = importlib.import_module('api.serializers') |
||||||
|
return getattr(module, transformed_string) |
||||||
|
|||||||
@ -0,0 +1 @@ |
|||||||
|
|
||||||
@ -1,9 +1,10 @@ |
|||||||
Django==4.2.11 |
Django==5.1 |
||||||
djangorestframework==3.14.0 |
djangorestframework==3.14.0 |
||||||
psycopg2-binary==2.9.9 |
psycopg2-binary==2.9.9 |
||||||
dj-rest-auth==5.1.0 |
dj-rest-auth==6.0.0 |
||||||
django-qr-code==4.0.1 |
django-qr-code==4.0.1 |
||||||
pycryptodome==3.20.0 |
pycryptodome==3.20.0 |
||||||
requests==2.31.0 |
requests==2.31.0 |
||||||
PyJWT==2.8.0 |
PyJWT==2.8.0 |
||||||
httpx[http2]==0.27.0 |
httpx[http2]==0.27.0 |
||||||
|
channels[daphne]==4.1.0 |
||||||
|
|||||||
@ -0,0 +1,41 @@ |
|||||||
|
import json |
||||||
|
|
||||||
|
from asgiref.sync import async_to_sync |
||||||
|
from channels.generic.websocket import WebsocketConsumer |
||||||
|
|
||||||
|
class ChatConsumer(WebsocketConsumer): |
||||||
|
def connect(self): |
||||||
|
self.room_name = 'main' |
||||||
|
self.room_group_name = f"chat_{self.room_name}" |
||||||
|
|
||||||
|
# Join room group |
||||||
|
async_to_sync(self.channel_layer.group_add)( |
||||||
|
self.room_group_name, self.channel_name |
||||||
|
) |
||||||
|
|
||||||
|
self.accept() |
||||||
|
|
||||||
|
def disconnect(self, close_code): |
||||||
|
# Leave room group |
||||||
|
async_to_sync(self.channel_layer.group_discard)( |
||||||
|
self.room_group_name, self.channel_name |
||||||
|
) |
||||||
|
|
||||||
|
# Receive message from WebSocket |
||||||
|
def receive(self, text_data): |
||||||
|
# text_data_json = json.loads(text_data) |
||||||
|
# message = text_data_json["message"] |
||||||
|
print(f'received {text_data}') |
||||||
|
|
||||||
|
# Send message to room group |
||||||
|
# chat.message calls the chat_message method |
||||||
|
async_to_sync(self.channel_layer.group_send)( |
||||||
|
self.room_group_name, {"type": "chat.message", "message": text_data} |
||||||
|
) |
||||||
|
|
||||||
|
# Receive message from room group |
||||||
|
def chat_message(self, event): |
||||||
|
message = event["message"] |
||||||
|
|
||||||
|
# Send message to WebSocket |
||||||
|
self.send(text_data=message) |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-09-12 13:49 |
||||||
|
|
||||||
|
import uuid |
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0079_alter_event_creator'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.CreateModel( |
||||||
|
name='ModelLog', |
||||||
|
fields=[ |
||||||
|
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)), |
||||||
|
('model_id', models.UUIDField()), |
||||||
|
('operation', models.IntegerField(choices=[(0, 'POST'), (1, 'PUT'), (2, 'DELETE')])), |
||||||
|
('date', models.DateTimeField()), |
||||||
|
('model_name', models.CharField(max_length=50)), |
||||||
|
], |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-09-12 15:21 |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0080_modellog'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AlterField( |
||||||
|
model_name='modellog', |
||||||
|
name='operation', |
||||||
|
field=models.IntegerField(choices=[('POST', 'POST'), ('PUT', 'PUT'), ('DELETE', 'DELETE')]), |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-09-12 15:30 |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0081_alter_modellog_operation'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AlterField( |
||||||
|
model_name='modellog', |
||||||
|
name='operation', |
||||||
|
field=models.CharField(choices=[('POST', 'POST'), ('PUT', 'PUT'), ('DELETE', 'DELETE')], max_length=50), |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-10-09 08:10 |
||||||
|
|
||||||
|
import django.db.models.deletion |
||||||
|
from django.conf import settings |
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0082_alter_modellog_operation'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AddField( |
||||||
|
model_name='modellog', |
||||||
|
name='creator', |
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-10-09 08:18 |
||||||
|
|
||||||
|
from django.db import migrations |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0083_modellog_creator'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.RenameField( |
||||||
|
model_name='modellog', |
||||||
|
old_name='creator', |
||||||
|
new_name='user', |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-10-09 11:37 |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0084_rename_creator_modellog_user'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AddField( |
||||||
|
model_name='modellog', |
||||||
|
name='store_id', |
||||||
|
field=models.CharField(blank=True, max_length=200, null=True), |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,154 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-10-15 14:42 |
||||||
|
|
||||||
|
import django.utils.timezone |
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0085_modellog_store_id'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AddField( |
||||||
|
model_name='club', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='club', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='court', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='court', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='dateinterval', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='dateinterval', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='devicetoken', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='devicetoken', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='event', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='failedapicall', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='failedapicall', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='groupstage', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='groupstage', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='log', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='log', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='match', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='match', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='playerregistration', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='playerregistration', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='purchase', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='purchase', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='round', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='round', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='teamregistration', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='teamregistration', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='teamscore', |
||||||
|
name='creation_date', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, editable=False), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='teamscore', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='tournament', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,17 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-10-16 12:42 |
||||||
|
|
||||||
|
from django.db import migrations |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0086_club_creation_date_club_last_update_and_more'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.RemoveField( |
||||||
|
model_name='modellog', |
||||||
|
name='store_id', |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-10-17 10:36 |
||||||
|
|
||||||
|
import django.utils.timezone |
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0087_remove_modellog_store_id'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AddField( |
||||||
|
model_name='customuser', |
||||||
|
name='last_update', |
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now), |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,49 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-10-17 13:02 |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0088_customuser_last_update'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AddField( |
||||||
|
model_name='groupstage', |
||||||
|
name='store_id', |
||||||
|
field=models.CharField(default='', max_length=100), |
||||||
|
preserve_default=False, |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='match', |
||||||
|
name='store_id', |
||||||
|
field=models.CharField(default='', max_length=100), |
||||||
|
preserve_default=False, |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='playerregistration', |
||||||
|
name='store_id', |
||||||
|
field=models.CharField(default='', max_length=100), |
||||||
|
preserve_default=False, |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='round', |
||||||
|
name='store_id', |
||||||
|
field=models.CharField(default='', max_length=100), |
||||||
|
preserve_default=False, |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='teamregistration', |
||||||
|
name='store_id', |
||||||
|
field=models.CharField(default='', max_length=100), |
||||||
|
preserve_default=False, |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='teamscore', |
||||||
|
name='store_id', |
||||||
|
field=models.CharField(default='', max_length=100), |
||||||
|
preserve_default=False, |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,79 @@ |
|||||||
|
# Generated by Django 5.1 on 2024-10-17 13:02 |
||||||
|
|
||||||
|
from ast import Match |
||||||
|
from django.db import migrations |
||||||
|
|
||||||
|
from tournaments.models.player_registration import PlayerRegistration |
||||||
|
|
||||||
|
def update_group_stage_store_id(apps): |
||||||
|
GroupStage = apps.get_model('tournaments', 'GroupStage') |
||||||
|
|
||||||
|
for group_stage in GroupStage.objects.all(): |
||||||
|
group_stage.store_id = str(group_stage.tournament.id) |
||||||
|
group_stage.save() |
||||||
|
|
||||||
|
def update_round_store_id(apps): |
||||||
|
Round = apps.get_model('tournaments', 'Round') |
||||||
|
|
||||||
|
for round in Round.objects.all(): |
||||||
|
round.store_id = str(round.tournament.id) |
||||||
|
round.save() |
||||||
|
|
||||||
|
def update_team_registration_store_id(apps): |
||||||
|
TeamRegistration = apps.get_model('tournaments', 'TeamRegistration') |
||||||
|
|
||||||
|
for tr in TeamRegistration.objects.all(): |
||||||
|
tr.store_id = str(tr.tournament.id) |
||||||
|
tr.save() |
||||||
|
|
||||||
|
def update_player_registration_store_id(apps): |
||||||
|
PlayerRegistration = apps.get_model('tournaments', 'PlayerRegistration') |
||||||
|
|
||||||
|
for pr in PlayerRegistration.objects.all(): |
||||||
|
pr.store_id = str(pr.team_registration.tournament.id) |
||||||
|
pr.save() |
||||||
|
|
||||||
|
def update_match_store_id(apps): |
||||||
|
Match = apps.get_model('tournaments', 'Match') |
||||||
|
|
||||||
|
for match in Match.objects.all(): |
||||||
|
if match.round: |
||||||
|
tournament = match.round.tournament |
||||||
|
else: |
||||||
|
tournament = match.group_stage.tournament |
||||||
|
match.store_id = str(tournament.id) |
||||||
|
match.save() |
||||||
|
|
||||||
|
def update_team_score_store_id(apps): |
||||||
|
TeamScore = apps.get_model('tournaments', 'TeamScore') |
||||||
|
|
||||||
|
for team_score in TeamScore.objects.all(): |
||||||
|
tournament = None |
||||||
|
if team_score.team_registration: |
||||||
|
tournament = team_score.team_registration.tournament |
||||||
|
elif team_score.match: |
||||||
|
if team_score.match.round: |
||||||
|
tournament = team_score.match.round.tournament |
||||||
|
else: |
||||||
|
tournament = team_score.team_registration.tournament |
||||||
|
|
||||||
|
team_score.store_id = str(tournament.id) |
||||||
|
team_score.save() |
||||||
|
|
||||||
|
def update_models(apps, schema_editor): |
||||||
|
update_group_stage_store_id(apps) |
||||||
|
update_round_store_id(apps) |
||||||
|
update_team_registration_store_id(apps) |
||||||
|
update_player_registration_store_id(apps) |
||||||
|
update_match_store_id(apps) |
||||||
|
update_team_score_store_id(apps) |
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('tournaments', '0089_groupstage_store_id_match_store_id_and_more'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.RunPython(update_models), |
||||||
|
] |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
from django.db import models |
||||||
|
from django.utils.timezone import now |
||||||
|
|
||||||
|
class BaseModel(models.Model): |
||||||
|
creation_date = models.DateTimeField(default=now, editable=False) |
||||||
|
last_update = models.DateTimeField(default=now) |
||||||
|
|
||||||
|
class Meta: |
||||||
|
abstract = True |
||||||
|
|
||||||
|
class SideStoreModel(BaseModel): |
||||||
|
store_id = models.CharField(max_length=100) |
||||||
|
|
||||||
|
class Meta: |
||||||
|
abstract = True |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
from django.db import models |
||||||
|
import uuid |
||||||
|
from . import ModelOperation |
||||||
|
|
||||||
|
class ModelLog(models.Model): |
||||||
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) |
||||||
|
user = models.ForeignKey('CustomUser', blank=True, null=True, on_delete=models.SET_NULL) |
||||||
|
model_id = models.UUIDField() |
||||||
|
operation = models.CharField(choices=ModelOperation.choices, max_length=50) |
||||||
|
date = models.DateTimeField() |
||||||
|
model_name = models.CharField(max_length=50) |
||||||
|
# store_id = models.CharField(max_length=200, blank=True, null=True) |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
# chat/routing.py |
||||||
|
from django.urls import re_path |
||||||
|
|
||||||
|
from . import consumers |
||||||
|
|
||||||
|
websocket_urlpatterns = [ |
||||||
|
re_path(r"ws/chat/$", consumers.ChatConsumer.as_asgi()), |
||||||
|
# re_path(r"ws/chat/(?P<room_name>\w+)/$", consumers.ChatConsumer.as_asgi()), |
||||||
|
] |
||||||
@ -0,0 +1 @@ |
|||||||
|
|
||||||
Loading…
Reference in new issue