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

Commit

Permalink
CPA-202 Use self.stdout/self.stderr instead of print()
Browse files Browse the repository at this point in the history
  • Loading branch information
bikramtuladhar committed Apr 28, 2021
1 parent 84dd711 commit f90186e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion country/management/commands/fill_contract_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
class Command(BaseCommand):
def handle(self, *args, **kwargs):
tenders = Tender.objects.all()
print("Created task: fill_contract_values")
self.stdout.write("Created task: fill_contract_values")
for tender in tenders:
fill_contract_values.apply_async(args=(tender.id,), queue="covid19")
6 changes: 3 additions & 3 deletions country/management/commands/generate_excel_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Command(BaseCommand):
help = "Generate Excel Summary"

def handle(self, *args, **kwargs):
print("Exporting")
self.stdout.write("Exporting")
os.makedirs(os.path.join("media", "export"), exist_ok=True)
workbook = xlsxwriter.Workbook("media/export/overall_summary.xlsx")
worksheet = workbook.add_worksheet()
Expand Down Expand Up @@ -139,7 +139,7 @@ def handle(self, *args, **kwargs):

try:
obj, created = OverallSummary.objects.get_or_create(country=country)
print(f"Created : {obj}, {created}")
self.stdout.write(f"Created : {obj}, {created}")
except Exception as e:
print(e)
self.stderr.write(e)
workbook.close()
10 changes: 5 additions & 5 deletions country/management/commands/import_red_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

class Command(BaseCommand):
def handle(self, *args, **kwargs):
print("Removing all the relations of Red flag")
self.stdout.write("Removing all the relations of Red flag")
tenders = Tender.objects.all()
for tender in tenders:
id = tender.id
clear_redflag.apply_async(args=(id,), queue="covid19")

print("All cleared")
print("Processing Red Flag in tender")
self.stdout.write("All cleared")
self.stdout.write("Processing Red Flag in tender")

tender_instance = Tender.objects.filter(supplier__isnull=False, buyer__isnull=False).values(
"id", "buyer__buyer_name", "supplier__supplier_name", "supplier__supplier_address"
Expand All @@ -26,5 +26,5 @@ def handle(self, *args, **kwargs):
for tender in tenders:
id = tender.id
process_redflag.apply_async(args=(id,), queue="covid19")
print("Created task for id :" + str(id))
return "Done"
self.stdout.write("Created task for id :" + str(id))
self.stdout.write("Done")
8 changes: 4 additions & 4 deletions country/management/commands/import_tender_from_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def add_arguments(self, parser):
def handle(self, *args, **kwargs):
country = kwargs["country"]
batch_id = kwargs["batch_id"]
print(f"Fetching tender data for Batch id {batch_id} for country {country}")
self.stdout.write(f"Fetching tender data for Batch id {batch_id} for country {country}")

try:
result = Country.objects.filter(name=country).first()
country = result.name
currency = result.currency

if not result:
print(f'Country "{country}" does not exists in our database.')
self.stderr.write(f'Country "{country}" does not exists in our database.')
else:
import_tender_from_batch_id.apply_async(args=(batch_id, country, currency), queue="covid19")
print("Created task: import_tender_from_batch_id")
self.stdout.write("Created task: import_tender_from_batch_id")
except Exception as e:
print(e)
self.stderr.write(e)
6 changes: 3 additions & 3 deletions country/management/commands/process_currency_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Command(BaseCommand):
def handle(self, *args, **kwargs):
print("Processing currency conversion")
self.stdout.write("Processing currency conversion")
unconverted_tender = GoodsServices.objects.filter(
Q(tender_value_usd__isnull=True) | Q(award_value_usd__isnull=True) | Q(contract_value_usd__isnull=True)
)
Expand All @@ -22,5 +22,5 @@ def handle(self, *args, **kwargs):
args=(tender_value_local, award_value_local, contract_value_local, tender_date, currency, id),
queue="covid19",
)
print("Created task for id :" + str(id))
return "Done"
self.stdout.write("Created task for id :" + str(id))
self.stdout.write("Done")
10 changes: 5 additions & 5 deletions country/management/commands/save_database_equity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def add_arguments(self, parser):

def handle(self, *args, **kwargs):
country_name = kwargs["country"]
print(f"Fetching equity data for {country_name}")
self.stdout.write(f"Fetching equity data for {country_name}")
if country_name:
try:
if Country.objects.filter(name=country_name).exists():
fetch_equity_data.apply_async(args=(country_name,), queue="covid19")
print(print("Created task: import_equity_data"))
self.stdout.write("Created task: import_equity_data")
except Exception as e:
print(e)
self.stderr.write(e)

else:
print("Enter country name as arguments")
return "Done"
self.stderr.write("Enter country name as arguments")
self.stdout.write("Done")

0 comments on commit f90186e

Please sign in to comment.