Piki is a minimal wiki
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

__init__.py 1021B

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(request, rel_path, **kwargs):
  10. return reverse('page-page', kwargs={'rel_path': rel_path}) + params(**kwargs)
  11. def url_helpview(request, page):
  12. return reverse('page-helpview', kwargs={'page': page})
  13. def url_edit(request, 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)