mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-10 00:03:24 +00:00
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
|
from django.conf import settings
|
||
|
from django.http import HttpResponse
|
||
|
from ninja_extra import ControllerBase, api_controller, route
|
||
|
from ninja_extra.exceptions import PermissionDenied
|
||
|
|
||
|
from club.models import Mailing
|
||
|
from core.schemas import MarkdownSchema
|
||
|
from core.templatetags.renderer import markdown
|
||
|
|
||
|
|
||
|
@api_controller("/markdown")
|
||
|
class MarkdownController(ControllerBase):
|
||
|
@route.post("", url_name="markdown")
|
||
|
def render_markdown(self, body: MarkdownSchema):
|
||
|
"""Convert the markdown text into html."""
|
||
|
return HttpResponse(markdown(body.text), content_type="text/html")
|
||
|
|
||
|
|
||
|
@api_controller("/mailings")
|
||
|
class MailingListController(ControllerBase):
|
||
|
@route.get("", response=str)
|
||
|
def fetch_mailing_lists(self, key: str):
|
||
|
if key != settings.SITH_MAILING_FETCH_KEY:
|
||
|
raise PermissionDenied
|
||
|
mailings = Mailing.objects.filter(
|
||
|
is_moderated=True, club__is_active=True
|
||
|
).prefetch_related("subscriptions")
|
||
|
data = "\n".join(m.fetch_format() for m in mailings)
|
||
|
return data
|