piki/pages/__init__.py

36 lines
940 B
Python
Raw Normal View History

from datetime import datetime
from django.urls.base import reverse
import zoneinfo
2024-10-09 13:07:38 +02:00
def url_page(request, rel_path, **kwargs):
params = "&".join([f"{key}" + ("" if kwargs[key] is None else f"={kwargs[key]}") for key in kwargs])
if len(params) > 0:
params = "?" + params
return reverse('page-page', kwargs={'rel_path': rel_path}) + params
def url_helpview(request, page):
2024-10-05 16:22:40 +02:00
return reverse('page-helpview', kwargs={'page': page})
def url_edit(request, rel_path):
return reverse('page-edit', kwargs={'rel_path': rel_path})
2024-10-09 09:57:05 +02:00
def get_search_query(request):
return request.GET.get('q')
def timestamp_to_datetime(request, tm):
from users.models import get_userprofile
#
2024-10-09 21:21:33 +02:00
try:
up = get_userprofile(request.user)
except AttributeError:
return datetime.fromtimestamp(tm)
else:
tz = zoneinfo.ZoneInfo(up.timezone)
#
return datetime.fromtimestamp(tm, tz)