def pagination(self): sortable_columns = [ "agency_name", "abbreviation", "toptier_code", "current_total_budget_authority_amount", "publication_date", ] default_sort_column = "current_total_budget_authority_amount" models = customize_pagination_with_sort_columns(sortable_columns, default_sort_column) models.extend([{"key": "fiscal_year", "name": "fiscal_year", "type": "integer", "optional": False}]) if self.request.query_params.get("sort") and "publication_date" in self.request.query_params.get("sort"): modified_query_params = deepcopy(self.request.query_params) modified_query_params.pop("sort") request_data = TinyShield(models).block(modified_query_params) request_data["sort"] = self.request.query_params.get("sort") else: request_data = TinyShield(models).block(self.request.query_params) # since publication_date requires a variable that we can't check for using the enum check, we're doing it separately return Pagination( page=request_data["page"], limit=request_data["limit"], lower_limit=(request_data["page"] - 1) * request_data["limit"], upper_limit=(request_data["page"] * request_data["limit"]), sort_key=request_data.get("sort", default_sort_column), sort_order=request_data["order"], )
def pagination(self): model = customize_pagination_with_sort_columns( self.sortable_columns, self.default_sort_column) request_data = TinyShield(model).block(self.request.query_params) return Pagination( page=request_data["page"], limit=request_data["limit"], lower_limit=(request_data["page"] - 1) * request_data["limit"], upper_limit=(request_data["page"] * request_data["limit"]), sort_key=request_data.get("sort", self.default_sort_column), sort_order=request_data["order"], )
def run_models(self, columns, default_sort_column="id"): model = customize_pagination_with_sort_columns(columns, default_sort_column) request_data = TinyShield(model).block(self.request.data.get("pagination", {})) return Pagination( page=request_data["page"], limit=request_data["limit"], lower_limit=(request_data["page"] - 1) * request_data["limit"], upper_limit=(request_data["page"] * request_data["limit"]), sort_key=request_data.get("sort", "obligation"), sort_order=request_data["order"], secondary_sort_key="id", )
def pagination(self): sortable_columns = ["name", "obligated_amount", "gross_outlay_amount"] default_sort_column = "obligated_amount" model = customize_pagination_with_sort_columns(sortable_columns, default_sort_column) request_data = TinyShield(model).block(self.request.query_params) return Pagination( page=request_data["page"], limit=request_data["limit"], lower_limit=(request_data["page"] - 1) * request_data["limit"], upper_limit=(request_data["page"] * request_data["limit"]), sort_key=request_data.get("sort", "obligated_amount"), sort_order=request_data["order"], )
def __init__(self): models = customize_pagination_with_sort_columns( list(TransactionViewSet.transaction_lookup.keys()), "action_date") models.extend([ get_internal_or_generated_award_id_model(), { "key": "idv", "name": "idv", "type": "boolean", "default": True, "optional": True }, ]) self._tiny_shield_models = update_model_in_list(model_list=models, model_name="limit", new_dict={"max": 5000}) super(TransactionViewSet, self).__init__()
def _parse_and_validate_request(request_dict) -> dict: sortable_columns = [ "difference", "file_a_obligation", "file_b_obligation", "tas" ] default_sort_column = "tas" models = customize_pagination_with_sort_columns( sortable_columns, default_sort_column) models.extend([ { "key": "fiscal_year", "name": "fiscal_year", "type": "integer", "optional": False }, { "key": "fiscal_period", "name": "fiscal_period", "type": "integer", "optional": False }, ]) validated_request_data = TinyShield(models).block(request_dict) return validated_request_data