2015-01-17 14:01:22 +01:00
|
|
|
"""
|
|
|
|
This module defines the views for the gnuviechadmin customer dashboard.
|
|
|
|
|
|
|
|
"""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2015-01-17 15:42:47 +01:00
|
|
|
from django.http import HttpResponseForbidden
|
2015-01-17 14:01:22 +01:00
|
|
|
from django.views.generic import (
|
|
|
|
DetailView,
|
|
|
|
TemplateView,
|
|
|
|
)
|
2015-01-17 15:42:47 +01:00
|
|
|
from django.views.generic.base import RedirectView
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.contrib.auth import get_user_model, logout
|
2015-01-17 14:01:22 +01:00
|
|
|
|
|
|
|
from braces.views import LoginRequiredMixin
|
|
|
|
|
2015-01-18 16:19:28 +01:00
|
|
|
from hostingpackages.models import CustomerHostingPackage
|
|
|
|
|
2015-01-17 14:01:22 +01:00
|
|
|
|
|
|
|
class IndexView(TemplateView):
|
|
|
|
"""
|
|
|
|
This is the dashboard view.
|
|
|
|
|
|
|
|
"""
|
|
|
|
template_name = 'dashboard/index.html'
|
|
|
|
|
|
|
|
|
2015-01-17 15:42:47 +01:00
|
|
|
class UserDashboardView(LoginRequiredMixin, DetailView):
|
2015-01-17 14:01:22 +01:00
|
|
|
"""
|
|
|
|
This is the user dashboard view.
|
|
|
|
|
|
|
|
"""
|
|
|
|
model = get_user_model()
|
2015-01-17 15:42:47 +01:00
|
|
|
context_object_name = 'dashboard_user'
|
2015-01-17 14:01:22 +01:00
|
|
|
slug_field = 'username'
|
|
|
|
template_name = 'dashboard/user_dashboard.html'
|
2015-01-17 15:42:47 +01:00
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
if (request.user.is_staff or request.user == self.get_object()):
|
|
|
|
return super(UserDashboardView, self).dispatch(
|
|
|
|
request, *args, **kwargs
|
|
|
|
)
|
|
|
|
return HttpResponseForbidden(
|
|
|
|
_('You are not allowed to view this page.')
|
|
|
|
)
|
|
|
|
|
2015-01-18 16:19:28 +01:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(UserDashboardView, self).get_context_data(**kwargs)
|
|
|
|
context['hosting_packages'] = CustomerHostingPackage.objects.filter(
|
|
|
|
customer=self.object
|
|
|
|
)
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
2015-01-17 15:42:47 +01:00
|
|
|
class LogoutView(RedirectView):
|
|
|
|
pattern_name = 'dashboard'
|
|
|
|
|
|
|
|
def get(self, *args, **kwargs):
|
|
|
|
logout(self.request)
|
|
|
|
return super(LogoutView, self).get(*args, **kwargs)
|
|
|
|
|
|
|
|
def get_redirect_url(self, *args, **kwargs):
|
|
|
|
if 'next' in self.request.GET:
|
|
|
|
return self.request.GET['next']
|
|
|
|
return super(LogoutView, self).get_redirect_url(*args, **kwargs)
|