123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- from django.urls.base import reverse
- from django.utils.translation import gettext as _
-
-
- def back_url(request, addition):
- return request.path + addition
-
-
- def url_current(request):
- return request.GET.get('next', request.get_full_path())
-
-
- def url_tasklist(request, user_filter_id=None, search_txt=None, common_filter_id=None):
- if user_filter_id is not None:
- return reverse('patt-userfilter', kwargs={'user_filter_id': user_filter_id})
- elif search_txt is not None:
- return reverse('search') + '?q=%s' % search_txt
- elif common_filter_id is not None:
- return reverse('patt-commonfilter', kwargs={'common_filter_id': common_filter_id})
- else:
- return reverse('patt-tasklist')
-
-
- def url_projectlist(request):
- return reverse('patt-projectlist')
-
-
- def url_helpview(request, page):
- return reverse('patt-helpview', kwargs={'page': page})
-
-
- def url_tasknew(request, project_id):
- nxt = url_current(request)
- return reverse('patt-tasknew') + '?next=%s' % nxt + ('&project_id=%s' % project_id if project_id is not None else '')
-
-
- def url_projectnew(request):
- nxt = url_current(request)
- return reverse('patt-projectnew') + '?next=%s' % nxt
-
-
- def url_taskedit(request, task_id):
- nxt = url_current(request)
- return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=edit&next=%s' % nxt
-
-
- def url_projectedit(request, project_id):
- nxt = url_current(request)
- return reverse('patt-projectedit', kwargs={'project_id': project_id}) + '?next=%s' % nxt
-
-
- def url_commentnew(request, task_id):
- nxt = url_current(request)
- return reverse('patt-commentnew', kwargs={'task_id': task_id}) + '?next=%s' % nxt
-
-
- def url_easysearch(request):
- return reverse('patt-easysearch')
-
-
- def url_taskset(request, task_id, **kwargs):
- nxt = url_current(request)
- if kwargs.get('priority') is not None:
- return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=set_priority&priority=%s&next=%s' % (kwargs.get('priority'), nxt)
- elif kwargs.get('state') is not None:
- return reverse('patt-taskedit', kwargs={'task_id': task_id}) + '?do=set_state&state=%s&next=%s' % (kwargs.get('state'), nxt)
- else:
- raise Exception('Required keyword missing. One of "priority", "state" is not in %s.' % repr(kwargs.keys()))
-
-
- def url_filteredit(request, search_id=None):
- if search_id is None:
- if get_search_query(request) is None:
- return reverse('patt-filternew')
- else:
- return reverse('patt-filternew') + '?q=%s' % get_search_query(request)
- else:
- return reverse('patt-filteredit', kwargs={'search_id': search_id})
-
-
- def url_printview(request):
- if not is_printview(request):
- search_query = get_search_query(request)
- return '?printview' + ('&q=%s' % search_query) if search_query is not None else ''
- else:
- return request.path
-
-
- def get_search_query(request):
- return request.GET.get('q')
-
-
- def is_printview(request):
- return 'printview' in request.GET
-
-
- def is_projectlistview(request):
- return request.META['PATH_INFO'].startswith(reverse('patt-projectlist'))
-
-
- def is_tasklistview(request, search_id=None):
- if request.META['PATH_INFO'].startswith(url_tasklist('patt-tasklist', search_id)):
- return True
- if search_id is None and get_search_query(request) is not None:
- return True
- return False
|