Add additional None checks

This commit is contained in:
PCoder 2019-05-06 08:30:50 +02:00
parent 0f777e66d8
commit 3f01145cd1

View file

@ -86,12 +86,39 @@ class Command(BaseCommand):
vm_ids = [] vm_ids = []
for order in hosting_orders: for order in hosting_orders:
vm_ids.append(order.vm_id) vm_ids.append(order.vm_id)
# Delete Billing Address # Delete Billing Address
if order.billing_address is not None:
order.billing_address.delete() order.billing_address.delete()
logger.debug(
"Billing Address {} associated with {} deleted"
"".format(order.billing_address.id, email)
)
else:
logger.error(
"Error while deleting the billing_address")
# Delete Order Detail # Delete Order Detail
if order.order_detail is not None:
order.order_detail.delete() order.order_detail.delete()
logger.debug(
"Order Detail {} associated with {} deleted"
"".format(order.order_detail.id, email)
)
else:
logger.error(
"Error while deleting the order_detail. None")
# Delete order # Delete order
if order is not None:
order.delete() order.delete()
logger.debug(
"Order {} associated with {} deleted"
"".format(order.id, email)
)
else:
logger.error(
"Error while deleting the Order")
hosting_bills = HostingBill.objects.filter( hosting_bills = HostingBill.objects.filter(
customer=stripe_customer.id customer=stripe_customer.id
@ -99,20 +126,53 @@ class Command(BaseCommand):
# delete hosting bills # delete hosting bills
for bill in hosting_bills: for bill in hosting_bills:
if bill.billing_address is not None:
bill.billing_address.delete() bill.billing_address.delete()
logger.debug(
"HostingBills billing address {} associated with {} deleted"
"".format(bill.billing_address.id, email)
)
else:
logger.error(
"Error while deleting the HostingBill's Billing address")
if bill is not None:
bill.delete() bill.delete()
logger.debug(
"HostingBill {} associated with {} deleted"
"".format(bill.id, email)
)
else:
logger.error(
"Error while deleting the HostingBill")
# delete VMDetail # delete VMDetail
for vm_id in vm_ids: for vm_id in vm_ids:
vm_detail = VMDetail.objects.get(vm_id=vm_id) vm_detail = VMDetail.objects.get(vm_id=vm_id)
if vm_detail is not None:
vm_detail.delete() vm_detail.delete()
logger.debug(
"vm_detail {} associated with {} deleted"
"".format(vm_detail.id, email)
)
else:
logger.error(
"Error while deleting the vm_detail")
# delete UserCardDetail # delete UserCardDetail
ucds = UserCardDetail.objects.filter( ucds = UserCardDetail.objects.filter(
stripe_customer=stripe_customer stripe_customer=stripe_customer
) )
for ucd in ucds: for ucd in ucds:
if ucd is not None:
ucd.delete() ucd.delete()
logger.debug(
"User Card Detail {} associated with {} deleted"
"".format(ucd.id, email)
)
else:
logger.error(
"Error while deleting the User Card Detail")
# delete UserHostingKey # delete UserHostingKey
uhks = UserHostingKey.objects.filter( uhks = UserHostingKey.objects.filter(