Add WebFinger support and refactor some of the request manip stuff
This commit is contained in:
parent
00d7a29b2d
commit
1a9582213a
7 changed files with 81 additions and 22 deletions
|
@ -1,16 +1,13 @@
|
|||
import json
|
||||
from os.path import join
|
||||
from types import SimpleNamespace
|
||||
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from ..utils import load_package_json, origin, uri
|
||||
|
||||
from .. import breadcrumbs
|
||||
from entries import kinds
|
||||
|
||||
register = template.Library()
|
||||
cache = SimpleNamespace(package_json=None)
|
||||
|
||||
|
||||
class MenuItem:
|
||||
|
@ -22,24 +19,17 @@ class MenuItem:
|
|||
|
||||
@register.simple_tag
|
||||
def get_package_json():
|
||||
if cache.package_json:
|
||||
return cache.package_json
|
||||
with open(join(settings.BASE_DIR, 'package.json')) as f:
|
||||
cache.package_json = json.load(f)
|
||||
return cache.package_json
|
||||
return load_package_json()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def request_origin(request):
|
||||
return '{scheme}://{host}'.format(
|
||||
scheme=request.scheme,
|
||||
host=request.META['HTTP_HOST'],
|
||||
)
|
||||
return origin(request)
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def request_uri(request):
|
||||
return request_origin(request) + request.path
|
||||
return uri(request)
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
|
|
22
lemoncurry/utils.py
Normal file
22
lemoncurry/utils.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
import json
|
||||
from django.conf import settings
|
||||
from os.path import join
|
||||
from types import SimpleNamespace
|
||||
|
||||
cache = SimpleNamespace(package_json=None)
|
||||
|
||||
|
||||
def load_package_json():
|
||||
if cache.package_json:
|
||||
return cache.package_json
|
||||
with open(join(settings.BASE_DIR, 'package.json')) as f:
|
||||
cache.package_json = json.load(f)
|
||||
return cache.package_json
|
||||
|
||||
|
||||
def origin(request):
|
||||
return '{0}://{1}'.format(request.scheme, request.META['HTTP_HOST'])
|
||||
|
||||
|
||||
def uri(request):
|
||||
return origin(request) + request.path
|
Loading…
Add table
Add a link
Reference in a new issue