117 lines
3.1 KiB
Python
117 lines
3.1 KiB
Python
# 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',)
|