66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
"""
|
|
This module defines the views for the gnuviechadmin customer dashboard.
|
|
|
|
"""
|
|
from __future__ import unicode_literals
|
|
|
|
from django.http import HttpResponseForbidden
|
|
from django.views.generic import (
|
|
DetailView,
|
|
TemplateView,
|
|
)
|
|
from django.views.generic.base import RedirectView
|
|
from django.utils.translation import ugettext as _
|
|
from django.contrib.auth import get_user_model, logout
|
|
|
|
from braces.views import LoginRequiredMixin
|
|
|
|
from hostingpackages.models import CustomerHostingPackage
|
|
|
|
|
|
class IndexView(TemplateView):
|
|
"""
|
|
This is the dashboard view.
|
|
|
|
"""
|
|
template_name = 'dashboard/index.html'
|
|
|
|
|
|
class UserDashboardView(LoginRequiredMixin, DetailView):
|
|
"""
|
|
This is the user dashboard view.
|
|
|
|
"""
|
|
model = get_user_model()
|
|
context_object_name = 'dashboard_user'
|
|
slug_field = 'username'
|
|
template_name = 'dashboard/user_dashboard.html'
|
|
|
|
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.')
|
|
)
|
|
|
|
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
|
|
|
|
|
|
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)
|