Exemplo n.º 1
0
def search(request):
    searchable_fields = settings.TICKET_SEARCH_FIELDS

    if request.method == 'POST' and 'reportname' in request.POST and request.POST['reportname']:
        rep = tickets_reports()
        rep.name = request.POST['reportname']
        rep.search = json.dumps(request.session['last_search'], cls=DjangoJSONEncoder)
        rep.save(user=request.user)

        request.session['last_search'] = convert_sarch(clean_search_values(request.session['last_search']))
        request.session['last_search_caption'] = request.POST['reportname']

        return table(request, search=request.session['last_search'], list_caption=request.session['last_search_caption'])

    if request.method == 'POST':
        form = SearchForm(request.POST, include_list=searchable_fields, is_stuff=request.user.is_staff, user=request.user, customer=request.organisation.id)
        form.is_valid()
        request.session['last_search'] = convert_sarch(clean_search_values(form.cleaned_data))
        request.session['last_search_caption'] = ''

        return table(request, search=request.session['last_search'])

    if 'last_search' in request.session and 'new' not in request.GET:
        return table(request, search=request.session['last_search'], list_caption=request.session.get('last_search_caption', ''))

    return HttpResponseRedirect('/tickets/search/extended/')
Exemplo n.º 2
0
def search(request):
    searchable_fields = settings.TICKET_SEARCH_FIELDS

    if request.method == 'POST' and 'reportname' in request.POST and request.POST['reportname']:
        rep = tickets_reports()
        rep.name = request.POST['reportname']
        rep.search = json.dumps(request.session['last_search'], cls=DjangoJSONEncoder)
        rep.save(user=request.user)

        request.session['last_search'] = convert_sarch(clean_search_values(request.session['last_search']))
        request.session['last_search_caption'] = request.POST['reportname']

        return table(request, search=request.session['last_search'], list_caption=request.session['last_search_caption'])

    if request.method == 'POST':
        form = SearchForm(request.POST, include_list=searchable_fields, is_stuff=request.user.is_staff, user=request.user, customer=request.organisation.id)
        form.is_valid()
        request.session['last_search'] = convert_sarch(clean_search_values(form.cleaned_data))
        request.session['last_search_caption'] = ''

        return table(request, search=request.session['last_search'])

    if 'last_search' in request.session and 'new' not in request.GET:
        return table(request, search=request.session['last_search'], list_caption=request.session.get('last_search_caption', ''))

    return HttpResponseRedirect('/tickets/search/extended/')
Exemplo n.º 3
0
def convertOldStyleSearch(apps, schema_editor):
    reports = apps.get_model('yats', 'tickets_reports')
    for rep in reports.objects.all():
        search = json.loads(rep.search)
        rep.search = json.dumps(convert_sarch(clean_search_values(search)),
                                cls=DjangoJSONEncoder)
        rep.save()
Exemplo n.º 4
0
def convertOldStyleSearch(apps, schema_editor):
    boards = apps.get_model('yats', 'boards')
    for board in boards.objects.all():
        if board.columns:
            columns = json.loads(board.columns)
            for column in columns:
                search = column['query']
                column['query'] = convert_sarch(clean_search_values(search))

            board.columns = json.dumps(columns, cls=DjangoJSONEncoder)
            board.save()
Exemplo n.º 5
0
def convertOldStyleSearch(apps, schema_editor):
    boards = apps.get_model('yats', 'boards')
    for board in boards.objects.all():
        if board.columns:
            columns = json.loads(board.columns)
            for column in columns:
                search = column['query']
                column['query'] = convert_sarch(clean_search_values(search))

            board.columns = json.dumps(columns, cls=DjangoJSONEncoder)
            board.save()
Exemplo n.º 6
0
def kanban(request):
    flows = ticket_flow.objects.all().order_by('type')
    columns = []
    finish_state = -1
    days = UserProfile.objects.get(user=request.user).day_since_closed_tickets

    query = get_ticket_model().objects.select_related('type', 'state', 'assigned', 'priority', 'customer').all()

    for flow in flows:
        search_params, flow.data = build_ticket_search_ext(request, query, convert_sarch({'state': flow.pk}))
        flow.data = flow.data.filter(Q(show_start=None) | Q(show_start__lte=timezone.now()))

        if flow.type == 2:
            flow.data = flow.data.filter(Q(assigned=None) | Q(assigned=request.user)).order_by('-close_date')
        else:
            flow.data = flow.data.filter(Q(assigned=None) | Q(assigned=request.user)).extra(select={'prio': 'COALESCE(caldav, 10)'}, order_by=['prio', '-c_date'])

        if flow.type == 1:
            columns.insert(0, flow)
        else:
            columns.append(flow)
            if flow.type == 2:
                finish_state = flow.pk
                flow.data = flow.data.filter(close_date__gte=datetime.date.today() - datetime.timedelta(days=days))

        seen_elements = {}
        seen = tickets_participants.objects.filter(user=request.user, ticket__in=flow.data.values_list('id', flat=True)).values_list('ticket_id', 'seen')
        for see in seen:
            seen_elements[see[0]] = see[1]

        seen = tickets_ignorants.objects.filter(user=request.user, ticket__in=flow.data.values_list('id', flat=True)).values_list('ticket_id')
        for see in seen:
            seen_elements[see[0]] = True

        flow.seen = seen_elements

    close = TicketCloseForm()
    reassign = TicketReassignForm()
    edges = ticket_flow_edges.objects.all().order_by('now')
    add_breadcrumbs(request, 0, 'k')
    cur_language = translation.get_language()
    return render(request, 'board/kanban.html', {'layout': 'horizontal', 'columns': columns, 'edges': edges, 'finish_state': finish_state, 'close': close, 'reassign': reassign, 'cur_language': cur_language})
Exemplo n.º 7
0
def table(request, **kwargs):
    def pretty_condition(condition):
        if condition == 'AND':
            return _('AND')
        else:
            return _('OR')

    def pretty_operator(operator):
        if operator == 'is_null':
            return _('is null')
        elif operator == 'is_not_null':
            return _('is not null')
        elif operator == 'equal':
            return _('equal')
        elif operator == 'not_equal':
            return _('not equal')
        elif operator == 'begins_with':
            return _('begins with')
        elif operator == 'not_begins_with':
            return _('not begins with')
        elif operator == 'contains':
            return _('contains')
        elif operator == 'not_contains':
            return _('not contains')
        elif operator == 'ends_with':
            return _('ends with')
        elif operator == 'not_ends_with':
            return _('not ends with')
        elif operator == 'is_empty':
            return _('is empty')
        elif operator == 'is_not_empty':
            return _('is not empty')
        elif operator == 'less_or_equal':
            return _('less or equal')
        elif operator == 'less':
            return _('less')
        elif operator == 'greater_or_equal':
            return _('greater or equal')
        elif operator == 'greater':
            return _('greater')
        elif operator == 'between':
            return _('between')
        elif operator == 'not_between':
            return _('not between')

        return operator

    def pretty_value(value):
        if value is None:
            return ''
        if isinstance(value, (bool)):
            if value:
                return _('yes')
            else:
                return _('no')
        return unicode(value)

    def formatQuery(rules, condition):
        result = '('
        for rule in rules:
            if 'rules' in rule:
                result = (
                    '%s %s %s' %
                    (result, pretty_condition(condition),
                     formatQuery(rule['rules'], rule['condition']))).strip()
                continue

            param = ('%s %s %s' %
                     (rule['label'], pretty_operator(rule['operator']),
                      pretty_value(rule['value']))).strip()
            if result != '(':
                result = '%s %s %s' % (result, pretty_condition(condition),
                                       param)
            else:
                result = ('%s%s' % (result, param)).strip()

        return '%s)' % result

    tic = get_ticket_model().objects.select_related('type').all()

    if 'search' in kwargs:
        is_search = True
        search_params, tic = build_ticket_search_ext(request, tic,
                                                     kwargs['search'])

    else:
        tic = tic.filter(closed=False).order_by('-id')
        search_params = convert_sarch({'closed': False})
        is_search = False

    list_caption = kwargs.get('list_caption')
    if 'report' in request.GET:
        list_caption = tickets_reports.objects.get(
            pk=request.GET['report']).name

    paginator = Paginator(tic, 20)
    page = request.GET.get('page')
    try:
        tic_lines = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        tic_lines = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        tic_lines = paginator.page(paginator.num_pages)

    board_form = AddToBordForm()
    board_form.fields['board'].queryset = board_form.fields[
        'board'].queryset.filter(c_user=request.user)
    pretty_params = prettyValues(copy.deepcopy(search_params))
    pretty_query = formatQuery(pretty_params['rules'],
                               pretty_params['condition'])
    return render(
        request, 'tickets/list.html', {
            'lines': tic_lines,
            'is_search': is_search,
            'search_params': pretty_params,
            'list_caption': list_caption,
            'board_form': board_form,
            'query': json.dumps(search_params),
            'sql': tic.query,
            'pretty_query': pretty_query
        })
Exemplo n.º 8
0
def kanban(request):
    flows = ticket_flow.objects.all().order_by('type')
    columns = []
    finish_state = -1
    days = UserProfile.objects.get(user=request.user).day_since_closed_tickets

    query = get_ticket_model().objects.select_related('type', 'state',
                                                      'assigned', 'priority',
                                                      'customer').all()

    for flow in flows:
        search_params, flow.data = build_ticket_search_ext(
            request, query, convert_sarch({'state': flow.pk}))
        flow.data = flow.data.filter(
            Q(show_start=None) | Q(show_start__lte=timezone.now()))

        if flow.type == 2:
            flow.data = flow.data.filter(
                Q(assigned=None)
                | Q(assigned=request.user)).order_by('-close_date')
        else:
            flow.data = flow.data.filter(
                Q(assigned=None) | Q(assigned=request.user)).extra(
                    select={'prio': 'COALESCE(caldav, 10)'},
                    order_by=['prio', '-c_date'])

        if flow.type == 1:
            columns.insert(0, flow)
        else:
            columns.append(flow)
            if flow.type == 2:
                finish_state = flow.pk
                flow.data = flow.data.filter(
                    close_date__gte=datetime.date.today() -
                    datetime.timedelta(days=days))

        seen_elements = {}
        seen = tickets_participants.objects.filter(
            user=request.user,
            ticket__in=flow.data.values_list('id', flat=True)).values_list(
                'ticket_id', 'seen')
        for see in seen:
            seen_elements[see[0]] = see[1]

        seen = tickets_ignorants.objects.filter(
            user=request.user,
            ticket__in=flow.data.values_list(
                'id', flat=True)).values_list('ticket_id')
        for see in seen:
            seen_elements[see[0]] = True

        flow.seen = seen_elements

    close = TicketCloseForm()
    reassign = TicketReassignForm()
    edges = ticket_flow_edges.objects.all().order_by('now')
    add_breadcrumbs(request, 0, 'k')
    cur_language = translation.get_language()
    return render(
        request, 'board/kanban.html', {
            'layout': 'horizontal',
            'columns': columns,
            'edges': edges,
            'finish_state': finish_state,
            'close': close,
            'reassign': reassign,
            'cur_language': cur_language
        })
Exemplo n.º 9
0
def table(request, **kwargs):
    def pretty_condition(condition):
        if condition == 'AND':
            return _('AND')
        else:
            return _('OR')

    def pretty_operator(operator):
        if operator == 'is_null':
            return _('is null')
        elif operator == 'is_not_null':
            return _('is not null')
        elif operator == 'equal':
            return _('equal')
        elif operator == 'not_equal':
            return _('not equal')
        elif operator == 'begins_with':
            return _('begins with')
        elif operator == 'not_begins_with':
            return _('not begins with')
        elif operator == 'contains':
            return _('contains')
        elif operator == 'not_contains':
            return _('not contains')
        elif operator == 'ends_with':
            return _('ends with')
        elif operator == 'not_ends_with':
            return _('not ends with')
        elif operator == 'is_empty':
            return _('is empty')
        elif operator == 'is_not_empty':
            return _('is not empty')
        elif operator == 'less_or_equal':
            return _('less or equal')
        elif operator == 'less':
            return _('less')
        elif operator == 'greater_or_equal':
            return _('greater or equal')
        elif operator == 'greater':
            return _('greater')
        elif operator == 'between':
            return _('between')
        elif operator == 'not_between':
            return _('not between')

        return operator

    def pretty_value(value):
        if value is None:
            return ''
        if isinstance(value, (bool)):
            if value:
                return _('yes')
            else:
                return _('no')
        return unicode(value)

    def formatQuery(rules, condition):
        result = '('
        for rule in rules:
            if 'rules' in rule:
                result = ('%s %s %s' % (result, pretty_condition(condition), formatQuery(rule['rules'], rule['condition']))).strip()
                continue

            param = ('%s %s %s' % (rule['label'], pretty_operator(rule['operator']), pretty_value(rule['value']))).strip()
            if result != '(':
                result = '%s %s %s' % (result, pretty_condition(condition), param)
            else:
                result = ('%s%s' % (result, param)).strip()

        return '%s)' % result

    tic = get_ticket_model().objects.select_related('type').all()

    if 'search' in kwargs:
        is_search = True
        search_params, tic = build_ticket_search_ext(request, tic, kwargs['search'])

    else:
        tic = tic.filter(closed=False).order_by('-id')
        search_params = convert_sarch({'closed':False})
        is_search = False

    list_caption = kwargs.get('list_caption')
    if 'report' in request.GET:
        list_caption = tickets_reports.objects.get(pk=request.GET['report']).name

    paginator = Paginator(tic, 20)
    page = request.GET.get('page')
    try:
        tic_lines = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        tic_lines = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        tic_lines = paginator.page(paginator.num_pages)

    board_form = AddToBordForm()
    board_form.fields['board'].queryset = board_form.fields['board'].queryset.filter(c_user=request.user)
    pretty_params = prettyValues(copy.deepcopy(search_params))
    pretty_query = formatQuery(pretty_params['rules'], pretty_params['condition'])
    return render(request, 'tickets/list.html', {'lines': tic_lines, 'is_search': is_search, 'search_params': pretty_params, 'list_caption': list_caption, 'board_form': board_form, 'query': json.dumps(search_params), 'sql': tic.query, 'pretty_query': pretty_query})
Exemplo n.º 10
0
def convertOldStyleSearch(apps, schema_editor):
    reports = apps.get_model('yats', 'tickets_reports')
    for rep in reports.objects.all():
        search = json.loads(rep.search)
        rep.search = json.dumps(convert_sarch(clean_search_values(search)), cls=DjangoJSONEncoder)
        rep.save()