2021-06-11 17:31:07 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "whispermaphone.settings"
|
|
|
|
|
|
|
|
import django
|
|
|
|
from django.template.loader import render_to_string
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
django.setup()
|
|
|
|
from main.models import Thought
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
@app.route("", strict_trailing_slash=False)
|
|
|
|
def index(request):
|
|
|
|
thoughts = Thought.objects.order_by("-posted")
|
|
|
|
|
|
|
|
for thought in thoughts:
|
|
|
|
thought.timezone = timezone.get_fixed_timezone(-thought.timezone_offset)
|
|
|
|
offset_hours = -thought.timezone_offset / 60
|
|
|
|
if offset_hours == int(offset_hours):
|
|
|
|
offset_hours = int(offset_hours)
|
|
|
|
if offset_hours > 0:
|
|
|
|
offset_hours = "+" + str(offset_hours)
|
|
|
|
thought.offset_hours = offset_hours
|
|
|
|
|
|
|
|
|
|
|
|
rendered_text = render_to_string("whispermaphone/index.gmi", {
|
|
|
|
"thoughts": thoughts,
|
|
|
|
})
|
|
|
|
|
|
|
|
return Response(Status.SUCCESS, "text/gemini", rendered_text)
|
|
|
|
|
|
|
|
@app.route("/about", strict_trailing_slash=False)
|
|
|
|
def about(request):
|
2021-06-25 07:49:28 +00:00
|
|
|
return Response(Status.SUCCESS, "text/gemini", render_to_string("whispermaphone/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",
|
|
|
|
hostname=("localhost" if settings.DEBUG else settings.ALLOWED_HOSTS[0]),
|
|
|
|
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()
|