def post(self, request): """Returns boolean of whether a download request is greater than the max limit. """ models = [ { 'name': 'subawards', 'key': 'subawards', 'type': 'boolean', 'default': False }, ] models.extend(copy.deepcopy(AWARD_FILTER)) json_request = TinyShield(models).block(request.data) # If no filters in request return empty object to return all transactions filters = json_request.get('filters', {}) is_over_limit = False if json_request['subawards']: total_count = subaward_filter(filters).count() else: queryset, model = download_transaction_count(filters) if model in ['UniversalTransactionView']: total_count = queryset.count() else: # "summary" materialized views are pre-aggregated and contain a counts col total_count = queryset.aggregate( total_count=Sum('counts'))['total_count'] if total_count and total_count > settings.MAX_DOWNLOAD_LIMIT: is_over_limit = True result = {"transaction_rows_gt_limit": is_over_limit} return Response(result)
def post(self, request): """Returns boolean of whether a download request is greater than the max limit. """ models = [ {'name': 'subawards', 'key': 'subawards', 'type': 'boolean', 'default': False}, ] models.extend(copy.deepcopy(AWARD_FILTER)) json_request = TinyShield(models).block(request.data) # If no filters in request return empty object to return all transactions filters = json_request.get('filters', {}) is_over_limit = False if json_request['subawards']: total_count = subaward_filter(filters).count() else: queryset, model = download_transaction_count(filters) if model in ['UniversalTransactionView']: total_count = queryset.count() else: # "summary" materialized views are pre-aggregated and contain a counts col total_count = queryset.aggregate(total_count=Sum('counts'))['total_count'] if total_count and total_count > settings.MAX_DOWNLOAD_LIMIT: is_over_limit = True result = { "transaction_rows_gt_limit": is_over_limit } return Response(result)
def post(self, request): """Returns boolean of whether a download request is greater than the max limit. """ models = [{ "name": "subawards", "key": "subawards", "type": "boolean", "default": False }] models.extend(copy.deepcopy(AWARD_FILTER)) self.original_filters = request.data.get("filters") json_request = TinyShield(models).block(request.data) # If no filters in request return empty object to return all transactions filters = json_request.get("filters", {}) if json_request["subawards"]: total_count = subaward_filter(filters).count() else: queryset, model = download_transaction_count(filters) if model in ["UniversalTransactionView"]: total_count = queryset.count() else: # "summary" materialized views are pre-aggregated and contain a counts col total_count = queryset.aggregate( total_count=Sum("counts"))["total_count"] if total_count is None: total_count = 0 result = { "calculated_transaction_count": total_count, "maximum_transaction_limit": settings.MAX_DOWNLOAD_LIMIT, "transaction_rows_gt_limit": total_count > settings.MAX_DOWNLOAD_LIMIT, "messages": [ get_generic_filters_message( self.original_filters.keys(), [elem["name"] for elem in AWARD_FILTER]) ], } return Response(result)
def post(self, request): """Returns boolean of whether a download request is greater than the max limit. """ json_request = request.data # If no filters in request return empty object to return all transactions filters = json_request.get('filters', {}) is_over_limit = False queryset, model = download_transaction_count(filters) if model in ['UniversalTransactionView']: total_count = queryset.count() else: # "summary" materialized views are pre-aggregated and contain a counts col total_count = queryset.aggregate( total_count=Sum('counts'))['total_count'] if total_count and total_count > settings.MAX_DOWNLOAD_LIMIT: is_over_limit = True result = {"transaction_rows_gt_limit": is_over_limit} return Response(result)