2016-11-01 04:01:43 +00:00
|
|
|
from django.core.urlresolvers import reverse_lazy
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.views.generic import UpdateView
|
2016-08-31 02:32:45 +00:00
|
|
|
from django.db import models
|
2016-09-06 00:45:45 +00:00
|
|
|
from django.http import HttpResponseRedirect
|
2016-11-01 04:01:43 +00:00
|
|
|
from django.contrib import messages
|
|
|
|
|
|
|
|
|
2016-08-31 02:32:45 +00:00
|
|
|
from membership.models import StripeCustomer
|
|
|
|
from utils.models import BillingAddress
|
|
|
|
|
|
|
|
|
2016-09-09 04:24:52 +00:00
|
|
|
class MembershipRequiredMixin(object):
|
2016-09-06 00:45:45 +00:00
|
|
|
membership_redirect_url = None
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
from .models import Membership
|
2016-09-29 05:04:40 +00:00
|
|
|
if not Membership.is_digitalglarus_active_member(request.user):
|
2016-09-06 00:45:45 +00:00
|
|
|
return HttpResponseRedirect(self.membership_redirect_url)
|
|
|
|
|
2016-09-09 04:24:52 +00:00
|
|
|
return super(MembershipRequiredMixin, self).dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class IsNotMemberMixin(object):
|
|
|
|
already_member_redirect_url = None
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
from .models import Membership
|
2016-09-29 05:04:40 +00:00
|
|
|
if Membership.is_digitalglarus_active_member(request.user):
|
2016-09-09 04:24:52 +00:00
|
|
|
return HttpResponseRedirect(self.already_member_redirect_url)
|
|
|
|
|
Reduced pixels needed to navbar transition color, Added membership deactivation form, Added membership deactivation view, Added membership status, Added membership charged.html, Added membership charged.txt, Extended class to send membership charge email, After membership, charge for first time an email is sent to the user, Fixed bug on redirecting, user to membership payment after signup, Fixed redirecting after buying a membership
2016-09-14 05:24:20 +00:00
|
|
|
return super(IsNotMemberMixin, self).dispatch(request, *args, **kwargs)
|
2016-09-06 00:45:45 +00:00
|
|
|
|
|
|
|
|
2016-08-31 02:32:45 +00:00
|
|
|
class Ordereable(models.Model):
|
|
|
|
customer = models.ForeignKey(StripeCustomer)
|
2016-09-09 04:24:52 +00:00
|
|
|
amount = models.FloatField()
|
2016-08-31 02:32:45 +00:00
|
|
|
billing_address = models.ForeignKey(BillingAddress)
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
approved = models.BooleanField(default=False)
|
2016-10-14 04:33:48 +00:00
|
|
|
last4 = models.CharField(max_length=4, blank=True)
|
|
|
|
cc_brand = models.CharField(max_length=10, blank=True)
|
2016-08-31 02:32:45 +00:00
|
|
|
stripe_charge_id = models.CharField(max_length=100, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create(cls, data):
|
|
|
|
stripe_charge = data.pop('stripe_charge', None)
|
2016-12-07 03:19:22 +00:00
|
|
|
# del(data['status'])
|
2016-08-31 02:32:45 +00:00
|
|
|
instance = cls.objects.create(**data)
|
2016-10-14 04:33:48 +00:00
|
|
|
if not stripe_charge:
|
|
|
|
return instance
|
2016-08-31 02:32:45 +00:00
|
|
|
instance.stripe_charge_id = stripe_charge.id
|
|
|
|
instance.last4 = stripe_charge.source.last4
|
|
|
|
instance.cc_brand = stripe_charge.source.brand
|
2016-09-06 00:45:45 +00:00
|
|
|
instance.save()
|
2016-08-31 02:32:45 +00:00
|
|
|
return instance
|
2016-11-01 04:01:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ChangeMembershipStatusMixin(LoginRequiredMixin, UpdateView):
|
|
|
|
success_message = None
|
|
|
|
success_url = reverse_lazy('digitalglarus:membership_orders_list')
|
|
|
|
login_url = reverse_lazy('digitalglarus:login')
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def get_object(self):
|
|
|
|
from .models import MembershipOrder
|
|
|
|
membership_order = MembershipOrder.objects.\
|
|
|
|
filter(customer__user=self.request.user).last()
|
|
|
|
if not membership_order:
|
|
|
|
raise AttributeError("Membership does not exists")
|
|
|
|
membership = membership_order.membership
|
|
|
|
return membership
|
|
|
|
|
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
membership = self.get_object()
|
|
|
|
membership.activate()
|
|
|
|
|
|
|
|
messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
|
|
|
|
|
|
|
return HttpResponseRedirect(self.success_url)
|