2015-12-15 16:50:50 +00:00
from django . shortcuts import render
from django . views . generic . edit import UpdateView , CreateView
2016-02-05 15:59:42 +00:00
from django . views . generic . base import View
from django . core . exceptions import PermissionDenied
2015-12-15 16:50:50 +00:00
from django import forms
from django . forms import Select
from django . conf import settings
2016-01-29 14:20:00 +00:00
from subscription . models import Subscriber , Subscription
2015-12-15 16:50:50 +00:00
from core . views import CanEditMixin , CanEditPropMixin , CanViewMixin
2016-02-05 15:59:42 +00:00
from core . models import User
class SubscriberMixin ( View ) :
def dispatch ( self , request , * arg , * * kwargs ) :
res = super ( SubscriberMixin , self ) . dispatch ( request , * arg , * * kwargs )
subscriber = Subscriber . objects . filter ( pk = request . user . pk ) . first ( )
if subscriber is not None and subscriber . is_subscribed ( ) :
return ret
raise PermissionDenied
2015-12-15 16:50:50 +00:00
class SubscriptionForm ( forms . ModelForm ) :
class Meta :
model = Subscription
2016-01-29 14:20:00 +00:00
fields = [ ' member ' , ' subscription_type ' , ' payment_method ' ]
2015-12-15 16:50:50 +00:00
#widgets = {
# 'subscription_type': Select(choices={(k.lower(), k+" - "+str(v['price'])+"€"+str(Subscription.compute_end(2))) for k,v in settings.AE_SUBSCRIPTIONS.items()}),
#}
class NewSubscription ( CanEditMixin , CreateView ) :
2016-01-28 16:42:22 +00:00
template_name = ' subscription/subscription.html '
2015-12-15 16:50:50 +00:00
form_class = SubscriptionForm