From 73cc787ca1cc14528a78ed9ffcf1b362916ffe0f Mon Sep 17 00:00:00 2001 From: Levi Date: Wed, 14 Sep 2016 00:24:20 -0500 Subject: [PATCH] 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 --- .../migrations/0017_membership_active.py | 20 +++ digitalglarus/mixins.py | 2 +- digitalglarus/models.py | 18 ++- .../digitalglarus/js/cbpAnimatedHeader.js | 2 +- .../digitalglarus/booking_orders_list.html | 1 + .../emails/membership_charge.html | 136 ++++++++++++++++++ .../emails/membership_charge.txt | 136 ++++++++++++++++++ .../digitalglarus/membership_deactivated.html | 62 ++++++++ .../membership_orders_detail.html | 2 +- .../digitalglarus/membership_orders_list.html | 21 ++- digitalglarus/urls.py | 4 +- digitalglarus/views.py | 51 ++++++- 12 files changed, 446 insertions(+), 9 deletions(-) create mode 100644 digitalglarus/migrations/0017_membership_active.py create mode 100644 digitalglarus/templates/digitalglarus/emails/membership_charge.html create mode 100644 digitalglarus/templates/digitalglarus/emails/membership_charge.txt create mode 100644 digitalglarus/templates/digitalglarus/membership_deactivated.html diff --git a/digitalglarus/migrations/0017_membership_active.py b/digitalglarus/migrations/0017_membership_active.py new file mode 100644 index 00000000..167fc18d --- /dev/null +++ b/digitalglarus/migrations/0017_membership_active.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2016-09-13 01:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('digitalglarus', '0016_auto_20160909_0110'), + ] + + operations = [ + migrations.AddField( + model_name='membership', + name='active', + field=models.BooleanField(default=True), + ), + ] diff --git a/digitalglarus/mixins.py b/digitalglarus/mixins.py index d224d0f3..40777bf3 100644 --- a/digitalglarus/mixins.py +++ b/digitalglarus/mixins.py @@ -23,7 +23,7 @@ class IsNotMemberMixin(object): if Membership.is_digitalglarus_member(request.user): return HttpResponseRedirect(self.already_member_redirect_url) - return super(MembershipRequiredMixin, self).dispatch(request, *args, **kwargs) + return super(IsNotMemberMixin, self).dispatch(request, *args, **kwargs) class Ordereable(models.Model): diff --git a/digitalglarus/models.py b/digitalglarus/models.py index 1da796a2..5fdf6607 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -60,6 +60,7 @@ class MembershipType(models.Model): class Membership(models.Model): type = models.ForeignKey(MembershipType) + active = models.BooleanField(default=True) @classmethod def is_digitalglarus_member(cls, user): @@ -68,17 +69,32 @@ class Membership(models.Model): membershiporder__created_at__month=datetime.today().month) has_booking_past_month = Q(membershiporder__customer__user=user, membershiporder__created_at__month=past_month) - return cls.objects.filter(has_booking_past_month | has_booking_current_month).exists() + active_membership = Q(active=True) + return cls.objects.filter(has_booking_past_month | has_booking_current_month).\ + filter(active_membership).exists() @classmethod def create(cls, data): instance = cls.objects.create(**data) return instance + def deactivate(self): + self.active = False + self.save() + class MembershipOrder(Ordereable, models.Model): membership = models.ForeignKey(Membership) + def first_membership_range_date(self): + start_date = self.created_at + _, days_in_month = calendar.monthrange(start_date.year, + start_date.month) + pass_days = start_date.day + days_left = days_in_month - pass_days + end_date = start_date + timedelta(days=days_left) + return start_date, end_date + @classmethod def current_membership(cls, user): last_payment = cls.objects.\ diff --git a/digitalglarus/static/digitalglarus/js/cbpAnimatedHeader.js b/digitalglarus/static/digitalglarus/js/cbpAnimatedHeader.js index 4554e2e5..dc750576 100755 --- a/digitalglarus/static/digitalglarus/js/cbpAnimatedHeader.js +++ b/digitalglarus/static/digitalglarus/js/cbpAnimatedHeader.js @@ -13,7 +13,7 @@ var cbpAnimatedHeader = (function() { var docElem = document.documentElement, header = document.querySelector( '.navbar-default' ), didScroll = false, - changeHeaderOn = 300; + changeHeaderOn = 20; function init() { window.addEventListener( 'scroll', function( event ) { diff --git a/digitalglarus/templates/digitalglarus/booking_orders_list.html b/digitalglarus/templates/digitalglarus/booking_orders_list.html index 58a5e4bd..bff0e231 100644 --- a/digitalglarus/templates/digitalglarus/booking_orders_list.html +++ b/digitalglarus/templates/digitalglarus/booking_orders_list.html @@ -64,5 +64,6 @@ + {% endblock %} \ No newline at end of file diff --git a/digitalglarus/templates/digitalglarus/emails/membership_charge.html b/digitalglarus/templates/digitalglarus/emails/membership_charge.html new file mode 100644 index 00000000..d2d3971f --- /dev/null +++ b/digitalglarus/templates/digitalglarus/emails/membership_charge.html @@ -0,0 +1,136 @@ +{% load static from staticfiles %} + + + + + + +Oxygen Invoice + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ logo + +
+
+ +
+
+
+
+ + + + + + + + + + +
+ Thank you for your subscription. +
+ Your monthly membership for period {{membership_start_date|date}} - {{membership_start_date|date}} has been charged.
You can view your invoice clicking on the button below. +
+ +
+
+
+
+ + +
+ ungleich
+
+
+
+ + + diff --git a/digitalglarus/templates/digitalglarus/emails/membership_charge.txt b/digitalglarus/templates/digitalglarus/emails/membership_charge.txt new file mode 100644 index 00000000..d2d3971f --- /dev/null +++ b/digitalglarus/templates/digitalglarus/emails/membership_charge.txt @@ -0,0 +1,136 @@ +{% load static from staticfiles %} + + + + + + +Oxygen Invoice + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ logo + +
+
+ +
+
+
+
+ + + + + + + + + + +
+ Thank you for your subscription. +
+ Your monthly membership for period {{membership_start_date|date}} - {{membership_start_date|date}} has been charged.
You can view your invoice clicking on the button below. +
+ +
+
+
+
+ + +
+ ungleich
+
+
+
+ + + diff --git a/digitalglarus/templates/digitalglarus/membership_deactivated.html b/digitalglarus/templates/digitalglarus/membership_deactivated.html new file mode 100644 index 00000000..3bfe3809 --- /dev/null +++ b/digitalglarus/templates/digitalglarus/membership_deactivated.html @@ -0,0 +1,62 @@ +{% extends "new_base_glarus.html" %} +{% load staticfiles cms_tags bootstrap3%} +{% block title %}crowdfunding{% endblock %} + +{% block content %} +
+ + + + +
+
+
+
+
+
+ Digital Glarus
+ In der Au 7 Schwanden 8762 Switzerland +
info@digitalglarus.ch +
+ (044) 534-66-22 +

 

+
+
+

 

+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/digitalglarus/templates/digitalglarus/membership_orders_detail.html b/digitalglarus/templates/digitalglarus/membership_orders_detail.html index a63342f9..ff31eb64 100644 --- a/digitalglarus/templates/digitalglarus/membership_orders_detail.html +++ b/digitalglarus/templates/digitalglarus/membership_orders_detail.html @@ -67,7 +67,7 @@ - + {% if stripe_key %} diff --git a/digitalglarus/templates/digitalglarus/membership_orders_list.html b/digitalglarus/templates/digitalglarus/membership_orders_list.html index eebf0f7b..159e1379 100644 --- a/digitalglarus/templates/digitalglarus/membership_orders_list.html +++ b/digitalglarus/templates/digitalglarus/membership_orders_list.html @@ -9,7 +9,7 @@
-

Your Order History

+

Your Membership History


Member Name

{{request.user.name}}

@@ -17,7 +17,7 @@

Active Membership

{{membership_start_date|date}}-{{membership_end_date|date}}


-

Booking history

+

Orders history

@@ -44,6 +44,22 @@ In der Au 7 8762 Schwanden
Switzerland + +
+

Your Next Membership

+

+ Dates: {{membership_start_date|date}} - {{membership_end_date|date}}
+

+

+ + Deactivate +

+
+
+ You will be charged on the first of the month until you + cancel your subscription. Previous charges won't be refunded. +
+
@@ -64,5 +80,6 @@ + {% endblock %} \ No newline at end of file diff --git a/digitalglarus/urls.py b/digitalglarus/urls.py index 2fbad407..89abd240 100644 --- a/digitalglarus/urls.py +++ b/digitalglarus/urls.py @@ -5,7 +5,7 @@ from . import views from .views import ContactView, IndexView, AboutView, HistoryView, LoginView, SignupView,\ PasswordResetView, PasswordResetConfirmView, MembershipPaymentView, MembershipActivatedView,\ MembershipPricingView, BookingSelectDatesView, BookingPaymentView, OrdersBookingDetailView,\ - BookingOrdersListView, MembershipOrdersListView, OrdersMembershipDetailView + BookingOrdersListView, MembershipOrdersListView, OrdersMembershipDetailView, MembershipDeactivateView # from membership.views import LoginRegistrationView urlpatterns = [ @@ -28,6 +28,8 @@ urlpatterns = [ url(_(r'membership/payment/?$'), MembershipPaymentView.as_view(), name='membership_payment'), url(_(r'membership/activated/?$'), MembershipActivatedView.as_view(), name='membership_activated'), + url(_(r'membership/deactivate/?$'), MembershipDeactivateView.as_view(), + name='membership_deactivate'), url(_(r'membership/pricing/?$'), MembershipPricingView.as_view(), name='membership_pricing'), url(_(r'membership/orders/(?P\d+)/?$'), OrdersMembershipDetailView.as_view(), diff --git a/digitalglarus/views.py b/digitalglarus/views.py index f37dd6eb..5bb7b40b 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -7,7 +7,7 @@ from django.forms import ModelForm from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse_lazy, reverse from django.utils.translation import ugettext_lazy as _ -from django.views.generic import TemplateView +from django.views.generic import TemplateView, UpdateView from django.contrib.auth.mixins import LoginRequiredMixin from django.utils.translation import get_language from djangocms_blog.models import Post @@ -15,8 +15,11 @@ from django.contrib import messages from django.http import JsonResponse from django.views.generic import View, DetailView, ListView + from .models import Supporter from utils.forms import ContactUsForm +from utils.mailer import BaseEmail + from django.views.generic.edit import FormView from membership.calendar.calendar import BookCalendar from membership.models import Calendar as CalendarModel, StripeCustomer @@ -296,12 +299,35 @@ class MembershipPaymentView(LoginRequiredMixin, IsNotMemberMixin, FormView): 'stripe_charge': charge, 'amount': membership_type.first_month_price } - MembershipOrder.create(order_data) + membership_order = MembershipOrder.create(order_data) request.session.update({ 'membership_price': membership.type.first_month_price, 'membership_dates': membership.type.first_month_formated_range }) + + start_m_date, end_m_date = membership_order.first_membership_range_date() + + context = { + 'membership': membership, + 'order': membership_order, + 'membership_start_date': start_m_date, + 'membership_end_date': end_m_date, + 'base_url': "{0}://{1}".format(request.scheme, request.get_host()) + + } + email_data = { + 'subject': 'Your membership has been charged', + 'to': request.user.email, + 'context': context, + 'template_name': 'membership_charge', + 'template_path': 'digitalglarus/emails/' + } + email = BaseEmail(**email_data) + email.send() + import pdb + pdb.set_trace() + return HttpResponseRedirect(reverse('digitalglarus:membership_activated')) else: @@ -322,6 +348,27 @@ class MembershipActivatedView(TemplateView): return context +class MembershipDeactivateView(LoginRequiredMixin, UpdateView): + template_name = "digitalglarus/membership_deactivated.html" + model = Membership + success_url = reverse_lazy('digitalglarus:membership_orders_list') + login_url = reverse_lazy('digitalglarus:login') + fields = '__all__' + + def get_object(self): + 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.deactivate() + return HttpResponseRedirect(self.success_url) + + class MembershipOrdersListView(LoginRequiredMixin, ListView): template_name = "digitalglarus/membership_orders_list.html" context_object_name = "orders"