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.utils.translation import ugettext as _
|
2015-01-20 00:47:24 +01:00
|
|
|
from django.contrib.auth import get_user_model
|
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
|