Example #1
0
    def post(self) -> Response:
        dossier_slug = self._get_dossier_slug()

        if not dossier_slug:
            self.request.session.flash(
                Message(cls="error", text="Ce dossier n’existe pas."))
            return HTTPFound(location=self.request.resource_url(self.context))

        dossier = Dossier.get(slug=dossier_slug)

        if dossier is None:
            self.request.session.flash(
                Message(cls="error", text="Ce dossier n’existe pas."))
            return HTTPFound(location=self.request.resource_url(self.context))

        if dossier.team:
            self.request.session.flash(
                Message(cls="warning",
                        text="Ce dossier appartient à une autre équipe…"))
            return HTTPFound(location=self.request.resource_url(self.context))

        team = Team.create(name=dossier.slug)
        dossier.team = team
        for admin in DBSession.query(User).filter(
                User.admin_at.isnot(None)  # type: ignore
        ):
            admin.teams.append(team)

        # Enqueue task to asynchronously add the lectures
        create_missing_lectures(dossier_pk=dossier.pk,
                                user_pk=self.request.user.pk)

        DossierActive.create(dossier=dossier, request=self.request)

        self.request.session.flash(
            Message(
                cls="success",
                text=(
                    "Dossier créé avec succès, lectures en cours de création."
                ),
            ))
        return HTTPFound(
            location=self.request.resource_url(self.context[dossier.url_key]))
Example #2
0
 def model(self, *options: Any) -> Dossier:
     dossier = Dossier.get(self.slug, *options)
     if dossier is None:
         raise ResourceNotFound(self)
     return dossier