Django Library PaTT
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

__init__.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from django.urls.base import reverse
  2. from django.utils.translation import gettext as _
  3. def back_url(request, addition):
  4. return request.path + addition
  5. def url_current(request):
  6. return request.GET.get('next', request.get_full_path())
  7. def url_tasklist(request, user_filter_id=None, search_txt=None, common_filter_id=None):
  8. if user_filter_id is not None:
  9. return reverse('patt-userfilter', kwargs={'user_filter_id': user_filter_id})
  10. elif search_txt is not None:
  11. return reverse('search') + '?q=%s' % search_txt
  12. elif common_filter_id is not None:
  13. return reverse('patt-commonfilter', kwargs={'common_filter_id': common_filter_id})
  14. else:
  15. return reverse('patt-tasklist')
  16. def url_projectlist(request):
  17. return reverse('patt-projectlist')
  18. def url_helpview(request, page):
  19. return reverse('patt-helpview', kwargs={'page': page})
  20. def url_tasknew(request, project_id):
  21. nxt = url_current(request)
  22. return reverse('patt-tasknew') + '?next=%s' % nxt + ('&project_id=%s' % project_id if project_id is not None else '')
  23. def url_projectnew(request):
  24. nxt = url_current(request)
  25. return reverse('patt-projectnew') + '?next=%s' % nxt
  26. def url_taskedit(request, task_id):
  27. nxt = url_current(request)
  28. return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=edit&next=%s' % nxt
  29. def url_projectedit(request, project_id):
  30. nxt = url_current(request)
  31. return reverse('patt-projectedit', kwargs={'project_id': project_id}) + '?next=%s' % nxt
  32. def url_commentnew(request, task_id):
  33. nxt = url_current(request)
  34. return reverse('patt-commentnew', kwargs={'task_id': task_id}) + '?next=%s' % nxt
  35. def url_easysearch(request):
  36. return reverse('patt-easysearch')
  37. def url_taskset(request, task_id, **kwargs):
  38. nxt = url_current(request)
  39. if kwargs.get('priority') is not None:
  40. return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=set_priority&priority=%s&next=%s' % (kwargs.get('priority'), nxt)
  41. elif kwargs.get('state') is not None:
  42. return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=set_state&state=%s&next=%s' % (kwargs.get('state'), nxt)
  43. else:
  44. raise Exception('Required keyword missing. One of "priority", "state" is not in %s.' % repr(kwargs.keys()))
  45. def url_filteredit(request, search_id=None):
  46. if search_id is None:
  47. if get_search_query(request) is None:
  48. return reverse('patt-filternew')
  49. else:
  50. return reverse('patt-filternew') + '?q=%s' % get_search_query(request)
  51. else:
  52. return reverse('patt-filteredit', kwargs={'search_id': search_id})
  53. def url_printview(request):
  54. if not is_printview(request):
  55. search_query = get_search_query(request)
  56. return '?printview' + (('&q=%s' % search_query) if search_query is not None else '')
  57. else:
  58. return request.path
  59. def get_search_query(request):
  60. return request.GET.get('q')
  61. def is_printview(request):
  62. return 'printview' in request.GET
  63. def is_projectlistview(request):
  64. return request.META['PATH_INFO'].startswith(reverse('patt-projectlist'))
  65. def is_tasklistview(request, search_id=None):
  66. if request.META['PATH_INFO'].startswith(url_tasklist('patt-tasklist', search_id)):
  67. return True
  68. if search_id is None and get_search_query(request) is not None:
  69. return True
  70. return False