Changeset View
Changeset View
Standalone View
Standalone View
looper/views/settings.py
| from typing import Optional, Any, Dict | |||||
| import logging | import logging | ||||
| from django.contrib.auth.decorators import login_required | from django.contrib.auth.decorators import login_required | ||||
| from django.contrib.auth.mixins import LoginRequiredMixin | from django.contrib.auth.mixins import LoginRequiredMixin | ||||
| from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect | from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect | ||||
| from django.shortcuts import get_object_or_404, render | from django.shortcuts import get_object_or_404, render | ||||
| from django.urls import reverse_lazy | from django.urls import reverse_lazy | ||||
| from django.views.generic import UpdateView, ListView, DeleteView, DetailView | from django.views.generic import UpdateView, ListView, DeleteView, DetailView | ||||
| ▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | def dispatch(self, request, *args, **kwargs): | ||||
| return super().dispatch(request, *args, **kwargs) | return super().dispatch(request, *args, **kwargs) | ||||
| def determine_currency(self) -> str: | def determine_currency(self) -> str: | ||||
| """Determine the currency for which this payment method was used. | """Determine the currency for which this payment method was used. | ||||
| It could be more than one, but we just pick one from the last | It could be more than one, but we just pick one from the last | ||||
| transaction, order, or subscription. | transaction, order, or subscription. | ||||
| """ | """ | ||||
| trans = self.paymeth.transaction_set.last() | trans: Optional['models.Transaction'] = self.paymeth.transaction_set.last() | ||||
| if trans is not None: | if trans is not None: | ||||
| return trans.currency | return trans.currency | ||||
| order = self.paymeth.order_set.last() | order: Optional['models.Order'] = self.paymeth.order_set.last() | ||||
| if order is not None: | if order is not None: | ||||
| return order.currency | return order.currency | ||||
| subs = self.paymeth.subscription_set.last() | subs: Optional['models.Subscription'] = self.paymeth.subscription_set.last() | ||||
| if subs is not None: | if subs is not None: | ||||
| return subs.currency | return subs.currency | ||||
| return '' | return '' | ||||
| def get_currency(self) -> str: | def get_currency(self) -> str: | ||||
| return self.currency | return self.currency | ||||
| def get_context_data(self, **kwargs) -> dict: | def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: | ||||
| ctx = { | ctx = { | ||||
| **super().get_context_data(**kwargs), | **super().get_context_data(**kwargs), | ||||
| 'paymeth': self.paymeth, | 'paymeth': self.paymeth, | ||||
| 'currency': self.currency, | 'currency': self.currency, | ||||
| } | } | ||||
| return ctx | return ctx | ||||
| def form_valid(self, form: forms.CheckoutForm) -> HttpResponse: | def form_valid(self, form: forms.CheckoutForm) -> HttpResponse: | ||||
| Show All 27 Lines | |||||