def fetch_requests(output_results_only = False, filters_map = None, date_format = '%Y-%m-%d', checkbox_value = 'on'): user_id = get_user_id() if not filters_map: if request.args: if is_supported_browser(): return backbone_requests() else: # Clear URL filters_map = request.args else: filters_map = request.form # Set defaults is_open = checkbox_value is_closed = None due_soon = checkbox_value overdue = checkbox_value mine_as_poc = checkbox_value mine_as_helper = checkbox_value departments_selected = [] sort_column = "id" sort_direction = "asc" min_due_date = None max_due_date = None min_date_received = None max_date_received = None requester_name = None page_number = 1 search_term = None if filters_map: departments_selected = get_filter_value(filters_map = filters_map, filter_name = 'departments_selected', is_list = True) or get_filter_value(filters_map, 'department') is_open = get_filter_value(filters_map = filters_map, filter_name = 'is_open', is_boolean = True) is_closed = get_filter_value(filters_map = filters_map, filter_name = 'is_closed', is_boolean = True) due_soon = get_filter_value(filters_map = filters_map, filter_name = 'due_soon', is_boolean = True) overdue = get_filter_value(filters_map = filters_map, filter_name = 'overdue', is_boolean = True) mine_as_poc = get_filter_value(filters_map = filters_map, filter_name = 'mine_as_poc', is_boolean = True) mine_as_helper = get_filter_value(filters_map = filters_map, filter_name = 'mine_as_helper', is_boolean = True) sort_column = get_filter_value(filters_map, 'sort_column') or 'id' sort_direction = get_filter_value(filters_map, 'sort_direction') or 'asc' search_term = get_filter_value(filters_map, 'search_term') min_due_date = get_filter_value(filters_map, 'min_due_date') max_due_date = get_filter_value(filters_map, 'max_due_date') min_date_received = get_filter_value(filters_map, 'min_date_received') max_date_received = get_filter_value(filters_map, 'max_date_received') requester_name = get_filter_value(filters_map, 'requester_name') page_number = int(get_filter_value(filters_map, 'page_number') or '1') results = get_results_by_filters(departments_selected = departments_selected, is_open = is_open, is_closed = is_closed, due_soon = due_soon, overdue = overdue, mine_as_poc = mine_as_poc, mine_as_helper = mine_as_helper, sort_column = sort_column, sort_direction = sort_direction, search_term = search_term, min_due_date = min_due_date, max_due_date = max_due_date, min_date_received = min_date_received, max_date_received = max_date_received, requester_name = requester_name, page_number = page_number, user_id = user_id, date_format = date_format, checkbox_value = checkbox_value) # Execute query limit = 15 offset = limit * (page_number - 1) app.logger.info("Page Number: {0}, Limit: {1}, Offset: {2}".format(page_number, limit, offset)) more_results = False num_results = results.count() start_index = 0 end_index = 0 if num_results != 0: start_index = (page_number - 1) * limit if start_index == 0: start_index = 1 if num_results > (limit * page_number): more_results = True end_index = start_index + 14 else: end_index = num_results results = results.limit(limit).offset(offset).all() requests = prepare_request_fields(results = results) if output_results_only == True: return requests, num_results, more_results, start_index, end_index template = "all_requests_less_js.html" if is_supported_browser(): template = "all_requests.html" return render_template(template, total_requests_count = get_count("Request"), requests = requests, departments = db.session.query(models.Department).all(), departments_selected = departments_selected, is_open = is_open, is_closed = is_closed, due_soon = due_soon, overdue = overdue, mine_as_poc = mine_as_poc, mine_as_helper = mine_as_helper, sort_column = sort_column, sort_direction = sort_direction, search_term = search_term, min_due_date = min_due_date, max_due_date = max_due_date, min_date_received = min_date_received, max_date_received = max_date_received, requester_name = requester_name, page_number = page_number, more_results = more_results, num_results = num_results, start_index = start_index, end_index = end_index)
def fetch_requests(output_results_only=False, filters_map=None, date_format='%Y-%m-%d', checkbox_value='on'): user_id = get_user_id() if not filters_map: if request.args: if is_supported_browser(): return backbone_requests() else: # Clear URL filters_map = request.args else: filters_map = request.form # Set defaults is_open = checkbox_value is_closed = None due_soon = checkbox_value overdue = checkbox_value mine_as_poc = checkbox_value mine_as_helper = checkbox_value departments_selected = [] sort_column = "id" sort_direction = "asc" min_due_date = None max_due_date = None min_date_received = None max_date_received = None requester_name = None page_number = 1 search_term = None if filters_map: departments_selected = get_filter_value( filters_map=filters_map, filter_name='departments_selected', is_list=True) or get_filter_value(filters_map, 'department') is_open = get_filter_value(filters_map=filters_map, filter_name='is_open', is_boolean=True) is_closed = get_filter_value(filters_map=filters_map, filter_name='is_closed', is_boolean=True) due_soon = get_filter_value(filters_map=filters_map, filter_name='due_soon', is_boolean=True) overdue = get_filter_value(filters_map=filters_map, filter_name='overdue', is_boolean=True) mine_as_poc = get_filter_value(filters_map=filters_map, filter_name='mine_as_poc', is_boolean=True) mine_as_helper = get_filter_value(filters_map=filters_map, filter_name='mine_as_helper', is_boolean=True) sort_column = get_filter_value(filters_map, 'sort_column') or 'id' sort_direction = get_filter_value(filters_map, 'sort_direction') or 'asc' search_term = get_filter_value(filters_map, 'search_term') min_due_date = get_filter_value(filters_map, 'min_due_date') max_due_date = get_filter_value(filters_map, 'max_due_date') min_date_received = get_filter_value(filters_map, 'min_date_received') max_date_received = get_filter_value(filters_map, 'max_date_received') requester_name = get_filter_value(filters_map, 'requester_name') page_number = int(get_filter_value(filters_map, 'page_number') or '1') results = get_results_by_filters(departments_selected=departments_selected, is_open=is_open, is_closed=is_closed, due_soon=due_soon, overdue=overdue, mine_as_poc=mine_as_poc, mine_as_helper=mine_as_helper, sort_column=sort_column, sort_direction=sort_direction, search_term=search_term, min_due_date=min_due_date, max_due_date=max_due_date, min_date_received=min_date_received, max_date_received=max_date_received, requester_name=requester_name, page_number=page_number, user_id=user_id, date_format=date_format, checkbox_value=checkbox_value) # Execute query limit = 15 offset = limit * (page_number - 1) app.logger.info("Page Number: {0}, Limit: {1}, Offset: {2}".format( page_number, limit, offset)) more_results = False num_results = results.count() start_index = 0 end_index = 0 if num_results != 0: start_index = (page_number - 1) * limit if start_index == 0: start_index = 1 if num_results > (limit * page_number): more_results = True end_index = start_index + 14 else: end_index = num_results results = results.limit(limit).offset(offset).all() requests = prepare_request_fields(results=results) if output_results_only == True: return requests, num_results, more_results, start_index, end_index template = "all_requests_less_js.html" if is_supported_browser(): template = "all_requests.html" return render_template(template, total_requests_count=get_count("Request"), requests=requests, departments=db.session.query( models.Department).all(), departments_selected=departments_selected, is_open=is_open, is_closed=is_closed, due_soon=due_soon, overdue=overdue, mine_as_poc=mine_as_poc, mine_as_helper=mine_as_helper, sort_column=sort_column, sort_direction=sort_direction, search_term=search_term, min_due_date=min_due_date, max_due_date=max_due_date, min_date_received=min_date_received, max_date_received=max_date_received, requester_name=requester_name, page_number=page_number, more_results=more_results, num_results=num_results, start_index=start_index, end_index=end_index)
def backbone_requests(): return render_template("all_requests.html", departments = db.session.query(models.Department).all(), total_requests_count = get_count("Request"))
def backbone_requests(): return render_template("all_requests.html", departments=db.session.query( models.Department).all(), total_requests_count=get_count("Request"))