mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-03-17 00:47:32 +00:00
Compare commits
3 Commits
2f6a1f6e56
...
1392b50db1
Author | SHA1 | Date | |
---|---|---|---|
|
1392b50db1 | ||
|
bcca41bfb6 | ||
|
4f1f4b0783 |
41
apps/participation/management/commands/setup_third_phase.py
Normal file
41
apps/participation/management/commands/setup_third_phase.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from corres2math.matrix import Matrix, RoomVisibility
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
from participation.models import Participation
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
for participation in Participation.objects.filter(valid=True).all():
|
||||||
|
for i, question in enumerate(participation.questions.order_by("id").all()):
|
||||||
|
solution_author = participation.received_participation.team
|
||||||
|
alias = f"equipe-{solution_author.trigram.lower()}-question-{i}"
|
||||||
|
room_id = f"#{alias}:correspondances-maths.fr"
|
||||||
|
Matrix.create_room(
|
||||||
|
visibility=RoomVisibility.public,
|
||||||
|
alias=alias,
|
||||||
|
name=f"Solution équipe {solution_author.trigram} - question {i+1}",
|
||||||
|
topic=f"Échange entre l'équipe {solution_author.name} ({solution_author.trigram}) "
|
||||||
|
f"et l'équipe {participation.team.name} ({participation.team.trigram}) "
|
||||||
|
f"autour de la question {i+1} sur le problème {participation.problem}",
|
||||||
|
federate=False,
|
||||||
|
invite=[f"@{registration.matrix_username}:correspondances-maths.fr" for registration in
|
||||||
|
list(participation.team.students.all()) + list(participation.team.coachs.all()) +
|
||||||
|
list(solution_author.students.all()) + list(solution_author.coachs.all())],
|
||||||
|
)
|
||||||
|
Matrix.set_room_power_level_event(room_id, "events_default", 21)
|
||||||
|
for registration in solution_author.students.all():
|
||||||
|
Matrix.set_room_power_level(room_id,
|
||||||
|
f"@{registration.matrix_username}:correspondances-maths.fr", 42)
|
||||||
|
|
||||||
|
Matrix.send_message(room_id, "Bienvenue dans la troisième phase des Correspondances !")
|
||||||
|
Matrix.send_message(room_id, f"L'équipe {participation.team.name} a visionné la vidéo de l'équipe "
|
||||||
|
f"{solution_author.name} sur le problème {participation.problem}, et a posé "
|
||||||
|
"une série de questions.")
|
||||||
|
Matrix.send_message(room_id, "L'équipe ayant composé la vidéo doit maintenant proposer une réponse.")
|
||||||
|
Matrix.send_message(room_id, "Une fois la réponse apportée, vous pourrez ensuite échanger plus "
|
||||||
|
"librement autour de la question, au travers de ce canal.")
|
||||||
|
Matrix.send_message(room_id, "**Question posée :**", formatted_body="<strong>Question posée :</strong>")
|
||||||
|
Matrix.send_message(room_id, question.question,
|
||||||
|
formatted_body=f"<font color=\"#ff0000\">{question.question}</font>")
|
||||||
|
|
||||||
|
# TODO Setup the bot the set the power level of all members of the room to 42
|
@ -83,7 +83,7 @@ class Team(models.Model):
|
|||||||
Matrix.create_room(
|
Matrix.create_room(
|
||||||
visibility=RoomVisibility.private,
|
visibility=RoomVisibility.private,
|
||||||
name=f"#équipe-{self.trigram.lower()}",
|
name=f"#équipe-{self.trigram.lower()}",
|
||||||
alias=f"team-{self.trigram.lower()}",
|
alias=f"equipe-{self.trigram.lower()}",
|
||||||
topic=f"Discussion de l'équipe {self.name}",
|
topic=f"Discussion de l'équipe {self.name}",
|
||||||
preset=RoomPreset.private_chat,
|
preset=RoomPreset.private_chat,
|
||||||
)
|
)
|
||||||
@ -245,6 +245,9 @@ class Question(models.Model):
|
|||||||
verbose_name=_("question"),
|
verbose_name=_("question"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.question
|
||||||
|
|
||||||
|
|
||||||
class Phase(models.Model):
|
class Phase(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -65,7 +65,7 @@ class CreateTeamView(LoginRequiredMixin, CreateView):
|
|||||||
f"{user.first_name} {user.last_name}")
|
f"{user.first_name} {user.last_name}")
|
||||||
|
|
||||||
# Invite the user in the team Matrix room
|
# Invite the user in the team Matrix room
|
||||||
Matrix.invite(f"#team-{form.instance.trigram.lower()}:correspondances-maths.fr",
|
Matrix.invite(f"#equipe-{form.instance.trigram.lower()}:correspondances-maths.fr",
|
||||||
f"@{user.registration.matrix_username}:correspondances-maths.fr")
|
f"@{user.registration.matrix_username}:correspondances-maths.fr")
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ class JoinTeamView(LoginRequiredMixin, FormView):
|
|||||||
f"{user.first_name} {user.last_name}")
|
f"{user.first_name} {user.last_name}")
|
||||||
|
|
||||||
# Invite the user in the team Matrix room
|
# Invite the user in the team Matrix room
|
||||||
Matrix.invite(f"#team-{form.instance.trigram.lower()}:correspondances-maths.fr",
|
Matrix.invite(f"#equipe-{form.instance.trigram.lower()}:correspondances-maths.fr",
|
||||||
f"@{user.registration.matrix_username}:correspondances-maths.fr")
|
f"@{user.registration.matrix_username}:correspondances-maths.fr")
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ class TeamLeaveView(LoginRequiredMixin, TemplateView):
|
|||||||
request.user.registration.team = None
|
request.user.registration.team = None
|
||||||
request.user.registration.save()
|
request.user.registration.save()
|
||||||
get_sympa_client().unsubscribe(request.user.email, f"equipe-{team.trigram.lower()}", False)
|
get_sympa_client().unsubscribe(request.user.email, f"equipe-{team.trigram.lower()}", False)
|
||||||
Matrix.kick(f"#team-{team.trigram.lower()}:correspondances-maths.fr",
|
Matrix.kick(f"#equipe-{team.trigram.lower()}:correspondances-maths.fr",
|
||||||
f"@{request.user.registration.matrix_username}:correspondances-maths.fr",
|
f"@{request.user.registration.matrix_username}:correspondances-maths.fr",
|
||||||
"Équipe quittée")
|
"Équipe quittée")
|
||||||
if team.students.count() + team.coachs.count() == 0:
|
if team.students.count() + team.coachs.count() == 0:
|
||||||
@ -449,7 +449,6 @@ class DeleteQuestionView(LoginRequiredMixin, DeleteView):
|
|||||||
return reverse_lazy("participation:participation_detail", args=(self.object.participation.pk,))
|
return reverse_lazy("participation:participation_detail", args=(self.object.participation.pk,))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UploadVideoView(LoginRequiredMixin, UpdateView):
|
class UploadVideoView(LoginRequiredMixin, UpdateView):
|
||||||
"""
|
"""
|
||||||
Upload a solution video for a team.
|
Upload a solution video for a team.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from corres2math.lists import get_sympa_client
|
from corres2math.lists import get_sympa_client
|
||||||
|
from corres2math.matrix import Matrix
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from corres2math.matrix import Matrix
|
|
||||||
from .models import AdminRegistration, Registration
|
from .models import AdminRegistration, Registration
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,6 +238,29 @@ class Matrix:
|
|||||||
room_id = await cls.resolve_room_alias(room_id)
|
room_id = await cls.resolve_room_alias(room_id)
|
||||||
return await client.room_invite(room_id, user_id)
|
return await client.room_invite(room_id, user_id)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@async_to_sync
|
||||||
|
async def send_message(cls, room_id: str, body: str, formatted_body: str = None,
|
||||||
|
msgtype: str = "m.text", html: bool = True):
|
||||||
|
"""
|
||||||
|
Send a message to a room.
|
||||||
|
"""
|
||||||
|
client = await cls._get_client()
|
||||||
|
if room_id.startswith("#"):
|
||||||
|
room_id = await cls.resolve_room_alias(room_id)
|
||||||
|
content = {
|
||||||
|
"msgtype": msgtype,
|
||||||
|
"body": body,
|
||||||
|
"formatted_body": formatted_body or body,
|
||||||
|
}
|
||||||
|
if html:
|
||||||
|
content["format"] = "org.matrix.custom.html"
|
||||||
|
return await client.room_send(
|
||||||
|
room_id=room_id,
|
||||||
|
message_type="m.room.message",
|
||||||
|
content=content,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@async_to_sync
|
@async_to_sync
|
||||||
async def kick(cls, room_id: str, user_id: str, reason: str = None) -> Union[RoomKickResponse, RoomInviteError]:
|
async def kick(cls, room_id: str, user_id: str, reason: str = None) -> Union[RoomKickResponse, RoomInviteError]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user