From 303eb4112d5af67c307951b756282bee696114d6 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 21 Oct 2017 21:34:54 +0200 Subject: [PATCH] Add doc. and return empty list for get_all_cards_list function --- hosting/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hosting/models.py b/hosting/models.py index 62957100..18027790 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -212,10 +212,19 @@ class UserCardDetail(AssignPermissionsMixin, models.Model): @classmethod def get_all_cards_list(cls, stripe_customer): + """ + Get all the cards of the given customer as a list + + :param stripe_customer: The StripeCustomer object + :return: A list of all cards; an empty list if the customer object is + None + """ + cards_list = [] + if stripe_customer is None: + return cards_list user_card_details = UserCardDetail.objects.filter( stripe_customer_id=stripe_customer.id ) - cards_list = [] for card in user_card_details: cards_list.append({ 'last4': card.last4, 'brand': card.brand, 'id': card.id