2017-12-24 13:25:04 +00:00
|
|
|
import logging
|
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
from django.conf import settings
|
2017-01-20 16:33:25 +00:00
|
|
|
from django.shortcuts import render
|
2018-04-19 07:12:54 +00:00
|
|
|
from django.http import HttpResponseRedirect, Http404
|
2016-08-20 05:57:35 +00:00
|
|
|
from django.core.urlresolvers import reverse_lazy, reverse
|
2016-04-12 05:50:15 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
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
|
|
|
from django.views.generic import TemplateView, UpdateView
|
2016-08-20 05:57:35 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2015-09-08 04:23:32 +00:00
|
|
|
from django.utils.translation import get_language
|
|
|
|
from djangocms_blog.models import Post
|
2016-04-07 05:26:50 +00:00
|
|
|
from django.contrib import messages
|
2017-01-20 16:33:25 +00:00
|
|
|
from django.views.generic import DetailView, ListView
|
2016-04-10 21:12:43 +00:00
|
|
|
from utils.forms import ContactUsForm
|
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
|
|
|
from utils.mailer import BaseEmail
|
2016-04-07 05:26:50 +00:00
|
|
|
from django.views.generic.edit import FormView
|
2017-01-20 16:33:25 +00:00
|
|
|
from membership.models import StripeCustomer
|
2017-12-24 13:23:33 +00:00
|
|
|
from utils.views import (
|
|
|
|
LoginViewMixin, SignupViewMixin, PasswordResetViewMixin,
|
|
|
|
PasswordResetConfirmViewMixin
|
|
|
|
)
|
|
|
|
from utils.forms import (
|
|
|
|
PasswordResetRequestForm, UserBillingAddressForm, EditCreditCardForm
|
|
|
|
)
|
2016-08-20 05:57:35 +00:00
|
|
|
from utils.stripe_utils import StripeUtils
|
2016-10-14 04:33:48 +00:00
|
|
|
from utils.models import UserBillingAddress
|
2017-12-27 19:04:20 +00:00
|
|
|
from utils.tasks import send_plain_email_task
|
2016-08-20 05:57:35 +00:00
|
|
|
|
2017-12-24 13:23:33 +00:00
|
|
|
from .forms import (
|
|
|
|
LoginForm, SignupForm, MembershipBillingForm, BookingDateForm,
|
2016-11-28 15:32:37 +00:00
|
|
|
BookingBillingForm, CancelBookingForm
|
2017-12-24 13:23:33 +00:00
|
|
|
)
|
|
|
|
from .models import (
|
|
|
|
MembershipType, Membership, MembershipOrder, Booking, BookingPrice,
|
|
|
|
BookingOrder, BookingCancellation, Supporter
|
|
|
|
)
|
|
|
|
from .mixins import (
|
|
|
|
MembershipRequiredMixin, IsNotMemberMixin, ChangeMembershipStatusMixin
|
|
|
|
)
|
2016-08-31 02:32:45 +00:00
|
|
|
|
2017-12-24 13:25:04 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2016-11-22 00:56:03 +00:00
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
|
|
|
|
class IndexView(TemplateView):
|
2016-10-23 23:09:01 +00:00
|
|
|
template_name = "digitalglarus/index.html"
|
2016-08-20 05:57:35 +00:00
|
|
|
|
|
|
|
|
2016-11-03 17:59:32 +00:00
|
|
|
class SupportusView(TemplateView):
|
|
|
|
template_name = "digitalglarus/supportus.html"
|
|
|
|
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
context = super(SupportusView, self).get_context_data(**kwargs)
|
2016-11-18 02:08:16 +00:00
|
|
|
tags = ["dg-renovation"]
|
2016-11-03 17:59:32 +00:00
|
|
|
posts = Post.objects.filter(tags__name__in=tags, publish=True).translated(get_language())
|
|
|
|
context.update({
|
|
|
|
'post_list': posts
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
class LoginView(LoginViewMixin):
|
|
|
|
template_name = "digitalglarus/login.html"
|
|
|
|
form_class = LoginForm
|
2016-09-20 00:20:57 +00:00
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
# redirect to membership orders list if user has at least one.
|
|
|
|
if self.request.user \
|
|
|
|
and MembershipOrder.objects.filter(customer__user=self.request.user):
|
|
|
|
|
|
|
|
return reverse_lazy('digitalglarus:membership_orders_list')
|
|
|
|
|
|
|
|
return reverse_lazy('digitalglarus:membership_pricing')
|
2016-08-20 05:57:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SignupView(SignupViewMixin):
|
|
|
|
template_name = "digitalglarus/signup.html"
|
|
|
|
form_class = SignupForm
|
|
|
|
success_url = reverse_lazy('digitalglarus:login')
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetView(PasswordResetViewMixin):
|
|
|
|
template_name = 'digitalglarus/reset_password.html'
|
|
|
|
success_url = reverse_lazy('digitalglarus:login')
|
|
|
|
form_class = PasswordResetRequestForm
|
|
|
|
template_email_path = 'digitalglarus/emails/'
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetConfirmView(PasswordResetConfirmViewMixin):
|
|
|
|
template_name = 'digitalglarus/confirm_reset_password.html'
|
|
|
|
success_url = reverse_lazy('digitalglarus:login')
|
|
|
|
|
|
|
|
|
|
|
|
class HistoryView(TemplateView):
|
|
|
|
template_name = "digitalglarus/history.html"
|
|
|
|
|
2016-08-31 02:32:45 +00:00
|
|
|
def get_context_data(self, *args, **kwargs):
|
2016-08-20 05:57:35 +00:00
|
|
|
context = super(HistoryView, self).get_context_data(**kwargs)
|
|
|
|
supporters = Supporter.objects.all()
|
|
|
|
context.update({
|
|
|
|
'supporters': supporters
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
2016-04-23 17:00:20 +00:00
|
|
|
|
2017-01-20 16:33:25 +00:00
|
|
|
class EditCreditCardView(FormView):
|
|
|
|
template_name = "digitalglarus/edit_credit_card.html"
|
|
|
|
form_class = EditCreditCardForm
|
|
|
|
success_url = reverse_lazy('digitalglarus:booking_payment')
|
|
|
|
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
context = super(EditCreditCardView, self).get_context_data(*args, **kwargs)
|
|
|
|
context.update({
|
|
|
|
'stripe_key': settings.STRIPE_API_PUBLIC_KEY
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
token = form.cleaned_data.get('token')
|
|
|
|
user = self.request.user
|
|
|
|
customer = user.stripecustomer
|
|
|
|
stripe_utls = StripeUtils()
|
|
|
|
card_response = stripe_utls.update_customer_card(customer.stripe_id, token)
|
|
|
|
new_card_data = card_response.get('response_object')
|
|
|
|
self.request.session.update({
|
|
|
|
'new_change_credit_card': new_card_data
|
|
|
|
})
|
|
|
|
|
|
|
|
return super(EditCreditCardView, self).form_valid(form)
|
|
|
|
|
|
|
|
|
2016-09-09 04:24:52 +00:00
|
|
|
class BookingSelectDatesView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
|
2016-08-31 02:32:45 +00:00
|
|
|
template_name = "digitalglarus/booking.html"
|
|
|
|
form_class = BookingDateForm
|
2016-09-06 00:45:45 +00:00
|
|
|
membership_redirect_url = reverse_lazy('digitalglarus:membership_pricing')
|
2016-08-31 02:32:45 +00:00
|
|
|
login_url = reverse_lazy('digitalglarus:login')
|
|
|
|
success_url = reverse_lazy('digitalglarus:booking_payment')
|
|
|
|
|
2016-10-14 06:04:40 +00:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super(BookingSelectDatesView, self).get_form_kwargs()
|
|
|
|
kwargs.update({'user': self.request.user})
|
|
|
|
return kwargs
|
|
|
|
|
2016-08-31 02:32:45 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
user = self.request.user
|
|
|
|
start_date = form.cleaned_data.get('start_date')
|
|
|
|
end_date = form.cleaned_data.get('end_date')
|
2016-09-06 00:45:45 +00:00
|
|
|
booking_days = (end_date - start_date).days + 1
|
2016-09-29 05:04:40 +00:00
|
|
|
|
|
|
|
price_per_day = BookingPrice.objects.get().price_per_day
|
|
|
|
|
2016-10-23 04:15:23 +00:00
|
|
|
original_price, final_price, free_days = Booking.\
|
2016-08-31 02:32:45 +00:00
|
|
|
booking_price(user, start_date, end_date)
|
2016-09-29 05:04:40 +00:00
|
|
|
|
|
|
|
total_discount = price_per_day * free_days
|
|
|
|
|
2016-08-31 02:32:45 +00:00
|
|
|
self.request.session.update({
|
|
|
|
'original_price': original_price,
|
2016-09-29 05:04:40 +00:00
|
|
|
'final_price': final_price,
|
|
|
|
'total_discount': total_discount,
|
|
|
|
'booking_price_per_day': price_per_day,
|
2016-08-31 02:32:45 +00:00
|
|
|
'booking_days': booking_days,
|
|
|
|
'free_days': free_days,
|
|
|
|
'start_date': start_date.strftime('%m/%d/%Y'),
|
|
|
|
'end_date': end_date.strftime('%m/%d/%Y'),
|
2016-10-14 04:33:48 +00:00
|
|
|
'is_free': final_price == 0
|
2016-08-31 02:32:45 +00:00
|
|
|
})
|
|
|
|
return super(BookingSelectDatesView, self).form_valid(form)
|
|
|
|
|
|
|
|
|
2016-09-09 04:24:52 +00:00
|
|
|
class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView):
|
2016-08-31 02:32:45 +00:00
|
|
|
template_name = "digitalglarus/booking_payment.html"
|
|
|
|
form_class = BookingBillingForm
|
2016-09-06 00:45:45 +00:00
|
|
|
membership_redirect_url = reverse_lazy('digitalglarus:membership_pricing')
|
|
|
|
# success_url = reverse_lazy('digitalglarus:booking_payment')
|
2016-09-29 05:04:40 +00:00
|
|
|
booking_needed_fields = ['original_price', 'final_price', 'booking_days', 'free_days',
|
2016-10-23 04:15:23 +00:00
|
|
|
'start_date', 'end_date', 'booking_price_per_day',
|
2016-10-14 04:33:48 +00:00
|
|
|
'total_discount', 'is_free']
|
2016-08-31 02:32:45 +00:00
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
from_booking = all(field in request.session.keys()
|
|
|
|
for field in self.booking_needed_fields)
|
|
|
|
if not from_booking:
|
|
|
|
return HttpResponseRedirect(reverse('digitalglarus:booking'))
|
|
|
|
|
|
|
|
return super(BookingPaymentView, self).dispatch(request, *args, **kwargs)
|
|
|
|
|
2016-09-06 00:45:45 +00:00
|
|
|
def get_success_url(self, order_id):
|
2016-09-06 01:06:20 +00:00
|
|
|
return reverse('digitalglarus:booking_orders_detail', kwargs={'pk': order_id})
|
2016-09-06 00:45:45 +00:00
|
|
|
|
2016-08-31 02:32:45 +00:00
|
|
|
def get_form_kwargs(self):
|
2016-10-14 04:33:48 +00:00
|
|
|
current_billing_address = self.request.user.billing_addresses.first()
|
2016-08-31 02:32:45 +00:00
|
|
|
form_kwargs = super(BookingPaymentView, self).get_form_kwargs()
|
|
|
|
form_kwargs.update({
|
|
|
|
'initial': {
|
|
|
|
'start_date': self.request.session.get('start_date'),
|
|
|
|
'end_date': self.request.session.get('end_date'),
|
2016-09-29 05:04:40 +00:00
|
|
|
'price': self.request.session.get('final_price'),
|
2016-10-14 04:33:48 +00:00
|
|
|
'street_address': current_billing_address.street_address,
|
|
|
|
'city': current_billing_address.city,
|
|
|
|
'postal_code': current_billing_address.postal_code,
|
|
|
|
'country': current_billing_address.country,
|
2016-08-31 02:32:45 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return form_kwargs
|
|
|
|
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
context = super(BookingPaymentView, self).get_context_data(*args, **kwargs)
|
|
|
|
|
|
|
|
booking_data = {key: self.request.session.get(key)
|
|
|
|
for key in self.booking_needed_fields}
|
2016-10-14 04:33:48 +00:00
|
|
|
user = self.request.user
|
|
|
|
last_booking_order = BookingOrder.objects.filter(customer__user=user).last()
|
2016-10-14 05:51:39 +00:00
|
|
|
last_membership_order = MembershipOrder.objects.filter(customer__user=user).last()
|
2017-01-20 16:33:25 +00:00
|
|
|
|
|
|
|
# check if user changes his credit card
|
|
|
|
credit_card_data = self.request.session.get('new_change_credit_card')
|
|
|
|
# import pdb
|
|
|
|
# pdb.set_trace()
|
|
|
|
|
|
|
|
if not credit_card_data:
|
|
|
|
credit_card_data = last_booking_order.get_booking_cc_data() if last_booking_order \
|
|
|
|
and last_booking_order.get_booking_cc_data() \
|
|
|
|
else last_membership_order.get_membership_order_cc_data()
|
2016-10-23 04:15:23 +00:00
|
|
|
|
2016-08-31 02:32:45 +00:00
|
|
|
booking_data.update({
|
2016-10-14 05:51:39 +00:00
|
|
|
'credit_card_data': credit_card_data if credit_card_data else None,
|
2016-08-31 02:32:45 +00:00
|
|
|
'stripe_key': settings.STRIPE_API_PUBLIC_KEY
|
|
|
|
})
|
|
|
|
context.update(booking_data)
|
|
|
|
return context
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
data = form.cleaned_data
|
|
|
|
context = self.get_context_data()
|
|
|
|
token = data.get('token')
|
|
|
|
start_date = data.get('start_date')
|
|
|
|
end_date = data.get('end_date')
|
2016-10-14 04:33:48 +00:00
|
|
|
is_free = context.get('is_free')
|
2016-10-23 04:15:23 +00:00
|
|
|
normal_price, final_price, free_days = Booking.\
|
2016-08-31 02:32:45 +00:00
|
|
|
booking_price(self.request.user, start_date, end_date)
|
2016-10-23 04:15:23 +00:00
|
|
|
charge = None
|
2016-08-31 02:32:45 +00:00
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
# if not credit_card_needed:
|
2016-08-31 02:32:45 +00:00
|
|
|
# Get or create stripe customer
|
|
|
|
customer = StripeCustomer.get_or_create(email=self.request.user.email,
|
|
|
|
token=token)
|
|
|
|
if not customer:
|
|
|
|
form.add_error("__all__", "Invalid credit card")
|
|
|
|
return self.render_to_response(self.get_context_data(form=form))
|
|
|
|
|
2016-10-19 04:29:07 +00:00
|
|
|
# If booking is not free, make the stripe charge
|
|
|
|
if not is_free:
|
|
|
|
# Make stripe charge to a customer
|
|
|
|
stripe_utils = StripeUtils()
|
|
|
|
charge_response = stripe_utils.make_charge(amount=final_price,
|
|
|
|
customer=customer.stripe_id)
|
|
|
|
charge = charge_response.get('response_object')
|
2016-10-14 04:33:48 +00:00
|
|
|
|
2016-10-19 04:29:07 +00:00
|
|
|
# Check if the payment was approved
|
|
|
|
if not charge:
|
|
|
|
context.update({
|
|
|
|
'paymentError': charge_response.get('error'),
|
|
|
|
'form': form
|
2016-10-14 04:33:48 +00:00
|
|
|
})
|
2016-10-19 04:29:07 +00:00
|
|
|
return render(self.request, self.template_name, context)
|
2016-10-14 04:33:48 +00:00
|
|
|
|
2016-10-19 04:29:07 +00:00
|
|
|
charge = charge_response.get('response_object')
|
2016-10-14 04:33:48 +00:00
|
|
|
|
2016-10-19 04:29:07 +00:00
|
|
|
# Create Billing Address for Membership Order
|
|
|
|
billing_address = form.save()
|
2016-10-14 04:33:48 +00:00
|
|
|
|
|
|
|
# Create Billing Address for User if he does not have one
|
|
|
|
if not customer.user.billing_addresses.count():
|
|
|
|
data.update({
|
|
|
|
'user': customer.user.id
|
|
|
|
})
|
|
|
|
billing_address_user_form = UserBillingAddressForm(data)
|
|
|
|
billing_address_user_form.is_valid()
|
|
|
|
billing_address_user_form.save()
|
|
|
|
|
2016-10-19 04:29:07 +00:00
|
|
|
# Create Booking
|
2016-08-31 02:32:45 +00:00
|
|
|
booking_data = {
|
|
|
|
'start_date': start_date,
|
|
|
|
'end_date': end_date,
|
|
|
|
'free_days': free_days,
|
2016-09-06 00:45:45 +00:00
|
|
|
'price': normal_price,
|
|
|
|
'final_price': final_price,
|
2016-08-31 02:32:45 +00:00
|
|
|
}
|
|
|
|
booking = Booking.create(booking_data)
|
|
|
|
|
2016-10-19 04:29:07 +00:00
|
|
|
# Create Booking order
|
2016-08-31 02:32:45 +00:00
|
|
|
order_data = {
|
|
|
|
'booking': booking,
|
|
|
|
'customer': customer,
|
|
|
|
'billing_address': billing_address,
|
2016-09-09 04:24:52 +00:00
|
|
|
'stripe_charge': charge,
|
|
|
|
'amount': final_price,
|
|
|
|
'original_price': normal_price,
|
2016-09-29 05:04:40 +00:00
|
|
|
'special_month_price': BookingPrice.objects.last().special_month_price,
|
2016-08-31 02:32:45 +00:00
|
|
|
}
|
2016-09-06 00:45:45 +00:00
|
|
|
order = BookingOrder.create(order_data)
|
2016-08-31 02:32:45 +00:00
|
|
|
|
2016-10-28 16:25:09 +00:00
|
|
|
context = {
|
|
|
|
'booking': booking,
|
|
|
|
'order': order,
|
|
|
|
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host())
|
|
|
|
}
|
|
|
|
|
|
|
|
email_data = {
|
|
|
|
'subject': 'Your booking order has been placed',
|
|
|
|
'to': self.request.user.email,
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'booking_order_email',
|
|
|
|
'template_path': 'digitalglarus/emails/'
|
|
|
|
}
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
|
2016-09-06 00:45:45 +00:00
|
|
|
return HttpResponseRedirect(self.get_success_url(order.id))
|
2016-08-31 02:32:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MembershipPricingView(TemplateView):
|
|
|
|
template_name = "digitalglarus/membership_pricing.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(MembershipPricingView, self).get_context_data(**kwargs)
|
|
|
|
membership_type = MembershipType.objects.last()
|
|
|
|
context.update({
|
|
|
|
'membership_type': membership_type
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
2016-09-09 04:24:52 +00:00
|
|
|
class MembershipPaymentView(LoginRequiredMixin, IsNotMemberMixin, FormView):
|
2016-08-20 05:57:35 +00:00
|
|
|
template_name = "digitalglarus/membership_payment.html"
|
2016-08-31 02:32:45 +00:00
|
|
|
login_url = reverse_lazy('digitalglarus:signup')
|
2016-08-20 05:57:35 +00:00
|
|
|
form_class = MembershipBillingForm
|
2016-09-09 04:24:52 +00:00
|
|
|
already_member_redirect_url = reverse_lazy('digitalglarus:membership_orders_list')
|
2016-08-03 05:50:33 +00:00
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
def get_form_kwargs(self):
|
2016-08-22 07:52:29 +00:00
|
|
|
self.membership_type = MembershipType.objects.get(name='standard')
|
2016-08-20 05:57:35 +00:00
|
|
|
form_kwargs = super(MembershipPaymentView, self).get_form_kwargs()
|
|
|
|
form_kwargs.update({
|
2016-08-22 07:52:29 +00:00
|
|
|
'initial': {
|
|
|
|
'membership_type': self.membership_type.id
|
|
|
|
}
|
2016-08-20 05:57:35 +00:00
|
|
|
})
|
|
|
|
return form_kwargs
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(MembershipPaymentView, self).get_context_data(**kwargs)
|
|
|
|
context.update({
|
2016-08-22 07:52:29 +00:00
|
|
|
'stripe_key': settings.STRIPE_API_PUBLIC_KEY,
|
|
|
|
'membership_type': self.membership_type
|
2016-08-20 05:57:35 +00:00
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
form = self.get_form()
|
|
|
|
|
|
|
|
if form.is_valid():
|
|
|
|
data = form.cleaned_data
|
|
|
|
context = self.get_context_data()
|
|
|
|
token = data.get('token')
|
|
|
|
membership_type = data.get('membership_type')
|
|
|
|
|
|
|
|
# Get or create stripe customer
|
2017-12-24 11:48:03 +00:00
|
|
|
customer = StripeCustomer.get_or_create(
|
|
|
|
email=self.request.user.email, token=token
|
|
|
|
)
|
2016-08-20 05:57:35 +00:00
|
|
|
if not customer:
|
|
|
|
form.add_error("__all__", "Invalid credit card")
|
2017-12-24 11:48:03 +00:00
|
|
|
return self.render_to_response(
|
|
|
|
self.get_context_data(form=form)
|
|
|
|
)
|
2016-08-20 05:57:35 +00:00
|
|
|
|
|
|
|
# Make stripe charge to a customer
|
|
|
|
stripe_utils = StripeUtils()
|
2017-12-24 11:48:03 +00:00
|
|
|
charge_response = stripe_utils.make_charge(
|
|
|
|
amount=membership_type.first_month_price,
|
|
|
|
customer=customer.stripe_id
|
|
|
|
)
|
2016-08-20 05:57:35 +00:00
|
|
|
charge = charge_response.get('response_object')
|
|
|
|
|
|
|
|
# Check if the payment was approved
|
|
|
|
if not charge:
|
|
|
|
context.update({
|
|
|
|
'paymentError': charge_response.get('error'),
|
|
|
|
'form': form
|
|
|
|
})
|
2017-12-27 19:04:20 +00:00
|
|
|
email_to_admin_data = {
|
|
|
|
'subject': "Could not create charge for Digital Glarus "
|
|
|
|
"user: {user}".format(
|
|
|
|
user=self.request.user.email
|
|
|
|
),
|
|
|
|
'from_email': 'info@digitalglarus.ch',
|
|
|
|
'to': ['info@ungleich.ch'],
|
|
|
|
'body': "\n".join(
|
|
|
|
["%s=%s" % (k, v) for (k, v) in
|
|
|
|
charge_response.items()]),
|
|
|
|
}
|
|
|
|
send_plain_email_task.delay(email_to_admin_data)
|
2016-08-20 05:57:35 +00:00
|
|
|
return render(request, self.template_name, context)
|
|
|
|
|
2017-12-23 23:08:17 +00:00
|
|
|
# Subscribe the customer to dg plan from the next month onwards
|
|
|
|
stripe_plan = stripe_utils.get_or_create_stripe_plan(
|
|
|
|
amount=membership_type.price,
|
|
|
|
name='Digital Glarus {sub_type_name} Subscription'.format(
|
|
|
|
sub_type_name=membership_type.name
|
|
|
|
),
|
|
|
|
stripe_plan_id='dg-{sub_type_name}'.format(
|
|
|
|
sub_type_name=membership_type.name
|
|
|
|
)
|
|
|
|
)
|
|
|
|
subscription_result = stripe_utils.subscribe_customer_to_plan(
|
|
|
|
customer.stripe_id,
|
2017-12-24 11:51:16 +00:00
|
|
|
[{"plan": stripe_plan.get('response_object').stripe_plan_id}],
|
|
|
|
trial_end=membership_type.next_month_in_sec_since_epoch
|
2017-12-23 23:08:17 +00:00
|
|
|
)
|
|
|
|
stripe_subscription_obj = subscription_result.get(
|
|
|
|
'response_object'
|
|
|
|
)
|
2017-12-24 11:53:23 +00:00
|
|
|
# Check if call to create subscription was ok
|
2017-12-23 23:21:25 +00:00
|
|
|
if (stripe_subscription_obj is None or
|
2017-12-24 17:33:24 +00:00
|
|
|
(stripe_subscription_obj.status != 'active' and
|
|
|
|
stripe_subscription_obj.status != 'trialing')):
|
2017-12-24 11:53:23 +00:00
|
|
|
context.update({
|
|
|
|
'paymentError': subscription_result.get('error'),
|
|
|
|
'form': form
|
|
|
|
})
|
2017-12-27 19:04:20 +00:00
|
|
|
email_to_admin_data = {
|
|
|
|
'subject': "Could not create Stripe subscription for "
|
|
|
|
"Digital Glarus user: {user}".format(
|
|
|
|
user=self.request.user.email
|
|
|
|
),
|
|
|
|
'from_email': 'info@digitalglarus.ch',
|
|
|
|
'to': ['info@ungleich.ch'],
|
|
|
|
'body': "\n".join(
|
|
|
|
["%s=%s" % (k, v) for (k, v) in
|
|
|
|
subscription_result.items()]),
|
|
|
|
}
|
|
|
|
send_plain_email_task.delay(email_to_admin_data)
|
2017-12-24 11:53:23 +00:00
|
|
|
return render(request, self.template_name, context)
|
2017-12-23 23:08:17 +00:00
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
charge = charge_response.get('response_object')
|
2017-12-23 21:59:16 +00:00
|
|
|
if 'source' in charge:
|
|
|
|
cardholder_name = charge['source']['name']
|
|
|
|
else:
|
2017-12-23 22:07:53 +00:00
|
|
|
cardholder_name = customer.user.name
|
2016-08-22 07:52:29 +00:00
|
|
|
|
|
|
|
# Create Billing Address
|
|
|
|
billing_address = form.save()
|
|
|
|
|
2016-10-14 04:50:13 +00:00
|
|
|
# Create Billing Address for User if he does not have one
|
|
|
|
if not customer.user.billing_addresses.count():
|
|
|
|
data.update({
|
2017-12-23 21:59:16 +00:00
|
|
|
'user': customer.user.id,
|
|
|
|
'cardholder_name': cardholder_name
|
2016-10-14 04:50:13 +00:00
|
|
|
})
|
|
|
|
billing_address_user_form = UserBillingAddressForm(data)
|
|
|
|
billing_address_user_form.is_valid()
|
|
|
|
billing_address_user_form.save()
|
|
|
|
|
2016-10-19 04:29:07 +00:00
|
|
|
# Get membership dates
|
|
|
|
membership_start_date, membership_end_date = membership_type.first_month_range
|
|
|
|
|
2016-11-01 04:01:43 +00:00
|
|
|
# Create or update membership plan
|
2016-10-19 04:29:07 +00:00
|
|
|
membership_data = {
|
|
|
|
'type': membership_type,
|
2016-11-01 04:01:43 +00:00
|
|
|
'active': True,
|
2016-10-19 04:29:07 +00:00
|
|
|
'start_date': membership_start_date,
|
|
|
|
'end_date': membership_end_date
|
|
|
|
}
|
2016-11-01 04:01:43 +00:00
|
|
|
membership = Membership.activate_or_crete(membership_data, self.request.user)
|
2016-08-22 07:52:29 +00:00
|
|
|
|
|
|
|
# Create membership order
|
|
|
|
order_data = {
|
|
|
|
'membership': membership,
|
|
|
|
'customer': customer,
|
|
|
|
'billing_address': billing_address,
|
2016-09-09 04:24:52 +00:00
|
|
|
'stripe_charge': charge,
|
2017-12-24 11:54:59 +00:00
|
|
|
'stripe_subscription_id': stripe_subscription_obj.id,
|
2016-10-19 04:29:07 +00:00
|
|
|
'amount': membership_type.first_month_price,
|
|
|
|
'start_date': membership_start_date,
|
|
|
|
'end_date': membership_end_date
|
2016-08-22 07:52:29 +00:00
|
|
|
}
|
2016-10-14 04:33:48 +00:00
|
|
|
|
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
|
|
|
membership_order = MembershipOrder.create(order_data)
|
2016-08-22 07:52:29 +00:00
|
|
|
|
|
|
|
request.session.update({
|
|
|
|
'membership_price': membership.type.first_month_price,
|
|
|
|
'membership_dates': membership.type.first_month_formated_range
|
|
|
|
})
|
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
|
|
|
|
2018-08-10 19:16:53 +00:00
|
|
|
email_to_admin_data = {
|
|
|
|
'subject': "New Digital Glarus subscription: {user}".format(
|
|
|
|
user=self.request.user.email
|
|
|
|
),
|
|
|
|
'from_email': 'info@digitalglarus.ch',
|
|
|
|
'to': ['info@ungleich.ch'],
|
|
|
|
'body': "\n".join(
|
|
|
|
["%s=%s" % (k, v) for (k, v) in
|
|
|
|
order_data.items()]),
|
|
|
|
}
|
|
|
|
send_plain_email_task.delay(email_to_admin_data)
|
|
|
|
|
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
|
|
|
context = {
|
|
|
|
'membership': membership,
|
|
|
|
'order': membership_order,
|
2016-10-19 04:29:07 +00:00
|
|
|
'membership_start_date': membership_start_date,
|
|
|
|
'membership_end_date': membership_end_date,
|
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
|
|
|
'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()
|
|
|
|
|
2016-08-22 07:52:29 +00:00
|
|
|
return HttpResponseRedirect(reverse('digitalglarus:membership_activated'))
|
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
else:
|
|
|
|
return self.form_invalid(form)
|
|
|
|
|
|
|
|
|
2016-08-22 07:52:29 +00:00
|
|
|
class MembershipActivatedView(TemplateView):
|
|
|
|
template_name = "digitalglarus/membership_activated.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(MembershipActivatedView, self).get_context_data(**kwargs)
|
|
|
|
membership_price = self.request.session.get('membership_price')
|
|
|
|
membership_dates = self.request.session.get('membership_dates')
|
|
|
|
context.update({
|
|
|
|
'membership_price': membership_price,
|
|
|
|
'membership_dates': membership_dates,
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
2016-08-20 05:57:35 +00:00
|
|
|
|
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
|
|
|
class MembershipDeactivateView(LoginRequiredMixin, UpdateView):
|
|
|
|
template_name = "digitalglarus/membership_deactivated.html"
|
|
|
|
model = Membership
|
2016-10-14 04:33:48 +00:00
|
|
|
success_message = "Your membership has been deactivated :("
|
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
|
|
|
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()
|
2017-12-24 13:25:04 +00:00
|
|
|
messages.add_message(
|
|
|
|
self.request, messages.SUCCESS, self.success_message
|
|
|
|
)
|
|
|
|
# cancel Stripe subscription
|
|
|
|
stripe_utils = StripeUtils()
|
|
|
|
membership_order = MembershipOrder.objects.filter(
|
|
|
|
customer__user=self.request.user
|
|
|
|
).last()
|
2017-12-24 13:38:32 +00:00
|
|
|
if membership_order:
|
2017-12-24 14:04:20 +00:00
|
|
|
if membership_order.stripe_subscription_id:
|
2017-12-24 13:38:32 +00:00
|
|
|
result = stripe_utils.unsubscribe_customer(
|
2017-12-24 14:04:20 +00:00
|
|
|
subscription_id=membership_order.stripe_subscription_id
|
2017-12-24 13:38:32 +00:00
|
|
|
)
|
|
|
|
stripe_subscription_obj = result.get('response_object')
|
|
|
|
# Check if the subscription was canceled
|
|
|
|
if (stripe_subscription_obj is None or
|
|
|
|
stripe_subscription_obj.status != 'canceled'):
|
|
|
|
error_msg = result.get('error')
|
|
|
|
logger.error(
|
|
|
|
"Could not cancel Digital Glarus subscription. "
|
|
|
|
"Reason: {reason}".format(
|
|
|
|
reason=error_msg
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
2017-12-24 13:25:04 +00:00
|
|
|
logger.error(
|
2017-12-24 13:38:32 +00:00
|
|
|
"User {user} may have Stripe subscriptions created "
|
|
|
|
"manually. Please check.".format(
|
|
|
|
user=self.request.user.name
|
2017-12-24 13:25:04 +00:00
|
|
|
)
|
|
|
|
)
|
2017-12-24 13:38:32 +00:00
|
|
|
else:
|
|
|
|
logger.error(
|
|
|
|
"MembershipOrder for {user} not found".format(
|
|
|
|
user=self.request.user.name
|
|
|
|
)
|
|
|
|
)
|
2016-10-14 04:33:48 +00:00
|
|
|
|
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 HttpResponseRedirect(self.success_url)
|
|
|
|
|
|
|
|
|
2016-11-01 04:01:43 +00:00
|
|
|
class MembershipReactivateView(ChangeMembershipStatusMixin):
|
|
|
|
success_message = "Your membership has been reactivate :)"
|
|
|
|
template_name = "digitalglarus/membership_orders_list.html"
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
membership = self.get_object()
|
|
|
|
membership.activate()
|
|
|
|
return super(MembershipReactivateView, self).post(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
class UserBillingAddressView(LoginRequiredMixin, UpdateView):
|
|
|
|
model = UserBillingAddress
|
|
|
|
form_class = UserBillingAddressForm
|
2016-10-14 04:50:13 +00:00
|
|
|
template_name = "digitalglarus/user_billing_address.html"
|
2016-10-14 04:33:48 +00:00
|
|
|
success_url = reverse_lazy('digitalglarus:user_billing_address')
|
2016-10-14 06:17:10 +00:00
|
|
|
success_message = "Billing Address Updated"
|
|
|
|
|
2016-10-19 04:29:07 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
next_url = self.request.POST.get('next') if self.request.POST.get('next')\
|
|
|
|
else self.success_url
|
|
|
|
|
|
|
|
return next_url
|
|
|
|
|
2016-12-05 00:44:26 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(UserBillingAddressView, self).get_context_data(**kwargs)
|
2017-01-16 16:03:23 +00:00
|
|
|
current_billing_address = self.request.user.billing_addresses.all().first()
|
2016-12-05 00:44:26 +00:00
|
|
|
context.update({
|
|
|
|
'current_billing_address': current_billing_address
|
|
|
|
})
|
2017-01-16 16:03:23 +00:00
|
|
|
return context
|
2016-12-05 00:44:26 +00:00
|
|
|
|
2016-10-14 06:17:10 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
"""
|
|
|
|
If the form is valid, save the associated model.
|
|
|
|
"""
|
|
|
|
messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
|
|
|
self.object = form.save()
|
|
|
|
return super(UserBillingAddressView, self).form_valid(form)
|
2016-10-14 04:33:48 +00:00
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
current_billing_address = self.request.user.billing_addresses.first()
|
|
|
|
form_kwargs = super(UserBillingAddressView, self).get_form_kwargs()
|
2016-10-14 04:50:13 +00:00
|
|
|
|
|
|
|
if not current_billing_address:
|
|
|
|
return form_kwargs
|
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
form_kwargs.update({
|
|
|
|
'initial': {
|
|
|
|
'street_address': current_billing_address.street_address,
|
|
|
|
'city': current_billing_address.city,
|
|
|
|
'postal_code': current_billing_address.postal_code,
|
|
|
|
'country': current_billing_address.country,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return form_kwargs
|
|
|
|
|
|
|
|
def get_object(self):
|
2017-01-16 16:03:23 +00:00
|
|
|
current_billing_address = self.request.user.\
|
|
|
|
billing_addresses.filter(current=True).last()
|
2016-12-05 00:44:26 +00:00
|
|
|
# if not current_billing_address:
|
|
|
|
# raise AttributeError("Billing Address does not exists")
|
2016-10-14 04:33:48 +00:00
|
|
|
return current_billing_address
|
|
|
|
|
|
|
|
|
2016-09-20 00:20:57 +00:00
|
|
|
class MembershipDeactivateSuccessView(LoginRequiredMixin, TemplateView):
|
|
|
|
template_name = "digitalglarus/membership_deactivated_success.html"
|
|
|
|
|
|
|
|
|
2016-09-09 04:24:52 +00:00
|
|
|
class MembershipOrdersListView(LoginRequiredMixin, ListView):
|
|
|
|
template_name = "digitalglarus/membership_orders_list.html"
|
|
|
|
context_object_name = "orders"
|
|
|
|
login_url = reverse_lazy('digitalglarus:login')
|
|
|
|
model = MembershipOrder
|
|
|
|
paginate_by = 10
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(MembershipOrdersListView, self).get_context_data(**kwargs)
|
2016-11-01 04:01:43 +00:00
|
|
|
current_membership = Membership.get_current_membership(self.request.user)
|
|
|
|
start_date, end_date = (current_membership.start_date, current_membership.end_date)\
|
|
|
|
if current_membership else [None, None]
|
|
|
|
|
2016-10-23 23:09:01 +00:00
|
|
|
next_start_date, next_end_date = MembershipOrder.next_membership_dates(self.request.user)
|
2016-10-14 04:33:48 +00:00
|
|
|
current_billing_address = self.request.user.billing_addresses.filter(current=True).last()
|
2016-09-09 04:24:52 +00:00
|
|
|
context.update({
|
|
|
|
'membership_start_date': start_date,
|
|
|
|
'membership_end_date': end_date,
|
2016-11-01 04:01:43 +00:00
|
|
|
'current_membership': current_membership,
|
2016-10-23 23:09:01 +00:00
|
|
|
'next_membership_start_date': next_start_date,
|
|
|
|
'next_membership_end_date': next_end_date,
|
2016-10-14 04:33:48 +00:00
|
|
|
'billing_address': current_billing_address
|
2016-09-09 04:24:52 +00:00
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
queryset = super(MembershipOrdersListView, self).get_queryset()
|
|
|
|
queryset = queryset.filter(customer__user=self.request.user)
|
|
|
|
return queryset
|
|
|
|
|
|
|
|
|
|
|
|
class OrdersMembershipDetailView(LoginRequiredMixin, DetailView):
|
|
|
|
template_name = "digitalglarus/membership_orders_detail.html"
|
|
|
|
context_object_name = "order"
|
|
|
|
login_url = reverse_lazy('digitalglarus:login')
|
|
|
|
# permission_required = ['view_hostingorder']
|
|
|
|
model = MembershipOrder
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(OrdersMembershipDetailView, self).get_context_data(**kwargs)
|
|
|
|
start_date, end_date = self.object.get_membership_range_date()
|
|
|
|
context.update({
|
|
|
|
'membership_start_date': start_date,
|
|
|
|
'membership_end_date': end_date,
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
2016-11-28 15:32:37 +00:00
|
|
|
class OrdersBookingDetailView(LoginRequiredMixin, UpdateView):
|
2016-09-06 00:45:45 +00:00
|
|
|
template_name = "digitalglarus/booking_orders_detail.html"
|
|
|
|
context_object_name = "order"
|
|
|
|
login_url = reverse_lazy('digitalglarus:login')
|
2016-11-28 15:32:37 +00:00
|
|
|
form_class = CancelBookingForm
|
|
|
|
success_message = "You booking has been cancelled"
|
2016-09-06 00:45:45 +00:00
|
|
|
# permission_required = ['view_hostingorder']
|
|
|
|
model = BookingOrder
|
|
|
|
|
2016-11-28 15:32:37 +00:00
|
|
|
def get_success_url(self):
|
|
|
|
pk = self.kwargs.get(self.pk_url_kwarg)
|
|
|
|
return reverse_lazy('digitalglarus:booking_orders_detail', kwargs={'pk': pk})
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
|
|
|
|
booking_order = self.get_object()
|
|
|
|
booking_order.cancel()
|
|
|
|
request = self.request
|
|
|
|
|
2016-12-05 00:44:26 +00:00
|
|
|
BookingCancellation.create(booking_order)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
'order': booking_order,
|
|
|
|
'booking': booking_order.booking,
|
|
|
|
'base_url': "{0}://{1}".format(request.scheme, request.get_host()),
|
|
|
|
'user': request.user
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
email_data = {
|
|
|
|
'subject': 'A cancellation has been requested',
|
|
|
|
'to': 'info@ungleich.ch',
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'booking_cancellation_notification',
|
|
|
|
'template_path': 'digitalglarus/emails/'
|
|
|
|
}
|
|
|
|
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
|
2016-11-28 15:32:37 +00:00
|
|
|
context = {
|
|
|
|
'order': booking_order,
|
|
|
|
'booking': booking_order.booking,
|
|
|
|
'base_url': "{0}://{1}".format(request.scheme, request.get_host())
|
|
|
|
|
|
|
|
}
|
|
|
|
email_data = {
|
2016-12-05 00:44:26 +00:00
|
|
|
'subject': 'Your booking has been cancelled',
|
2016-11-28 15:32:37 +00:00
|
|
|
'to': request.user.email,
|
|
|
|
'context': context,
|
|
|
|
'template_name': 'booking_cancellation',
|
|
|
|
'template_path': 'digitalglarus/emails/'
|
|
|
|
}
|
|
|
|
email = BaseEmail(**email_data)
|
|
|
|
email.send()
|
|
|
|
|
|
|
|
messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
|
|
|
|
|
|
|
return HttpResponseRedirect(self.get_success_url())
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2016-09-06 00:45:45 +00:00
|
|
|
|
|
|
|
context = super(OrdersBookingDetailView, self).get_context_data(**kwargs)
|
|
|
|
|
|
|
|
bookig_order = self.object
|
|
|
|
booking = bookig_order.booking
|
|
|
|
|
|
|
|
start_date = booking.start_date
|
|
|
|
end_date = booking.end_date
|
|
|
|
free_days = booking.free_days
|
|
|
|
|
|
|
|
booking_days = (end_date - start_date).days + 1
|
|
|
|
original_price = booking.price
|
|
|
|
final_price = booking.final_price
|
2016-09-29 05:04:40 +00:00
|
|
|
|
2016-09-06 00:45:45 +00:00
|
|
|
context.update({
|
|
|
|
'original_price': original_price,
|
|
|
|
'total_discount': original_price - final_price,
|
|
|
|
'final_price': final_price,
|
|
|
|
'booking_days': booking_days,
|
|
|
|
'free_days': free_days,
|
|
|
|
'start_date': start_date.strftime('%m/%d/%Y'),
|
|
|
|
'end_date': end_date.strftime('%m/%d/%Y'),
|
2016-12-07 02:47:59 +00:00
|
|
|
'booking_required': bookig_order.refund_required(),
|
2016-09-06 00:45:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class BookingOrdersListView(LoginRequiredMixin, ListView):
|
|
|
|
template_name = "digitalglarus/booking_orders_list.html"
|
|
|
|
context_object_name = "orders"
|
|
|
|
login_url = reverse_lazy('digitalglarus:login')
|
|
|
|
model = BookingOrder
|
|
|
|
paginate_by = 10
|
|
|
|
|
2016-10-14 04:33:48 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(BookingOrdersListView, self).get_context_data(**kwargs)
|
|
|
|
current_billing_address = self.request.user.billing_addresses.filter(current=True).last()
|
|
|
|
context.update({
|
|
|
|
'billing_address': current_billing_address
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
2016-09-06 00:45:45 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
queryset = super(BookingOrdersListView, self).get_queryset()
|
|
|
|
queryset = queryset.filter(customer__user=self.request.user)
|
|
|
|
return queryset
|
|
|
|
|
|
|
|
|
2016-04-07 05:26:50 +00:00
|
|
|
class ContactView(FormView):
|
|
|
|
template_name = 'contact.html'
|
|
|
|
form_class = ContactUsForm
|
2016-04-10 21:12:43 +00:00
|
|
|
success_url = reverse_lazy('digitalglarus:contact')
|
2016-04-07 05:26:50 +00:00
|
|
|
success_message = _('Message Successfully Sent')
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
2023-11-17 02:39:12 +00:00
|
|
|
print("digital glarus contactusform")
|
2023-11-17 02:29:10 +00:00
|
|
|
#form.save()
|
|
|
|
#form.send_email()
|
|
|
|
#messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
2016-04-07 05:26:50 +00:00
|
|
|
return super(ContactView, self).form_valid(form)
|
2015-05-02 20:42:08 +00:00
|
|
|
|
2017-06-29 14:34:40 +00:00
|
|
|
|
|
|
|
# OLD VIEWS
|
|
|
|
|
2015-09-08 04:23:32 +00:00
|
|
|
|
|
|
|
def blog(request):
|
2015-09-26 19:42:46 +00:00
|
|
|
tags = ["digitalglarus"]
|
2018-04-19 07:23:22 +00:00
|
|
|
posts = (Post.objects
|
|
|
|
.filter(tags__name__in=tags, publish=True)
|
|
|
|
.translated(get_language()))
|
2015-09-08 04:23:32 +00:00
|
|
|
context = {
|
|
|
|
'post_list': posts,
|
|
|
|
}
|
|
|
|
return render(request, 'glarus_blog/post_list.html', context)
|
|
|
|
|
|
|
|
|
|
|
|
def blog_detail(request, slug):
|
2016-07-01 05:40:39 +00:00
|
|
|
post = Post.objects.translated(get_language(), slug=slug).first()
|
2018-04-19 07:12:54 +00:00
|
|
|
if post is None:
|
|
|
|
raise Http404()
|
2015-09-08 04:23:32 +00:00
|
|
|
context = {
|
|
|
|
'post': post,
|
|
|
|
}
|
2016-04-09 06:51:20 +00:00
|
|
|
return render(request, 'glarus_blog/post_detail.html', context)
|
2016-02-03 13:27:29 +00:00
|
|
|
|
2016-04-07 05:26:50 +00:00
|
|
|
|
2016-04-04 01:39:57 +00:00
|
|
|
def support(request):
|
2016-04-04 02:28:04 +00:00
|
|
|
return render(request, 'support.html')
|
2016-02-03 13:27:29 +00:00
|
|
|
|
2016-04-07 05:26:50 +00:00
|
|
|
|
2016-02-03 13:27:29 +00:00
|
|
|
def supporters(request):
|
|
|
|
context = {
|
|
|
|
'supporters': Supporter.objects.order_by('name')
|
|
|
|
}
|
2016-04-01 10:37:01 +00:00
|
|
|
return render(request, 'supporters.html', context)
|