예제 #1
0
def tickets(page=1):
    form = SearchTicketForm()

    # get request arguments from the url
    status = request.args.get('status')
    department = request.args.get('department')
    category = request.args.get('category')
    content = request.args.get('content')
    user_id = request.args.get('user_id')

    if form.validate_on_submit():
        redirect_url = FlicketTicket.form_redirect(form,
                                                   url='flicket_bp.tickets')

        return redirect(redirect_url)

    ticket_query, form = FlicketTicket.query_tickets(form,
                                                     department=department,
                                                     category=category,
                                                     status=status,
                                                     user_id=user_id,
                                                     content=content)
    number_results = ticket_query.count()

    ticket_query = ticket_query.paginate(page, app.config['posts_per_page'])

    title = gettext('Tickets')

    # todo: pull from api on page load as other fields?
    if content:
        form.content.data = content

    return render_template('flicket_tickets.html',
                           title=title,
                           form=form,
                           tickets=ticket_query,
                           page=page,
                           number_results=number_results,
                           status=status,
                           department=department,
                           category=category,
                           user_id=user_id,
                           base_url='flicket_bp.tickets')
예제 #2
0
파일: tickets.py 프로젝트: xdml/flicket
def tickets_view(page, is_my_view=False):
    """
        Function common to 'tickets' and 'my_tickets' expect where query is filtered for users own tickets.
    """

    form = SearchTicketForm()

    # get request arguments from the url
    status = request.args.get('status')
    department = request.args.get('department')
    category = request.args.get('category')
    content = request.args.get('content')
    user_id = request.args.get('user_id')

    if form.validate_on_submit():
        redirect_url = FlicketTicket.form_redirect(form,
                                                   url='flicket_bp.tickets')

        return redirect(redirect_url)

    arg_sort = request.args.get('sort')
    if arg_sort:
        args = request.args.copy()
        del args['sort']

        response = make_response(
            redirect(url_for('flicket_bp.tickets', **args)))
        response.set_cookie('tickets_sort',
                            arg_sort,
                            max_age=2419200,
                            path=url_for('flicket_bp.tickets', **args))

        return response

    sort = request.cookies.get('tickets_sort')
    if sort:
        set_cookie = True
    else:
        sort = 'priority_desc'
        set_cookie = False

    ticket_query, form = FlicketTicket.query_tickets(form,
                                                     department=department,
                                                     category=category,
                                                     status=status,
                                                     user_id=user_id,
                                                     content=content)
    if is_my_view:
        ticket_query = FlicketTicket.my_tickets(ticket_query)
    ticket_query = FlicketTicket.sorted_tickets(ticket_query, sort)
    number_results = ticket_query.count()

    ticket_query = ticket_query.paginate(page, app.config['posts_per_page'])

    title = gettext('Tickets')
    if is_my_view:
        title = gettext('My Tickets')

    if content:
        form.content.data = content

    response = make_response(
        render_template('flicket_tickets.html',
                        title=title,
                        form=form,
                        tickets=ticket_query,
                        page=page,
                        number_results=number_results,
                        status=status,
                        department=department,
                        category=category,
                        user_id=user_id,
                        sort=sort,
                        base_url='flicket_bp.tickets'))

    if set_cookie:
        response.set_cookie('tickets_sort',
                            sort,
                            max_age=2419200,
                            path=url_for('flicket_bp.tickets'))

    return response
예제 #3
0
def tickets_view(page, is_my_view=False):
    """
    Function common to 'tickets' and 'my_tickets' expect where query is filtered for users own tickets.
    """

    form = SearchTicketForm()

    # get request arguments from the url
    status = request.args.get("status")
    institute = request.args.get("institute")
    domain = request.args.get("domain")
    content = request.args.get("content")
    requester = request.args.get("requester")
    referee = request.args.get("referee")
    user_id = request.args.get("user_id")
    requester_role = request.args.get("requester_role")
    request_stage = request.args.get("request_stage")
    procedure_stage = request.args.get("procedure_stage")

    if form.validate_on_submit():
        redirect_url = FlicketTicket.form_redirect(form,
                                                   url="flicket_bp.tickets")

        return redirect(redirect_url)

    arg_sort = request.args.get("sort")
    if arg_sort:
        print(arg_sort)
        args = request.args.copy()
        del args["sort"]

        response = make_response(
            redirect(url_for("flicket_bp.tickets", **args)))
        response.set_cookie(
            "tickets_sort",
            arg_sort,
            max_age=2419200,
            path=url_for("flicket_bp.tickets", **args),
        )

        return response

    sort = request.cookies.get("tickets_sort")
    if sort:
        set_cookie = True
    else:
        sort = "date_desc"
        set_cookie = False

    ticket_query, form = FlicketTicket.query_tickets(
        form,
        institute=institute,
        domain=domain,
        status=status,
        user_id=user_id,
        content=content,
        requester=requester,
        referee=referee,
        requester_role=requester_role,
        request_stage=request_stage,
        procedure_stage=procedure_stage,
    )
    if is_my_view:
        ticket_query = FlicketTicket.my_tickets(ticket_query)
    ticket_query = FlicketTicket.sorted_tickets(ticket_query, sort)
    number_results = ticket_query.count()

    ticket_query = ticket_query.paginate(page, app.config["posts_per_page"])

    title = gettext("Tickets")
    if is_my_view:
        title = gettext("My Tickets")

    if content:
        form.content.data = content
    if requester:
        form.requester.data = requester
    if referee:
        form.referee.data = referee

    response = make_response(
        render_template(
            "flicket_tickets.html",
            title=title,
            form=form,
            tickets=ticket_query,
            page=page,
            number_results=number_results,
            status=status,
            institute=institute,
            domain=domain,
            requester_role=requester_role,
            request_stage=request_stage,
            procedure_stage=procedure_stage,
            user_id=user_id,
            sort=sort,
            base_url="flicket_bp.tickets",
        ))

    if set_cookie:
        response.set_cookie("tickets_sort",
                            sort,
                            max_age=2419200,
                            path=url_for("flicket_bp.tickets"))

    return response
예제 #4
0
def tickets(page=1):

    form = SearchTicketForm()

    # get request arguments from the url
    status = request.args.get('status')
    department = request.args.get('department')
    category = request.args.get('category')
    content = request.args.get('content')
    user_id = request.args.get('user_id')

    if form.validate_on_submit():

        department = ''
        category = ''
        status = ''

        user = FlicketUser.query.filter_by(email=form.email.data).first()
        if user:
            user_id = user.id

        # convert form inputs to it's table title
        if form.department.data:
            department = FlicketDepartment.query.filter_by(
                id=form.department.data).first().department
        if form.category.data:
            category = FlicketCategory.query.filter_by(
                id=form.category.data).first().category
        if form.status.data:
            status = FlicketStatus.query.filter_by(
                id=form.status.data).first().status

        return redirect(
            url_for(
                'flicket_bp.tickets',
                content=form.content.data,
                page=page,
                department=department,
                category=category,
                status=status,
                user_id=user_id,
            ))

    # todo: get data from api

    tickets = FlicketTicket.query
    if status:
        tickets = tickets.filter(
            FlicketTicket.current_status.has(FlicketStatus.status == status))
        form.status.data = FlicketStatus.query.filter_by(
            status=status).first().id
    if category:
        tickets = tickets.filter(
            FlicketTicket.category.has(FlicketCategory.category == category))
        form.category.data = FlicketCategory.query.filter_by(
            category=category).first().id
    if department:
        department_filter = FlicketDepartment.query.filter_by(
            department=department).first()
        tickets = tickets.filter(
            FlicketTicket.category.has(
                FlicketCategory.department == department_filter))
        form.department.data = department_filter.id
    if user_id:
        tickets = tickets.filter_by(assigned_id=int(user_id))

    if content:
        # search the titles
        form.content.data = content

        f1 = FlicketTicket.title.ilike('%' + content + '%')
        f2 = FlicketTicket.content.ilike('%' + content + '%')
        f3 = FlicketTicket.posts.any(
            FlicketPost.content.ilike('%' + content + '%'))
        tickets = tickets.filter(f1 | f2 | f3)

    tickets = tickets.order_by(FlicketTicket.id.desc())
    number_results = tickets.count()

    tickets = tickets.paginate(page, app.config['posts_per_page'])

    return render_template('flicket_tickets.html',
                           title='Tickets',
                           form=form,
                           tickets=tickets,
                           page=page,
                           number_results=number_results,
                           status=status,
                           department=department,
                           category=category,
                           user_id=user_id)
예제 #5
0
def tickets(page=1):
    form = SearchTicketForm()

    # get request arguments from the url
    status = request.args.get('status')
    department = request.args.get('department')
    category = request.args.get('category')
    content = request.args.get('content')
    user_id = request.args.get('user_id')

    if form.validate_on_submit():
        redirect_url = FlicketTicket.form_redirect(form,
                                                   url='flicket_bp.tickets')

        return redirect(redirect_url)

    sort = request.args.get('sort')
    if sort:
        args = request.args.copy()
        del args['sort']

        response = make_response(
            redirect(url_for('flicket_bp.tickets', **args)))
        response.set_cookie('tickets_sort',
                            sort,
                            max_age=2419200,
                            path=url_for('flicket_bp.tickets'))

        return response

    sort = request.cookies.get('tickets_sort')
    if sort:
        set_cookie = True
    else:
        sort = 'priority_desc'
        set_cookie = False

    ticket_query, form = FlicketTicket.query_tickets(form,
                                                     department=department,
                                                     category=category,
                                                     status=status,
                                                     user_id=user_id,
                                                     content=content)
    ticket_query = FlicketTicket.sorted_tickets(ticket_query, sort)
    number_results = ticket_query.count()

    ticket_query = ticket_query.paginate(page, app.config['posts_per_page'])

    title = gettext('Tickets')

    # todo: pull from api on page load as other fields?
    if content:
        form.content.data = content

    response = make_response(
        render_template('flicket_tickets.html',
                        title=title,
                        form=form,
                        tickets=ticket_query,
                        page=page,
                        number_results=number_results,
                        status=status,
                        department=department,
                        category=category,
                        user_id=user_id,
                        sort=sort,
                        base_url='flicket_bp.tickets'))

    if set_cookie:
        response.set_cookie('tickets_sort',
                            sort,
                            max_age=2419200,
                            path=url_for('flicket_bp.tickets'))

    return response