mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-01 00:24:29 +01:00 
			
		
		
		
	Prepare models for new chat feature
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		
							
								
								
									
										2
									
								
								chat/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								chat/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
							
								
								
									
										22
									
								
								chat/admin.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								chat/admin.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
|  | ||||
| from django.contrib import admin | ||||
|  | ||||
| from .models import Channel, Message | ||||
|  | ||||
|  | ||||
| @admin.register(Channel) | ||||
| class ChannelAdmin(admin.ModelAdmin): | ||||
|     list_display = ('name', 'read_access', 'write_access', 'tournament', 'pool', 'team', 'private',) | ||||
|     list_filter = ('read_access', 'write_access', 'tournament', 'private',) | ||||
|     search_fields = ('name', 'tournament__name', 'team__name', 'team__trigram',) | ||||
|     autocomplete_fields = ('tournament', 'pool', 'team', 'invited', ) | ||||
|  | ||||
|  | ||||
| @admin.register(Message) | ||||
| class MessageAdmin(admin.ModelAdmin): | ||||
|     list_display = ('channel', 'author', 'created_at', 'updated_at', 'content',) | ||||
|     list_filter = ('channel', 'created_at', 'updated_at',) | ||||
|     search_fields = ('author__username', 'author__first_name', 'author__last_name', 'content',) | ||||
|     autocomplete_fields = ('channel', 'author',) | ||||
							
								
								
									
										9
									
								
								chat/apps.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								chat/apps.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
|  | ||||
| from django.apps import AppConfig | ||||
|  | ||||
|  | ||||
| class ChatConfig(AppConfig): | ||||
|     default_auto_field = "django.db.models.BigAutoField" | ||||
|     name = "chat" | ||||
							
								
								
									
										198
									
								
								chat/migrations/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										198
									
								
								chat/migrations/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,198 @@ | ||||
| # Generated by Django 5.0.3 on 2024-04-27 06:48 | ||||
|  | ||||
| import django.db.models.deletion | ||||
| from django.conf import settings | ||||
| from django.db import migrations, models | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|  | ||||
|     initial = True | ||||
|  | ||||
|     dependencies = [ | ||||
|         ("participation", "0013_alter_pool_options_pool_room"), | ||||
|         migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||||
|     ] | ||||
|  | ||||
|     operations = [ | ||||
|         migrations.CreateModel( | ||||
|             name="Channel", | ||||
|             fields=[ | ||||
|                 ( | ||||
|                     "id", | ||||
|                     models.BigAutoField( | ||||
|                         auto_created=True, | ||||
|                         primary_key=True, | ||||
|                         serialize=False, | ||||
|                         verbose_name="ID", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ("name", models.CharField(max_length=255, verbose_name="name")), | ||||
|                 ( | ||||
|                     "read_access", | ||||
|                     models.PositiveSmallIntegerField( | ||||
|                         choices=[ | ||||
|                             ("anonymous", "Everyone, including anonymous users"), | ||||
|                             ("authenticated", "Authenticated users"), | ||||
|                             ("volunteer", "All volunteers"), | ||||
|                             ("tournament", "All members of a given tournament"), | ||||
|                             ("organizer", "Tournament organizers only"), | ||||
|                             ( | ||||
|                                 "jury_president", | ||||
|                                 "Tournament organizers and jury presidents of the tournament", | ||||
|                             ), | ||||
|                             ("jury", "Jury members of the pool"), | ||||
|                             ("pool", "Jury members and participants of the pool"), | ||||
|                             ( | ||||
|                                 "team", | ||||
|                                 "Members of the team and organizers of concerned tournaments", | ||||
|                             ), | ||||
|                             ( | ||||
|                                 "private", | ||||
|                                 "Private, reserved to explicit authorized users", | ||||
|                             ), | ||||
|                             ("admin", "Admin users"), | ||||
|                         ], | ||||
|                         verbose_name="read permission", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "write_access", | ||||
|                     models.PositiveSmallIntegerField( | ||||
|                         choices=[ | ||||
|                             ("anonymous", "Everyone, including anonymous users"), | ||||
|                             ("authenticated", "Authenticated users"), | ||||
|                             ("volunteer", "All volunteers"), | ||||
|                             ("tournament", "All members of a given tournament"), | ||||
|                             ("organizer", "Tournament organizers only"), | ||||
|                             ( | ||||
|                                 "jury_president", | ||||
|                                 "Tournament organizers and jury presidents of the tournament", | ||||
|                             ), | ||||
|                             ("jury", "Jury members of the pool"), | ||||
|                             ("pool", "Jury members and participants of the pool"), | ||||
|                             ( | ||||
|                                 "team", | ||||
|                                 "Members of the team and organizers of concerned tournaments", | ||||
|                             ), | ||||
|                             ( | ||||
|                                 "private", | ||||
|                                 "Private, reserved to explicit authorized users", | ||||
|                             ), | ||||
|                             ("admin", "Admin users"), | ||||
|                         ], | ||||
|                         verbose_name="write permission", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "private", | ||||
|                     models.BooleanField( | ||||
|                         default=False, | ||||
|                         help_text="If checked, only users who have been explicitly added to the channel will be able to access it.", | ||||
|                         verbose_name="private", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "invited", | ||||
|                     models.ManyToManyField( | ||||
|                         blank=True, | ||||
|                         help_text="Extra users who have been invited to the channel, in addition to the permitted group of the channel.", | ||||
|                         related_name="+", | ||||
|                         to=settings.AUTH_USER_MODEL, | ||||
|                         verbose_name="invited users", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "pool", | ||||
|                     models.ForeignKey( | ||||
|                         blank=True, | ||||
|                         default=None, | ||||
|                         help_text="For a permission that concerns a pool, indicates what is the concerned pool.", | ||||
|                         null=True, | ||||
|                         on_delete=django.db.models.deletion.CASCADE, | ||||
|                         related_name="chat_channels", | ||||
|                         to="participation.pool", | ||||
|                         verbose_name="pool", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "team", | ||||
|                     models.ForeignKey( | ||||
|                         blank=True, | ||||
|                         default=None, | ||||
|                         help_text="For a permission that concerns a team, indicates what is the concerned team.", | ||||
|                         null=True, | ||||
|                         on_delete=django.db.models.deletion.CASCADE, | ||||
|                         related_name="chat_channels", | ||||
|                         to="participation.team", | ||||
|                         verbose_name="team", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "tournament", | ||||
|                     models.ForeignKey( | ||||
|                         blank=True, | ||||
|                         default=None, | ||||
|                         help_text="For a permission that concerns a tournament, indicates what is the concerned tournament.", | ||||
|                         null=True, | ||||
|                         on_delete=django.db.models.deletion.CASCADE, | ||||
|                         related_name="chat_channels", | ||||
|                         to="participation.tournament", | ||||
|                         verbose_name="tournament", | ||||
|                     ), | ||||
|                 ), | ||||
|             ], | ||||
|             options={ | ||||
|                 "verbose_name": "channel", | ||||
|                 "verbose_name_plural": "channels", | ||||
|                 "ordering": ("name",), | ||||
|             }, | ||||
|         ), | ||||
|         migrations.CreateModel( | ||||
|             name="Message", | ||||
|             fields=[ | ||||
|                 ( | ||||
|                     "id", | ||||
|                     models.BigAutoField( | ||||
|                         auto_created=True, | ||||
|                         primary_key=True, | ||||
|                         serialize=False, | ||||
|                         verbose_name="ID", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "created_at", | ||||
|                     models.DateTimeField(auto_now_add=True, verbose_name="created at"), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "updated_at", | ||||
|                     models.DateTimeField(auto_now=True, verbose_name="updated at"), | ||||
|                 ), | ||||
|                 ("content", models.TextField(verbose_name="content")), | ||||
|                 ( | ||||
|                     "author", | ||||
|                     models.ForeignKey( | ||||
|                         null=True, | ||||
|                         on_delete=django.db.models.deletion.SET_NULL, | ||||
|                         related_name="chat_messages", | ||||
|                         to=settings.AUTH_USER_MODEL, | ||||
|                         verbose_name="author", | ||||
|                     ), | ||||
|                 ), | ||||
|                 ( | ||||
|                     "channel", | ||||
|                     models.ForeignKey( | ||||
|                         on_delete=django.db.models.deletion.CASCADE, | ||||
|                         related_name="messages", | ||||
|                         to="chat.channel", | ||||
|                         verbose_name="channel", | ||||
|                     ), | ||||
|                 ), | ||||
|             ], | ||||
|             options={ | ||||
|                 "verbose_name": "message", | ||||
|                 "verbose_name_plural": "messages", | ||||
|                 "ordering": ("created_at",), | ||||
|             }, | ||||
|         ), | ||||
|     ] | ||||
							
								
								
									
										2
									
								
								chat/migrations/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								chat/migrations/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
							
								
								
									
										116
									
								
								chat/models.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								chat/models.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,116 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
|  | ||||
| from django.db import models | ||||
| from django.utils.text import format_lazy | ||||
| from django.utils.translation import gettext_lazy as _ | ||||
| from tfjm.permissions import PermissionType | ||||
|  | ||||
|  | ||||
| class Channel(models.Model): | ||||
|     name = models.CharField( | ||||
|         max_length=255, | ||||
|         verbose_name=_("name"), | ||||
|     ) | ||||
|  | ||||
|     read_access = models.PositiveSmallIntegerField( | ||||
|         verbose_name=_("read permission"), | ||||
|         choices=PermissionType, | ||||
|     ) | ||||
|  | ||||
|     write_access = models.PositiveSmallIntegerField( | ||||
|         verbose_name=_("write permission"), | ||||
|         choices=PermissionType, | ||||
|     ) | ||||
|  | ||||
|     tournament = models.ForeignKey( | ||||
|         'participation.Tournament', | ||||
|         on_delete=models.CASCADE, | ||||
|         blank=True, | ||||
|         null=True, | ||||
|         default=None, | ||||
|         verbose_name=_("tournament"), | ||||
|         related_name='chat_channels', | ||||
|         help_text=_("For a permission that concerns a tournament, indicates what is the concerned tournament."), | ||||
|     ) | ||||
|  | ||||
|     pool = models.ForeignKey( | ||||
|         'participation.Pool', | ||||
|         on_delete=models.CASCADE, | ||||
|         blank=True, | ||||
|         null=True, | ||||
|         default=None, | ||||
|         verbose_name=_("pool"), | ||||
|         related_name='chat_channels', | ||||
|         help_text=_("For a permission that concerns a pool, indicates what is the concerned pool."), | ||||
|     ) | ||||
|  | ||||
|     team = models.ForeignKey( | ||||
|         'participation.Team', | ||||
|         on_delete=models.CASCADE, | ||||
|         blank=True, | ||||
|         null=True, | ||||
|         default=None, | ||||
|         verbose_name=_("team"), | ||||
|         related_name='chat_channels', | ||||
|         help_text=_("For a permission that concerns a team, indicates what is the concerned team."), | ||||
|     ) | ||||
|  | ||||
|     private = models.BooleanField( | ||||
|         verbose_name=_("private"), | ||||
|         default=False, | ||||
|         help_text=_("If checked, only users who have been explicitly added to the channel will be able to access it."), | ||||
|     ) | ||||
|  | ||||
|     invited = models.ManyToManyField( | ||||
|         'auth.User', | ||||
|         verbose_name=_("invited users"), | ||||
|         related_name='+', | ||||
|         blank=True, | ||||
|         help_text=_("Extra users who have been invited to the channel, " | ||||
|                     "in addition to the permitted group of the channel."), | ||||
|     ) | ||||
|  | ||||
|     def __str__(self): | ||||
|         return format_lazy(_("Channel {name}"), name=self.name) | ||||
|  | ||||
|     class Meta: | ||||
|         verbose_name = _("channel") | ||||
|         verbose_name_plural = _("channels") | ||||
|         ordering = ('name',) | ||||
|  | ||||
|  | ||||
| class Message(models.Model): | ||||
|     channel = models.ForeignKey( | ||||
|         Channel, | ||||
|         on_delete=models.CASCADE, | ||||
|         verbose_name=_("channel"), | ||||
|         related_name='messages', | ||||
|     ) | ||||
|  | ||||
|     author = models.ForeignKey( | ||||
|         'auth.User', | ||||
|         verbose_name=_("author"), | ||||
|         on_delete=models.SET_NULL, | ||||
|         null=True, | ||||
|         related_name='chat_messages', | ||||
|     ) | ||||
|  | ||||
|     created_at = models.DateTimeField( | ||||
|         verbose_name=_("created at"), | ||||
|         auto_now_add=True, | ||||
|     ) | ||||
|  | ||||
|     updated_at = models.DateTimeField( | ||||
|         verbose_name=_("updated at"), | ||||
|         auto_now=True, | ||||
|     ) | ||||
|  | ||||
|     content = models.TextField( | ||||
|         verbose_name=_("content"), | ||||
|     ) | ||||
|  | ||||
|     class Meta: | ||||
|         verbose_name = _("message") | ||||
|         verbose_name_plural = _("messages") | ||||
|         ordering = ('created_at',) | ||||
							
								
								
									
										2
									
								
								chat/tests.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								chat/tests.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
							
								
								
									
										2
									
								
								chat/urls.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								chat/urls.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
							
								
								
									
										2
									
								
								chat/views.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								chat/views.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| # Copyright (C) 2024 by Animath | ||||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||||
		Reference in New Issue
	
	Block a user