Refactor getting all cards to UserCardDetail.get_all_cards_list()
This commit is contained in:
parent
8df72620d6
commit
14c7d6ac0e
2 changed files with 14 additions and 7 deletions
|
@ -209,3 +209,15 @@ class UserCardDetail(AssignPermissionsMixin, models.Model):
|
||||||
)
|
)
|
||||||
instance.assign_permissions(stripe_customer.user)
|
instance.assign_permissions(stripe_customer.user)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_all_cards_list(cls, stripe_customer):
|
||||||
|
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
|
||||||
|
})
|
||||||
|
return cards_list
|
||||||
|
|
|
@ -551,14 +551,9 @@ class SettingsView(LoginRequiredMixin, FormView):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(SettingsView, self).get_context_data(**kwargs)
|
context = super(SettingsView, self).get_context_data(**kwargs)
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
user_card_details = UserCardDetail.objects.filter(
|
cards_list = UserCardDetail.get_all_cards_list(
|
||||||
stripe_customer_id=user.stripecustomer.id
|
stripe_customer= user.stripecustomer
|
||||||
)
|
)
|
||||||
cards_list = []
|
|
||||||
for card in user_card_details:
|
|
||||||
cards_list.append({
|
|
||||||
'last4': card.last4, 'brand': card.brand, 'id': card.id
|
|
||||||
})
|
|
||||||
context.update({
|
context.update({
|
||||||
'cards_list': cards_list,
|
'cards_list': cards_list,
|
||||||
'stripe_key': settings.STRIPE_API_PUBLIC_KEY
|
'stripe_key': settings.STRIPE_API_PUBLIC_KEY
|
||||||
|
|
Loading…
Reference in a new issue