forked from ungleich-public/dynamicweb
Fix the login page and other views for current Django (is_authenticated is a property, method decorators)
This commit is contained in:
parent
de505d3845
commit
4321bf6b55
11 changed files with 36 additions and 33 deletions
|
|
@ -13,6 +13,7 @@ from django.http import (
|
|||
)
|
||||
from django.shortcuts import render
|
||||
from django.utils.translation import get_language, gettext_lazy as _
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.cache import cache_control
|
||||
from django.views.generic import FormView, CreateView, DetailView
|
||||
|
||||
|
|
@ -131,7 +132,7 @@ class IndexView(CreateView):
|
|||
if (value > 2000) or (value < 10):
|
||||
raise ValidationError(_('Invalid storage size'))
|
||||
|
||||
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
||||
@method_decorator(cache_control(no_cache=True, must_revalidate=True, no_store=True))
|
||||
def get(self, request, *args, **kwargs):
|
||||
clear_all_session_vars(request)
|
||||
return HttpResponseRedirect(reverse('datacenterlight:cms_index'))
|
||||
|
|
@ -242,7 +243,7 @@ class PaymentOrderView(FormView):
|
|||
template_name = 'datacenterlight/landing_payment.html'
|
||||
|
||||
def get_form_class(self):
|
||||
if self.request.user.is_authenticated():
|
||||
if self.request.user.is_authenticated:
|
||||
return BillingAddressForm
|
||||
else:
|
||||
return BillingAddressFormSignup
|
||||
|
|
@ -254,7 +255,7 @@ class PaymentOrderView(FormView):
|
|||
else:
|
||||
billing_address_data = {}
|
||||
|
||||
if self.request.user.is_authenticated():
|
||||
if self.request.user.is_authenticated:
|
||||
if billing_address_data:
|
||||
billing_address_form = BillingAddressForm(
|
||||
initial=billing_address_data
|
||||
|
|
@ -315,7 +316,7 @@ class PaymentOrderView(FormView):
|
|||
|
||||
return context
|
||||
|
||||
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
||||
@method_decorator(cache_control(no_cache=True, must_revalidate=True, no_store=True))
|
||||
def get(self, request, *args, **kwargs):
|
||||
request.session.pop('vat_validation_status')
|
||||
request.session.pop('card_id')
|
||||
|
|
@ -403,7 +404,7 @@ class PaymentOrderView(FormView):
|
|||
context = self.get_context_data()
|
||||
context['login_form'] = login_form
|
||||
return self.render_to_response(context)
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
address_form = BillingAddressForm(
|
||||
data=request.POST,
|
||||
)
|
||||
|
|
@ -478,7 +479,7 @@ class PaymentOrderView(FormView):
|
|||
id_payment_method = address_form.cleaned_data.get('card')
|
||||
request.session["id_payment_method"] = id_payment_method
|
||||
logger.debug("id_payment_method is %s" % id_payment_method)
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
this_user = {
|
||||
'email': request.user.email,
|
||||
'name': request.user.name
|
||||
|
|
@ -585,7 +586,7 @@ class OrderConfirmationView(DetailView, FormView):
|
|||
kwargs.update({'request': self.request})
|
||||
return kwargs
|
||||
|
||||
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
||||
@method_decorator(cache_control(no_cache=True, must_revalidate=True, no_store=True))
|
||||
def get(self, request, *args, **kwargs):
|
||||
context = {}
|
||||
# this is amount to be charge/subscribed before VAT and discount
|
||||
|
|
@ -762,7 +763,7 @@ class OrderConfirmationView(DetailView, FormView):
|
|||
'msg_body': _("Your product will be provisioned as soon as "
|
||||
"we receive the payment."),
|
||||
'redirect': reverse('hosting:invoices') if
|
||||
request.user.is_authenticated() else
|
||||
request.user.is_authenticated else
|
||||
reverse('datacenterlight:index')
|
||||
},
|
||||
'stripe_key': settings.STRIPE_API_PUBLIC_KEY,
|
||||
|
|
@ -1046,7 +1047,7 @@ class OrderConfirmationView(DetailView, FormView):
|
|||
latest_invoice.payment_intent
|
||||
)
|
||||
# TODO: requires_attention is probably wrong value to compare
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
if 'generic_payment_details' in request.session:
|
||||
redirect_url = reverse('hosting:invoices')
|
||||
else:
|
||||
|
|
@ -1128,7 +1129,7 @@ class OrderConfirmationView(DetailView, FormView):
|
|||
'status': True,
|
||||
'redirect': (
|
||||
reverse('hosting:virtual_machines')
|
||||
if request.user.is_authenticated()
|
||||
if request.user.is_authenticated
|
||||
else reverse('datacenterlight:index')
|
||||
),
|
||||
'msg_title': str(_('Thank you for the order.')),
|
||||
|
|
@ -1592,7 +1593,7 @@ def do_provisioning(request, stripe_api_cus_id, card_details_response,
|
|||
logger.debug("Sent user/admin emails")
|
||||
if real_request:
|
||||
clear_all_session_vars(real_request)
|
||||
if real_request.user.is_authenticated():
|
||||
if real_request.user.is_authenticated:
|
||||
redirect_url = reverse('hosting:invoices')
|
||||
logger.debug("redirect_url = %s " % redirect_url)
|
||||
response = {
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ class UserHostingKeyForm(forms.ModelForm):
|
|||
return self.data.get('name')
|
||||
|
||||
def clean_user(self):
|
||||
return self.request.user if self.request.user.is_authenticated() else None
|
||||
return self.request.user if self.request.user.is_authenticated else None
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = self.cleaned_data
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class ProcessVMSelectionMixin(object):
|
|||
request.session['template'] = data
|
||||
request.session['specs'] = configuration.serialize()
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
if not request.user.is_authenticated:
|
||||
request.session['next'] = reverse('hosting:payment')
|
||||
return redirect(reverse('hosting:login'))
|
||||
return redirect(reverse('hosting:payment'))
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ class SignupView(HostingContextMixin, CreateView):
|
|||
|
||||
@method_decorator(decorators)
|
||||
def get(self, request, *args, **kwargs):
|
||||
if self.request.user.is_authenticated():
|
||||
if self.request.user.is_authenticated:
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
return super(SignupView, self).get(request, *args, **kwargs)
|
||||
|
||||
|
|
@ -355,7 +355,7 @@ class SignupValidatedView(SignupValidateView, HostingContextMixin):
|
|||
|
||||
@method_decorator(decorators)
|
||||
def get(self, request, *args, **kwargs):
|
||||
if self.request.user.is_authenticated():
|
||||
if self.request.user.is_authenticated:
|
||||
return HttpResponseRedirect(reverse_lazy('hosting:dashboard'))
|
||||
return super(SignupValidatedView, self).get(request, *args, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from django.shortcuts import render, redirect
|
||||
from django.views.generic import View
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.cache import cache_control
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
|
|
@ -43,7 +44,7 @@ class CreditCardView(View):
|
|||
context['form'] = PaymentForm()
|
||||
return context
|
||||
|
||||
@cache_control(no_cache=True, must_revalidate=True)
|
||||
@method_decorator(cache_control(no_cache=True, must_revalidate=True))
|
||||
def get(self, request, time=None):
|
||||
context = self._get_context(request, time)
|
||||
next = request.session.get('next')
|
||||
|
|
@ -83,7 +84,7 @@ class LoginRegistrationView(View):
|
|||
login_form = LoginForm()
|
||||
register_form = RegisterForm()
|
||||
request.session['next'] = None
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
return redirect("membership")
|
||||
else:
|
||||
return render(request, 'templates/login.html',
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ class LandingView(TemplateView):
|
|||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
|
||||
allow_donation = self.request.user.is_anonymous() or \
|
||||
(self.request.user.is_authenticated() and
|
||||
allow_donation = self.request.user.is_anonymous or \
|
||||
(self.request.user.is_authenticated and
|
||||
not DonatorStatus.objects.filter(user=self.request.user).exists())
|
||||
|
||||
total_donations_amount = Donation.get_total_donations_amount()
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ class DefaultBackend(StoredMessagesBackend):
|
|||
|
||||
"""
|
||||
def inbox_list(self, user):
|
||||
if user.is_anonymous():
|
||||
if user.is_anonymous:
|
||||
return []
|
||||
inbox = Inbox.objects.filter(user=user).select_related("message")
|
||||
return [m.message for m in inbox]
|
||||
|
||||
def inbox_purge(self, user):
|
||||
if user.is_authenticated():
|
||||
if user.is_authenticated:
|
||||
Inbox.objects.filter(user=user).delete()
|
||||
signals.inbox_purged.send(sender=self.__class__, user=user)
|
||||
|
||||
|
|
|
|||
|
|
@ -78,12 +78,12 @@ class RedisBackend(StoredMessagesBackend):
|
|||
return Message(id=msg_id, message=msg_text, level=level, tags=extra_tags, date=r, url=url)
|
||||
|
||||
def inbox_list(self, user):
|
||||
if user.is_anonymous():
|
||||
if user.is_anonymous:
|
||||
return []
|
||||
return self._list('user:%d:notifications', user)
|
||||
|
||||
def inbox_purge(self, user):
|
||||
if user.is_authenticated():
|
||||
if user.is_authenticated:
|
||||
self.client.delete('user:%d:notifications' % user.pk)
|
||||
self.client.delete('user:%d:notificationsidx' % user.pk)
|
||||
signals.inbox_purged.send(sender=self.__class__, user=user)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class StorageMixin(object):
|
|||
from other storages
|
||||
"""
|
||||
messages, all_retrieved = super(StorageMixin, self)._get(*args, **kwargs)
|
||||
if self.user.is_authenticated():
|
||||
if self.user.is_authenticated:
|
||||
inbox_messages = self.backend.inbox_list(self.user)
|
||||
else:
|
||||
inbox_messages = []
|
||||
|
|
@ -51,7 +51,7 @@ class StorageMixin(object):
|
|||
if level < self.level:
|
||||
return
|
||||
# Check if the message doesn't have a level that needs to be persisted
|
||||
if level not in stored_messages_settings.STORE_LEVELS or self.user.is_anonymous():
|
||||
if level not in stored_messages_settings.STORE_LEVELS or self.user.is_anonymous:
|
||||
return super(StorageMixin, self).add(level, message, extra_tags)
|
||||
|
||||
self.added_new = True
|
||||
|
|
@ -70,7 +70,7 @@ class StorageMixin(object):
|
|||
else contains both new and unread messages
|
||||
"""
|
||||
contrib_messages = []
|
||||
if self.user.is_authenticated():
|
||||
if self.user.is_authenticated:
|
||||
if not messages:
|
||||
# erase inbox
|
||||
self.backend.inbox_purge(self.user)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ def stored_messages_list(context, num_elements=10):
|
|||
"""
|
||||
if "user" in context:
|
||||
user = context["user"]
|
||||
if user.is_authenticated():
|
||||
if user.is_authenticated:
|
||||
qs = Inbox.objects.select_related("message").filter(user=user)
|
||||
return {
|
||||
"messages": qs[:num_elements],
|
||||
|
|
@ -30,7 +30,7 @@ def stored_messages_count(context):
|
|||
"""
|
||||
if "user" in context:
|
||||
user = context["user"]
|
||||
if user.is_authenticated():
|
||||
if user.is_authenticated:
|
||||
return Inbox.objects.select_related("message").filter(user=user).count()
|
||||
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ def stored_messages_archive(context, num_elements=10):
|
|||
"""
|
||||
if "user" in context:
|
||||
user = context["user"]
|
||||
if user.is_authenticated():
|
||||
if user.is_authenticated:
|
||||
qs = MessageArchive.objects.select_related("message").filter(user=user)
|
||||
return {
|
||||
"messages": qs[:num_elements],
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from django.shortcuts import render
|
|||
from django.utils.encoding import force_bytes
|
||||
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.cache import cache_control
|
||||
from django.views.generic import FormView, CreateView
|
||||
|
||||
|
|
@ -67,9 +68,9 @@ class LoginViewMixin(FormView):
|
|||
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
||||
@method_decorator(cache_control(no_cache=True, must_revalidate=True, no_store=True))
|
||||
def get(self, request, *args, **kwargs):
|
||||
if self.request.user.is_authenticated():
|
||||
if self.request.user.is_authenticated:
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
return super(LoginViewMixin, self).get(request, *args, **kwargs)
|
||||
|
|
@ -225,7 +226,7 @@ class SSHKeyCreateView(FormView):
|
|||
'form': UserHostingKeyForm(request=self.request),
|
||||
})
|
||||
|
||||
if self.request.user.is_authenticated():
|
||||
if self.request.user.is_authenticated:
|
||||
owner = self.request.user
|
||||
manager = OpenNebulaManager(
|
||||
email=owner.username,
|
||||
|
|
@ -254,7 +255,7 @@ class AskSSHKeyView(SSHKeyCreateView):
|
|||
success_url = reverse_lazy('datacenterlight:order_confirmation')
|
||||
context_object_name = "dcl_vm_buy_add_ssh_key"
|
||||
|
||||
@cache_control(no_cache=True, must_revalidate=True, no_store=True)
|
||||
@method_decorator(cache_control(no_cache=True, must_revalidate=True, no_store=True))
|
||||
def get(self, request, *args, **kwargs):
|
||||
context = {
|
||||
'site_url': reverse_lazy('datacenterlight:index'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue