datatracker/ietf/status/views.py
Matthew Holloway e5e6c9bc89
feat: Site status message (#7659)
* Status WIP

* feat: Status

* fix: Status tests

* feat: status redirect

* chore: Status tests

* chore: Status tests

* feat: Status tests

* chore: Status playwright tests

* fix: PR feedback, mostly Vue and copyright dates

* fix: Status model migration tidy up

* chore: Status - one migration

* feat: status on doc/html pages

* chore: Resetting Status migration

* chore: removing unused FieldError

* fix: Update Status test to remove 'by'

* chore: fixing API test to exclude 'status'

* chore: fixing status_page test

* feat: Site Status PR feedback. URL coverage debugging

* Adding ietf.status to Tastypie omitted apps

* feat: Site Status PR feedback

* chore: correct copyright year on newly created files

* chore: repair merge damage

* chore: repair more merge damage

* fix: reconcile the api init refactor with ignoring apps

---------

Co-authored-by: Matthew Holloway <Matthew Holloway>
Co-authored-by: Robert Sparks <rjsparks@nostrum.com>
2024-08-07 13:36:21 -05:00

47 lines
1.5 KiB
Python

# Copyright The IETF Trust 2024, All Rights Reserved
# -*- coding: utf-8 -*-
from django.urls import reverse as urlreverse
from django.http import HttpResponseRedirect, HttpResponseNotFound, JsonResponse
from ietf.utils import markdown
from django.shortcuts import render, get_object_or_404
from ietf.status.models import Status
import debug # pyflakes:ignore
def get_last_active_status():
status = Status.objects.filter(active=True).order_by("-date").first()
if status is None:
return { "hasMessage": False }
context = {
"hasMessage": True,
"id": status.id,
"slug": status.slug,
"title": status.title,
"body": status.body,
"url": urlreverse("ietf.status.views.status_page", kwargs={ "slug": status.slug }),
"date": status.date.isoformat()
}
return context
def status_latest_html(request):
return render(request, "status/latest.html", context=get_last_active_status())
def status_page(request, slug):
sanitised_slug = slug.rstrip("/")
status = get_object_or_404(Status, slug=sanitised_slug)
return render(request, "status/status.html", context={
'status': status,
'status_page_html': markdown.markdown(status.page or ""),
})
def status_latest_json(request):
return JsonResponse(get_last_active_status())
def status_latest_redirect(request):
context = get_last_active_status()
if context["hasMessage"] == True:
return HttpResponseRedirect(context["url"])
return HttpResponseNotFound()