Piki is a minimal wiki
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

__init__.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_delete(rel_path, **kwargs):
  14. return reverse('page-delete', kwargs={'rel_path': rel_path}) + params(**kwargs)
  15. def url_edit(rel_path, **kwargs):
  16. return reverse('page-edit', kwargs={'rel_path': rel_path}) + params(**kwargs)
  17. def url_rename(rel_path, **kwargs):
  18. return reverse('page-rename', kwargs={'rel_path': rel_path}) + params(**kwargs)
  19. def get_search_query(request):
  20. return request.GET.get('q')
  21. def timestamp_to_datetime(request, tm):
  22. from users.models import get_userprofile
  23. #
  24. try:
  25. up = get_userprofile(request.user)
  26. except AttributeError:
  27. return datetime.fromtimestamp(tm)
  28. else:
  29. tz = zoneinfo.ZoneInfo(up.timezone)
  30. #
  31. return datetime.fromtimestamp(tm, tz)