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

Commit

Permalink
Revert "Replace "except Exception:" with "except:" to avoid hiding fl…
Browse files Browse the repository at this point in the history
…ake8 errors"
  • Loading branch information
jpmckinney committed Apr 12, 2021
1 parent fa6959d commit a9c520f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 40 deletions.
35 changes: 18 additions & 17 deletions country/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db.models import Sum
from rest_framework import serializers
from rest_framework_serializer_extensions.serializers import SerializerExtensionsMixin

from .models import Buyer, Country, Language, OverallSummary, RedFlag, Supplier, Tender


Expand Down Expand Up @@ -85,7 +86,7 @@ def get_amount_usd(self, obj):
return obj.amount_usd
else:
return None
except:
except Exception:
return obj.tenders.all().aggregate(sum_usd=Sum("goods_services__contract_value_usd"))["sum_usd"]

def get_amount_local(self, obj):
Expand All @@ -94,7 +95,7 @@ def get_amount_local(self, obj):
return obj.amount_local
else:
return None
except:
except Exception:
return obj.tenders.all().aggregate(sum_local=Sum("goods_services__contract_value_local"))["sum_local"]

# def get_red_flag_tender_count(self, obj):
Expand All @@ -105,7 +106,7 @@ def get_amount_local(self, obj):
# total = obj.tender_count
# try:
# return red_flags / total
# except:
# except Exception:
# return 0

def get_country_code(self, obj):
Expand All @@ -119,7 +120,7 @@ def get_country_name(self, obj):
return obj.country_name
else:
return None
except:
except Exception:
tender_obj = obj.tenders.first()
if tender_obj:
return tender_obj.country.name
Expand All @@ -138,7 +139,7 @@ def get_tender_count(self, obj):
return obj.tender_count
else:
return None
except:
except Exception:
supplier_related_tenders = obj.tenders.all()
if supplier_related_tenders:
return supplier_related_tenders.count()
Expand All @@ -149,7 +150,7 @@ def get_product_category_count(self, obj):
return obj.product_category_count
else:
return None
except:
except Exception:
supplier_related_tenders = obj.tenders.all()
if supplier_related_tenders:
product_category_count = supplier_related_tenders.distinct(
Expand Down Expand Up @@ -193,7 +194,7 @@ def get_amount_usd(self, obj):
return obj.amount_usd
else:
return None
except:
except Exception:
return (
obj.tenders.select_related("goods_services")
.all()
Expand All @@ -206,7 +207,7 @@ def get_amount_local(self, obj):
return obj.amount_local
else:
return None
except:
except Exception:
return (
obj.tenders.select_related("goods_services")
.all()
Expand All @@ -221,7 +222,7 @@ def get_amount_local(self, obj):
# total = obj.tender_count
# try:
# return red_flags / total
# except:
# except Exception:
# return 0

def get_country_code(self, obj):
Expand All @@ -235,7 +236,7 @@ def get_country_name(self, obj):
return obj.country_name
else:
return None
except:
except Exception:
tender_obj = obj.tenders.first()
if tender_obj:
return tender_obj.country.name
Expand All @@ -246,7 +247,7 @@ def get_product_category_count(self, obj):
return obj.product_category_count
else:
return None
except:
except Exception:
buyer_related_tenders = obj.tenders.all()
if buyer_related_tenders:
product_category_count = buyer_related_tenders.distinct(
Expand All @@ -265,7 +266,7 @@ def get_tender_count(self, obj):
return obj.tender_count
else:
return None
except:
except Exception:
buyer_related_tenders = obj.tenders.all()
if buyer_related_tenders:
return buyer_related_tenders.count()
Expand Down Expand Up @@ -365,31 +366,31 @@ def get_product_category(self, obj):
def get_bidders_no(self, obj):
try:
return obj.no_of_bidders
except:
except Exception:
return 0

def get_tender_local(self, obj):
try:
return obj.goods_services.aggregate(tender_value_local=Sum("tender_value_local"))["tender_value_local"]
except:
except Exception:
return 0

def get_tender_usd(self, obj):
try:
return obj.goods_services.aggregate(tender_value_usd=Sum("tender_value_usd"))["tender_value_usd"]
except:
except Exception:
return 0

def get_award_local(self, obj):
try:
return obj.goods_services.aggregate(award_value_local=Sum("award_value_local"))["award_value_local"]
except:
except Exception:
return 0

def get_award_usd(self, obj):
try:
return obj.goods_services.aggregate(award_value_usd=Sum("award_value_usd"))["award_value_usd"]
except:
except Exception:
return 0

def get_equity_category(self, obj):
Expand Down
8 changes: 4 additions & 4 deletions country/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def import_tender_from_batch_id(batch_id, country, currency):
temp_data = TempDataImportTable.objects.filter(import_batch_id=batch_id)
country = country
currency = currency
except:
except Exception:
traceback.print_exc(file=sys.stdout)
return True

Expand Down Expand Up @@ -296,7 +296,7 @@ def import_tender_from_batch_id(batch_id, country, currency):
)

total_rows_imported_count += 1
except:
except Exception:
# transaction.rollback()

contract_id = row.contract_id
Expand Down Expand Up @@ -675,7 +675,7 @@ def country_contract_excel(country):
for category in equitycategories:
equity_categorylist.append(category.category_name)
equitycategories = str(",".join(set(equity_categorylist)))
except:
except Exception:
equity_categorylist = []
equitycategories = ""

Expand Down Expand Up @@ -828,7 +828,7 @@ def country_contract_excel(country):
for category in equitycategories:
equity_categorylist.append(category["equity_category__category_name"])
equitycategories = str(",".join(set(equity_categorylist)))
except:
except Exception:
equity_categorylist = []
equitycategories = ""

Expand Down
4 changes: 2 additions & 2 deletions country/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def get(self, request):
messages.info(request, "Your import has started!")
return HttpResponseRedirect("/admin/content/dataimport")

except:
except Exception:
messages.error(request, "Your import has failed!")
return HttpResponseRedirect("/admin/content/dataimport")
else:
Expand Down Expand Up @@ -282,7 +282,7 @@ def get(self, request):
messages.info(request, "Validation is in progress!! Please wait for a while")
return HttpResponseRedirect("/admin/content/dataimport")

except:
except Exception:
messages.error(request, "Your import has failed!")
return HttpResponseRedirect("/admin/content/dataimport")
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[flake8]
exclude = migrations
max-line-length = 119
extend-ignore = E203, W503, E722
extend-ignore = E203, W503

[isort]
skip = migrations
Expand Down
32 changes: 16 additions & 16 deletions vizualization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def get(self, request):
if j["active_cases_count"] and j["death_count"]:
active_case_count += j["active_cases_count"]
death_count += j["death_count"]
except:
except Exception:
active_case_count = 0
death_count = 0
a = {}
Expand Down Expand Up @@ -936,7 +936,7 @@ def get(self, request):
country = self.request.GET.get("country", None)
try:
country_instance = Country.objects.get(country_code_alpha_2=country)
except:
except Exception:
return JsonResponse({"result": "Invalid Alpha Code"})
if country is not None and country_instance is not None:
tender_instance = Tender.objects.filter(country__country_code_alpha_2=country).aggregate(
Expand Down Expand Up @@ -1322,7 +1322,7 @@ def get(self, request):
},
]
return JsonResponse(data, safe=False)
except:
except Exception:
return JsonResponse([{"error": "Invalid country_code"}], safe=False)
else:
tenders_assigned = (
Expand Down Expand Up @@ -1405,7 +1405,7 @@ def get(self, request):
data["tender_count"] = tender["count"]
result.append(data)
return JsonResponse(result, safe=False)
except:
except Exception:
return JsonResponse([{"error": "Invalid country_code"}], safe=False)
else:
tenders_assigned = (
Expand Down Expand Up @@ -1436,7 +1436,7 @@ def get(self, request):
data["tender_count"] = tender["count"]
result.append(data)
return JsonResponse(result, safe=False)
except:
except Exception:
return JsonResponse([{"error": "Invalid country_code"}], safe=False)
return JsonResponse(data, safe=False)

Expand Down Expand Up @@ -1565,7 +1565,7 @@ def get(self, request, *args, **kwargs):
data["country_code"] = supplier_detail[0]["country__country_code_alpha_2"]
data["country_name"] = supplier_detail[0]["country__name"]
return JsonResponse(data, safe=False)
except:
except Exception:
data["error"] = "Enter valid ID"
return JsonResponse(data, safe=False)

Expand Down Expand Up @@ -1596,7 +1596,7 @@ def get(self, request, *args, **kwargs):
data["country_code"] = buyer_detail[0]["country__country_code_alpha_2"]
data["country_name"] = buyer_detail[0]["country__name"]
return JsonResponse(data, safe=False)
except:
except Exception:
data["error"] = "Enter valid ID"
return JsonResponse(data, safe=False)

Expand All @@ -1610,7 +1610,7 @@ def get(self, request):
filter_args["country__country_code_alpha_2"] = country
try:
data_provider = CountryPartner.objects.filter(**filter_args)
except:
except Exception:
data_provider = [{"error": "Country partner doesnot exist for this country"}]
result = []
if data_provider:
Expand Down Expand Up @@ -1638,7 +1638,7 @@ def get(self, request):
filter_args["country__country_code_alpha_2"] = country
try:
data_provider = DataProvider.objects.filter(**filter_args)
except:
except Exception:
data_provider = [{"error": "Data Provider doesnot exist for this country"}]
result = []
if data_provider:
Expand Down Expand Up @@ -1698,7 +1698,7 @@ def get(self, request):
)
print(final_current_month_count)
print(final_previous_month_count)
except:
except Exception:
percentage = 0
result["total"] = totals["total"]
result["percentage"] = percentage
Expand Down Expand Up @@ -1747,7 +1747,7 @@ def get(self, request):
percentage = round(
((final_current_month_count[0] - final_previous_month_count[0]) / final_previous_month_count[0]) * 100
)
except:
except Exception:
percentage = 0
result["total"] = totals["total"]
result["percentage"] = percentage
Expand Down Expand Up @@ -1844,7 +1844,7 @@ def get(self, request, *args, **kwargs):

return JsonResponse(result, safe=False)

except:
except Exception:
return JsonResponse([{"error": "No buyer and supplier data available"}], safe=False)


Expand Down Expand Up @@ -1943,7 +1943,7 @@ def get(self, request):
data["country_code"] = "USD"
result.append(data)
return JsonResponse(result, safe=False)
except:
except Exception:
return JsonResponse([{"error": "Country code doest not exists"}], safe=False)


Expand Down Expand Up @@ -1973,7 +1973,7 @@ def get(self, request):
data["country_code"] = "USD"
result.append(data)
return JsonResponse(result, safe=False)
except:
except Exception:
return JsonResponse([{"error": "Country code doest not exists"}], safe=False)


Expand Down Expand Up @@ -2137,7 +2137,7 @@ def get(self, request, *args, **kwargs):
result["country_id"] = results[0]["country_id"]
result["content_image_id"] = results[0]["content_image_id"]

except:
except Exception:
result = [{"error": "Content doest not exists"}]
return JsonResponse(result, safe=False)

Expand All @@ -2153,7 +2153,7 @@ def get(self, request, *args, **kwargs):
result["page_type"] = results[0]["page_type"]
result["body"] = results[0]["body"]

except:
except Exception:
result = [{"error": "Content doest not exists"}]

return JsonResponse(result, safe=False)
Expand Down

0 comments on commit a9c520f

Please sign in to comment.