Basic Gemini support
This commit is contained in:
parent
f087113400
commit
36d0d3b325
|
@ -0,0 +1,47 @@
|
|||
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
|
||||
|
||||
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):
|
||||
return Response(Status.SUCCESS, "text/gemini", "a mystery")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
server = GeminiServer(
|
||||
app=app,
|
||||
host=settings.ALLOWED_HOSTS[0]
|
||||
)
|
||||
server.run()
|
|
@ -0,0 +1,11 @@
|
|||
# Thoughts
|
||||
{% for thought in thoughts %}{{ thought.text|safe }}
|
||||
{% if thought.extended_text %}
|
||||
{{ thought.extended_text|safe }}{% endif %}{% if thought.media %}
|
||||
=> https://thoughts.learnerpages.com{{ thought.media.url }}{% endif %}{% load tz %}
|
||||
```
|
||||
{% timezone thought.timezone %}{{ thought.posted|time:"g:i a" }} {{ thought.posted|date:"M d, Y" }}, UTC{{ thought.offset_hours }}{% endtimezone %}
|
||||
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
|
||||
```
|
||||
{% endfor %}
|
||||
|
|
@ -3,3 +3,4 @@ python-magic~=0.4.22
|
|||
bleach~=3.3.0
|
||||
Pygments~=2.8.1
|
||||
Markdown~=3.3.4
|
||||
jetforce
|
||||
|
|
|
@ -27,7 +27,7 @@ DEBUG = True
|
|||
|
||||
ALLOWED_HOSTS = ["thoughts.learnerpages.com"]
|
||||
if DEBUG:
|
||||
ALLOWED_HOSTS += ["*"]
|
||||
ALLOWED_HOSTS = ["localhost"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
|
Loading…
Reference in New Issue