def my_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, page, url='flicket_bp.my_tickets') return redirect(redirect_url) ticket_query, form = FlicketTicket.query_tickets(form, department=department, category=category, status=status, user_id=user_id, content=content) ticket_query = FlicketTicket.my_tickets(ticket_query) number_results = ticket_query.count() ticket_query = ticket_query.paginate(page, app.config['posts_per_page']) title = gettext('My Tickets') 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.my_tickets')
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
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