Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
- [x] Rename GET parameters
Browse files Browse the repository at this point in the history
- [x] Transform country_code to uppercase before filtering
  • Loading branch information
KushalRaj committed Jul 22, 2021
1 parent 5efc531 commit 127347c
Show file tree
Hide file tree
Showing 26 changed files with 146 additions and 126 deletions.
13 changes: 7 additions & 6 deletions visualization/views/average_bids_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ def get(self, request):
"""
Returns average bids for contracts
"""
country = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer")
country_code = self.request.GET.get("country", None)
buyer_id = self.request.GET.get("buyer")

filter_args = {}
filter_args["no_of_bidders__gte"] = 1
if country:
filter_args["country__country_code_alpha_2"] = country
if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)

# Month wise average of number of bids for contracts
monthwise_data = (
Expand Down
7 changes: 4 additions & 3 deletions visualization/views/buyer_summary_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ class BuyerSummaryView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
country_code = self.request.GET.get("country", None)
result = {}
trend = []
current_time = datetime.datetime.now()
previous_month_date = current_time - dateutil.relativedelta.relativedelta(months=-1)
previous_month = previous_month_date.replace(day=1).date()
if country:
filter_args["country__country_code_alpha_2"] = country
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
buyer_details = (
Tender.objects.filter(**filter_args)
.exclude(buyer__isnull=True)
Expand Down
19 changes: 10 additions & 9 deletions visualization/views/contract_red_flags_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ class ContractRedFlagsView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
supplier = self.request.GET.get("supplier", None)
buyer = self.request.GET.get("buyer", None)
country_code = self.request.GET.get("country", None)
supplier_id = self.request.GET.get("supplier", None)
buyer_id = self.request.GET.get("buyer", None)
product = self.request.GET.get("product", None)
if country:
filter_args["country__country_code_alpha_2"] = country
if supplier:
filter_args = add_filter_args("supplier", supplier, filter_args)
if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
if supplier_id:
filter_args = add_filter_args("supplier", supplier_id, filter_args)
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)
if product:
filter_args["goods_services__goods_services_category__id"] = product
red_flags = RedFlag.objects.filter(implemented=True)
Expand Down
6 changes: 3 additions & 3 deletions visualization/views/contract_status_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def get(self, request):
currency_code = ""

country_code = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer")
buyer_id = self.request.GET.get("buyer")

if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code

if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)

if country_code:
try:
Expand Down
10 changes: 5 additions & 5 deletions visualization/views/country_map_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
class CountryMapView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
country = self.request.GET.get("country", None)
country_code = self.request.GET.get("country", None)

try:
country_instance = Country.objects.get(country_code_alpha_2=country)
country_instance = Country.objects.get(country_code_alpha_2=country_code)

if country is not None and country_instance is not None:
tender_instance = Tender.objects.filter(country__country_code_alpha_2=country).aggregate(
if country_code is not None and country_instance is not None:
tender_instance = Tender.objects.filter(country__country_code_alpha_2=country_code).aggregate(
total_usd=Sum("contract_value_usd"),
total_local=Sum("contract_value_local"),
)
count = Tender.objects.filter(country__country_code_alpha_2=country).count()
count = Tender.objects.filter(country__country_code_alpha_2=country_code).count()
final = {
"country_code": country_instance.country_code_alpha_2,
"country": country_instance.name,
Expand Down
7 changes: 4 additions & 3 deletions visualization/views/country_suppliers_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class CountrySuppliersView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
country_code = self.request.GET.get("country", None)
count = int(self.request.GET.get("count", 5))
if country:
filter_args["country__country_code_alpha_2"] = country
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code

usd_amountwise_sorted = (
Tender.objects.filter(
Expand Down
1 change: 1 addition & 0 deletions visualization/views/data_provider_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get(self, request):
country_code = self.request.GET.get("country", None)

if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code

try:
Expand Down
14 changes: 7 additions & 7 deletions visualization/views/direct_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ class DirectOpen(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
country_code = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer")
supplier = self.request.GET.get("supplier")
buyer_id = self.request.GET.get("buyer")
supplier_id = self.request.GET.get("supplier")
filter_args = {}
country_currency = ""

results = {}

if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)
results = procurement_procedure_amount(**filter_args)

if supplier:
filter_args = add_filter_args("supplier", supplier, filter_args)
if supplier_id:
filter_args = add_filter_args("supplier", supplier_id, filter_args)
results = procurement_procedure_amount(**filter_args)

if country_code:
Expand All @@ -49,7 +49,7 @@ def get(self, request):
filter_args = add_filter_args("country__country_code_alpha_2", country_code, filter_args, append_only=True)
results = procurement_procedure_amount(**filter_args)

if not country_code and not supplier and not buyer:
if not country_code and not supplier_id and not buyer_id:
results = procurement_procedure_amount(**filter_args)

response = []
Expand Down
17 changes: 9 additions & 8 deletions visualization/views/equity_indicator_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ class EquityIndicatorView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer")
if country:
filter_args["country__country_code_alpha_2"] = country
if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
if country:
country_code = self.request.GET.get("country", None)
buyer_id = self.request.GET.get("buyer")
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)
if country_code:
try:
country_instance = Country.objects.get(country_code_alpha_2=country)
country_instance = Country.objects.get(country_code_alpha_2=country_code)
filter_args["country"] = country_instance
tenders_assigned = (
Tender.objects.filter(**filter_args)
Expand Down
6 changes: 3 additions & 3 deletions visualization/views/filter_parameters_suppliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class FilterParametersSuppliers(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
country_code = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer", None)
buyer_id = self.request.GET.get("buyer", None)

filter_args = {"supplier__isnull": False}

if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)

if country_code:
country_code = str(country_code).upper()
Expand Down
7 changes: 4 additions & 3 deletions visualization/views/insights_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def paginate(self, object_list, page=1, limit=10, count=0, **kwargs):
class InsightsView(ViewPaginatorMixin, APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
country = self.request.GET.get("country", None)
country_code = self.request.GET.get("country", None)
insight_type = self.request.GET.get("type", None)
year = self.request.GET.get("year", None)
order = self.request.GET.get("order", None)
Expand All @@ -60,8 +60,9 @@ def get(self, request):
filter_args = {}
filter_insights_args = {}

if country:
filter_args["country__country_code_alpha_2"] = country
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code

if insight_type:
if insight_type in ["News", "Blog"]:
Expand Down
13 changes: 7 additions & 6 deletions visualization/views/monopolization_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ class MonopolizationView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer")
if country:
filter_args["country__country_code_alpha_2"] = country
if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
country_code = self.request.GET.get("country", None)
buyer_id = self.request.GET.get("buyer")
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)
filter_args["supplier_id__isnull"] = False
# Month wise average of number of bids for contracts
monthwise_data = (
Expand Down
19 changes: 10 additions & 9 deletions visualization/views/product_distribution_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class ProductDistributionView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer", None)
if country:
filter_args["country__country_code_alpha_2"] = country
if buyer:
filter_args["contract__buyer__buyer_id"] = buyer
if buyer == "notnull":
country_code = self.request.GET.get("country", None)
buyer_id = self.request.GET.get("buyer", None)
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
if buyer_id:
filter_args["contract__buyer__buyer_id"] = buyer_id
if buyer_id == "notnull":
filter_args["contract__buyer__isnull"] = False

result = []
Expand All @@ -37,8 +38,8 @@ def get(self, request):
"product_id": goods["goods_services_category__id"],
"local_currency_code": "USD",
}
if country:
instance = Country.objects.get(country_code_alpha_2=country)
if country_code:
instance = Country.objects.get(country_code_alpha_2=country_code)
data["local_currency_code"] = instance.currency

data["tender_count"] = goods["tender"]
Expand Down
9 changes: 5 additions & 4 deletions visualization/views/product_summary_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class ProductSummaryView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
country_code = self.request.GET.get("country", None)
currency = "USD"
if country:
filter_args["country__country_code_alpha_2"] = country
instance = Country.objects.get(country_code_alpha_2=country)
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
instance = Country.objects.get(country_code_alpha_2=country_code)
currency = instance.currency
result = []
tenders_assigned = (
Expand Down
7 changes: 4 additions & 3 deletions visualization/views/product_table_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ class ProductTableView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
if country:
filter_args["country__country_code_alpha_2"] = country
country_code = self.request.GET.get("country", None)
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
filter_args["goods_services__goods_services_category__isnull"] = False
result = []
product_tables = (
Expand Down
12 changes: 6 additions & 6 deletions visualization/views/product_timeline_race_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ class ProductTimelineRaceView(APIView):
def get(self, request):
filter_args = {}
country_code = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer")
supplier = self.request.GET.get("supplier")
buyer_id = self.request.GET.get("buyer")
supplier_id = self.request.GET.get("supplier")
currency = "USD"
if supplier:
filter_args = add_filter_args("supplier", supplier, filter_args)
if supplier_id:
filter_args = add_filter_args("supplier", supplier_id, filter_args)
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
instance = Country.objects.get(country_code_alpha_2=country_code)
currency = instance.currency
if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)
cum_dict = {}
final_data = []
categories = GoodsServicesCategory.objects.all()
Expand Down
19 changes: 10 additions & 9 deletions visualization/views/product_timeline_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ class ProductTimelineView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
buyer = self.request.GET.get("buyer")
supplier = self.request.GET.get("supplier")
if country:
filter_args["country__country_code_alpha_2"] = country
if buyer:
filter_args = add_filter_args("buyer", buyer, filter_args)
if supplier:
filter_args = add_filter_args("supplier", supplier, filter_args)
country_code = self.request.GET.get("country", None)
buyer_id = self.request.GET.get("buyer")
supplier_id = self.request.GET.get("supplier")
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
if buyer_id:
filter_args = add_filter_args("buyer", buyer_id, filter_args)
if supplier_id:
filter_args = add_filter_args("supplier", supplier_id, filter_args)
result = []
try:
tenders_assigned = (
Expand Down
7 changes: 4 additions & 3 deletions visualization/views/quantity_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class QuantityCorrelation(APIView):

@method_decorator(cache_page(page_expire_period()))
def get(self, request):
country = self.request.GET.get("country", None)
country_code = self.request.GET.get("country", None)
filter_args = {}
if country:
filter_args["country__country_code_alpha_2"] = country
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
contracts_quantity = (
Tender.objects.filter(**filter_args)
.annotate(month=TruncMonth("contract_date"))
Expand Down
7 changes: 4 additions & 3 deletions visualization/views/red_flag_summary_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class RedFlagSummaryView(APIView):
@method_decorator(cache_page(page_expire_period()))
def get(self, request):
filter_args = {}
country = self.request.GET.get("country", None)
if country:
filter_args["country__country_code_alpha_2"] = country
country_code = self.request.GET.get("country", None)
if country_code:
country_code = str(country_code).upper()
filter_args["country__country_code_alpha_2"] = country_code
filter_args["red_flag__isnull"] = False
result = []
equity_summary = (
Expand Down
Loading

0 comments on commit 127347c

Please sign in to comment.