1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from datetime import date
6 from django.views.decorators.cache import never_cache
7 from django.core.urlresolvers import reverse
8 from django.http import Http404
9 from django.shortcuts import redirect, get_object_or_404
10 from django.views.decorators.csrf import csrf_exempt
11 from django.views.generic import TemplateView, FormView, DetailView, ListView
12 import getpaid.backends.payu
13 from getpaid.models import Payment
14 from . import app_settings
15 from .forms import OrderForm
16 from .models import Offer, Order
20 class OfferDetailView(FormView):
21 form_class = OrderForm
22 template_name = "shop/offer_detail.html"
23 backend = 'getpaid.backends.payu'
26 def dispatch(self, request, slug):
27 if getattr(self, 'object', None) is None:
28 lang = request.LANGUAGE_CODE
29 args = {'entry__slug_%s' % lang: slug}
30 self.object = get_object_or_404(Offer, **args)
31 return super(OfferDetailView, self).dispatch(request, slug)
33 def get(self, *args, **kwargs):
34 return redirect(self.object.get_absolute_url())
36 def get_context_data(self, *args, **kwargs):
37 ctx = super(OfferDetailView, self).get_context_data(*args, **kwargs)
38 ctx['entry'] = self.object.entry
41 def get_form(self, form_class):
42 return form_class(self.object, self.request.POST)
44 def form_valid(self, form):
46 # Skip getpaid.forms.PaymentMethodForm, go directly to the broker.
47 payment = Payment.create(order, self.backend)
48 gateway_url_tuple = payment.get_processor()(payment).get_gateway_url(self.request)
49 payment.change_status('in_progress')
50 return redirect(gateway_url_tuple[0])
53 class ThanksView(DetailView):
55 template_name = "shop/thanks.html"
58 class NoThanksView(DetailView):
60 template_name = "shop/no_thanks.html"