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.

1234567891011121314151617181920212223242526272829303132333435
  1. from datetime import datetime
  2. from django.urls.base import reverse
  3. import zoneinfo
  4. def url_page(request, rel_path, **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 reverse('page-page', kwargs={'rel_path': rel_path}) + params
  9. def url_helpview(request, page):
  10. return reverse('page-helpview', kwargs={'page': page})
  11. def url_edit(request, rel_path):
  12. return reverse('page-edit', kwargs={'rel_path': rel_path})
  13. def get_search_query(request):
  14. return request.GET.get('q')
  15. def timestamp_to_datetime(request, tm):
  16. from users.models import get_userprofile
  17. #
  18. try:
  19. up = get_userprofile(request.user)
  20. except AttributeError:
  21. return datetime.fromtimestamp(tm)
  22. else:
  23. tz = zoneinfo.ZoneInfo(up.timezone)
  24. #
  25. return datetime.fromtimestamp(tm, tz)