Piki is a minimal wiki
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 994B

123456789101112131415161718192021222324252627282930313233343536373839
  1. from datetime import datetime
  2. from django.urls.base import reverse
  3. import zoneinfo
  4. def params(**kwargs):
  5. params = "&".join([f"{key}" + ("" if kwargs[key] is None else f"={kwargs[key]}") for key in kwargs])
  6. if len(params) > 0:
  7. params = "?" + params
  8. return params
  9. def url_page(rel_path, **kwargs):
  10. return reverse('page-page', kwargs={'rel_path': rel_path}) + params(**kwargs)
  11. def url_helpview(page):
  12. return reverse('page-helpview', kwargs={'page': page})
  13. def url_edit(rel_path, **kwargs):
  14. return reverse('page-edit', kwargs={'rel_path': rel_path}) + params(**kwargs)
  15. def get_search_query(request):
  16. return request.GET.get('q')
  17. def timestamp_to_datetime(request, tm):
  18. from users.models import get_userprofile
  19. #
  20. try:
  21. up = get_userprofile(request.user)
  22. except AttributeError:
  23. return datetime.fromtimestamp(tm)
  24. else:
  25. tz = zoneinfo.ZoneInfo(up.timezone)
  26. #
  27. return datetime.fromtimestamp(tm, tz)