43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
from django.shortcuts import redirect
|
|
from django.views.generic import TemplateView, FormView, DetailView
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from frontend.forms import SMSAuthForm
|
|
from frontend.models import CardURL
|
|
from django.utils import timezone
|
|
from datetime import timedelta
|
|
from django.http import Http404
|
|
from smsauth.views import requestToken
|
|
from buyer.views import getCard, sendStatus
|
|
from ledger.models import Payment
|
|
|
|
def makeCardURL(card):
|
|
return CardURL.objects.create(card=card) # pylint: disable=E1101
|
|
|
|
class IndexView(LoginRequiredMixin, TemplateView):
|
|
template_name = "frontend/index.html"
|
|
|
|
class SMSAuthView(LoginRequiredMixin, FormView):
|
|
template_name = "frontend/form.html"
|
|
form_class = SMSAuthForm
|
|
|
|
def get_context_data(self, **kwargs):
|
|
requestToken()
|
|
return super(SMSAuthView, self).get_context_data(**kwargs)
|
|
|
|
def form_valid(self, form):
|
|
Payment.objects.create(description="Paysafecard", amount=11) # pylint: disable=E1101
|
|
return redirect("/card/%s/" % makeCardURL(getCard()).uuid)
|
|
|
|
class CardView(LoginRequiredMixin, DetailView):
|
|
template_name = "frontend/card.html"
|
|
model = CardURL
|
|
pk_url_kwarg = "uuid"
|
|
|
|
def get_object(self, queryset=None):
|
|
obj = super(CardView, self).get_object(queryset=queryset)
|
|
if timezone.now() - timedelta(seconds=300) > obj.created:
|
|
raise Http404()
|
|
obj.card.delivered = timezone.now()
|
|
obj.card.save()
|
|
sendStatus()
|
|
return obj
|