2021-06-11 17:31:07 +00:00
|
|
|
import os
|
2022-09-11 01:35:07 +00:00
|
|
|
from urllib.parse import parse_qs
|
2021-06-11 17:31:07 +00:00
|
|
|
|
|
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "whispermaphone.settings"
|
|
|
|
|
|
|
|
import django
|
|
|
|
from django.template.loader import render_to_string
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
django.setup()
|
2022-09-11 01:35:07 +00:00
|
|
|
|
2022-04-30 17:33:57 +00:00
|
|
|
from thoughts.models import Thought
|
2022-09-11 01:35:07 +00:00
|
|
|
from thoughts.pagination import get_all_pages, get_page_slug, get_page
|
2021-06-11 17:31:07 +00:00
|
|
|
|
|
|
|
from jetforce import GeminiServer, JetforceApplication, Response, Status
|
|
|
|
|
2021-06-25 07:22:48 +00:00
|
|
|
from decouple import config
|
|
|
|
|
2021-06-11 17:31:07 +00:00
|
|
|
app = JetforceApplication()
|
|
|
|
|
2021-10-12 04:12:27 +00:00
|
|
|
|
2021-06-11 17:31:07 +00:00
|
|
|
@app.route("", strict_trailing_slash=False)
|
|
|
|
def index(request):
|
|
|
|
thoughts = Thought.objects.order_by("-posted")
|
|
|
|
|
2022-09-11 01:35:07 +00:00
|
|
|
pages = get_all_pages()
|
|
|
|
|
|
|
|
[requested_slug] = parse_qs(request.query).get("page", [""])
|
|
|
|
requested_page = get_page(requested_slug)
|
|
|
|
|
|
|
|
thoughts = requested_page.get_all_entries()
|
|
|
|
|
2022-04-30 17:33:57 +00:00
|
|
|
rendered_text = render_to_string("thoughts/index.gmi", {
|
2021-06-11 17:31:07 +00:00
|
|
|
"thoughts": thoughts,
|
2022-09-11 01:54:46 +00:00
|
|
|
"first_page": requested_page.slug == pages[0].slug,
|
2022-09-11 01:35:07 +00:00
|
|
|
"pages": pages,
|
|
|
|
"current_page_slug": requested_page.slug,
|
2021-06-11 17:31:07 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return Response(Status.SUCCESS, "text/gemini", rendered_text)
|
|
|
|
|
2021-10-12 04:12:27 +00:00
|
|
|
|
2021-06-11 17:31:07 +00:00
|
|
|
@app.route("/about", strict_trailing_slash=False)
|
|
|
|
def about(request):
|
2022-05-07 21:11:11 +00:00
|
|
|
return Response(Status.SUCCESS, "text/gemini", render_to_string("thoughts/about.gmi"))
|
2021-06-11 17:31:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
server = GeminiServer(
|
|
|
|
app=app,
|
2021-06-25 07:22:48 +00:00
|
|
|
host="0.0.0.0",
|
2021-10-12 04:12:27 +00:00
|
|
|
hostname="localhost",
|
2021-06-25 07:22:48 +00:00
|
|
|
certfile=config("CERTFILE", default=None),
|
2021-10-03 23:42:52 +00:00
|
|
|
keyfile=config("KEYFILE", default=None),
|
|
|
|
port=1973
|
2021-06-11 17:31:07 +00:00
|
|
|
)
|
|
|
|
server.run()
|