Django Library PaTT
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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_profile(request):
  17. return reverse('patt-profile')
  18. def url_projectlist(request):
  19. return reverse('patt-projectlist')
  20. def url_helpview(request, page):
  21. return reverse('patt-helpview', kwargs={'page': page})
  22. def url_tasknew(request, project_id):
  23. nxt = url_current(request)
  24. return reverse('patt-tasknew') + '?next=%s' % nxt + ('&project_id=%s' % project_id if project_id is not None else '')
  25. def url_projectnew(request):
  26. nxt = url_current(request)
  27. return reverse('patt-projectnew') + '?next=%s' % nxt
  28. def url_taskedit(request, task_id):
  29. nxt = url_current(request)
  30. return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=edit&next=%s' % nxt
  31. def url_projectedit(request, project_id):
  32. nxt = url_current(request)
  33. return reverse('patt-projectedit', kwargs={'project_id': project_id}) + '?next=%s' % nxt
  34. def url_commentnew(request, task_id):
  35. nxt = url_current(request)
  36. return reverse('patt-commentnew', kwargs={'task_id': task_id}) + '?next=%s' % nxt
  37. def url_easysearch(request):
  38. return reverse('patt-easysearch')
  39. def url_taskset(request, task_id, **kwargs):
  40. nxt = url_current(request)
  41. if kwargs.get('priority') is not None:
  42. return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=set_priority&priority=%s&next=%s' % (kwargs.get('priority'), nxt)
  43. elif kwargs.get('state') is not None:
  44. return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=set_state&state=%s&next=%s' % (kwargs.get('state'), nxt)
  45. else:
  46. raise Exception('Required keyword missing. One of "priority", "state" is not in %s.' % repr(kwargs.keys()))
  47. def url_filteredit(request, search_id=None):
  48. if search_id is None:
  49. if get_search_query(request) is None:
  50. return reverse('patt-filternew')
  51. else:
  52. return reverse('patt-filternew') + '?q=%s' % get_search_query(request)
  53. else:
  54. return reverse('patt-filteredit', kwargs={'search_id': search_id})
  55. def url_printview(request):
  56. if not is_printview(request):
  57. search_query = get_search_query(request)
  58. return '?printview' + (('&q=%s' % search_query) if search_query is not None else '')
  59. else:
  60. return request.path
  61. def get_search_query(request):
  62. return request.GET.get('q')
  63. def is_printview(request):
  64. return 'printview' in request.GET
  65. def is_projectlistview(request):
  66. return request.META['PATH_INFO'].startswith(reverse('patt-projectlist'))
  67. def is_tasklistview(request, search_id=None):
  68. if request.META['PATH_INFO'].startswith(url_tasklist('patt-tasklist', search_id)):
  69. return True
  70. if search_id is None and get_search_query(request) is not None:
  71. return True
  72. return False