Separate core from dashboard
This commit is contained in:
parent
3df754f54b
commit
a81e98f809
@ -1,17 +0,0 @@
|
||||
{% extends "core/service_base.html" %}
|
||||
|
||||
{% load a17t_tags pagination humanize helpers %}
|
||||
|
||||
{% block head_title %}{{object.name}} Sessions{% endblock %}
|
||||
|
||||
{% block service_actions %}
|
||||
<div class="mr-2">{% include 'core/includes/date_range.html' %}</div>
|
||||
<a href="{% url 'core:service' object.uuid %}" class="button field ~neutral w-auto">Analytics →</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block service_content %}
|
||||
<div class="card ~neutral !low mb-8 pt-2 max-w-full overflow-x-scroll">
|
||||
{% include 'core/includes/session_list.html' %}
|
||||
</div>
|
||||
{% pagination page_obj request %}
|
||||
{% endblock %}
|
@ -1,32 +1,9 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.urls import include, path, reverse_lazy
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", RedirectView.as_view(url="/dash"), name="index"),
|
||||
path("dash/", views.DashboardView.as_view(), name="dashboard"),
|
||||
path("dash/service/new/", views.ServiceCreateView.as_view(), name="service_create"),
|
||||
path("dash/service/<pk>/", views.ServiceView.as_view(), name="service"),
|
||||
path(
|
||||
"dash/service/<pk>/manage/",
|
||||
views.ServiceUpdateView.as_view(),
|
||||
name="service_update",
|
||||
),
|
||||
path(
|
||||
"dash/service/<pk>/delete/",
|
||||
views.ServiceDeleteView.as_view(),
|
||||
name="service_delete",
|
||||
),
|
||||
path(
|
||||
"dash/service/<pk>/sessions/",
|
||||
views.ServiceSessionsListView.as_view(),
|
||||
name="service_session_list",
|
||||
),
|
||||
path(
|
||||
"dash/service/<pk>/sessions/<session_pk>/",
|
||||
views.ServiceSessionView.as_view(),
|
||||
name="service_session",
|
||||
),
|
||||
path("", RedirectView.as_view(url=reverse_lazy("dashboard:dashboard")), name="index"),
|
||||
]
|
||||
|
@ -1,127 +1,4 @@
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import get_object_or_404, reverse
|
||||
from django.utils import timezone
|
||||
from django.views.generic import (
|
||||
CreateView,
|
||||
DeleteView,
|
||||
DetailView,
|
||||
ListView,
|
||||
TemplateView,
|
||||
UpdateView,
|
||||
)
|
||||
from rules.contrib.views import PermissionRequiredMixin
|
||||
from django.db.models import Q
|
||||
|
||||
from analytics.models import Session
|
||||
|
||||
from .forms import ServiceForm
|
||||
from .mixins import BaseUrlMixin, DateRangeMixin
|
||||
from .models import Service
|
||||
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
class IndexView(TemplateView):
|
||||
template_name = "core/pages/index.html"
|
||||
|
||||
|
||||
class DashboardView(LoginRequiredMixin, DateRangeMixin, TemplateView):
|
||||
template_name = "core/pages/dashboard.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["services"] = Service.objects.filter(
|
||||
Q(owner=self.request.user) | Q(collaborators__in=[self.request.user])
|
||||
)
|
||||
for service in data["services"]:
|
||||
service.stats = service.get_core_stats(data["start_date"], data["end_date"])
|
||||
return data
|
||||
|
||||
|
||||
class ServiceCreateView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
|
||||
model = Service
|
||||
form_class = ServiceForm
|
||||
template_name = "core/pages/service_create.html"
|
||||
permission_required = "core.create_service"
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("core:service", kwargs={"pk": self.object.uuid})
|
||||
|
||||
|
||||
class ServiceView(
|
||||
LoginRequiredMixin, PermissionRequiredMixin, DateRangeMixin, DetailView
|
||||
):
|
||||
model = Service
|
||||
template_name = "core/pages/service.html"
|
||||
permission_required = "core.view_service"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["stats"] = self.object.get_core_stats(data["start_date"], data["end_date"])
|
||||
data["object_list"] = Session.objects.filter(
|
||||
service=self.get_object(),
|
||||
start_time__lt=self.get_end_date(),
|
||||
start_time__gt=self.get_start_date(),
|
||||
).order_by("-start_time")[:10]
|
||||
return data
|
||||
|
||||
|
||||
class ServiceUpdateView(
|
||||
LoginRequiredMixin, PermissionRequiredMixin, BaseUrlMixin, UpdateView
|
||||
):
|
||||
model = Service
|
||||
form_class = ServiceForm
|
||||
template_name = "core/pages/service_update.html"
|
||||
permission_required = "core.change_service"
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("core:service", kwargs={"uuid": self.object.uuid})
|
||||
|
||||
|
||||
class ServiceDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteView):
|
||||
model = Service
|
||||
form_class = ServiceForm
|
||||
template_name = "core/pages/service_delete.html"
|
||||
permission_required = "core.delete_service"
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("core:dashboard")
|
||||
|
||||
|
||||
class ServiceSessionsListView(
|
||||
LoginRequiredMixin, PermissionRequiredMixin, DateRangeMixin, ListView
|
||||
):
|
||||
model = Session
|
||||
template_name = "core/pages/service_session_list.html"
|
||||
paginate_by = 20
|
||||
permission_required = "core.view_service"
|
||||
|
||||
def get_object(self):
|
||||
return get_object_or_404(Service, pk=self.kwargs.get("pk"))
|
||||
|
||||
def get_queryset(self):
|
||||
return Session.objects.filter(
|
||||
service=self.get_object(),
|
||||
start_time__lt=self.get_end_date(),
|
||||
start_time__gt=self.get_start_date(),
|
||||
).order_by("-start_time")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["object"] = self.get_object()
|
||||
return data
|
||||
|
||||
|
||||
class ServiceSessionView(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
|
||||
model = Session
|
||||
template_name = "core/pages/service_session.html"
|
||||
pk_url_kwarg = "session_pk"
|
||||
context_object_name = "session"
|
||||
permission_required = "core.view_service"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["object"] = get_object_or_404(Service, pk=self.kwargs.get("pk"))
|
||||
return data
|
||||
template_name = "dashboard/pages/index.html"
|
5
shynet/dashboard/apps.py
Normal file
5
shynet/dashboard/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class DashboardConfig(AppConfig):
|
||||
name = 'dashboard'
|
@ -1,7 +1,7 @@
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import Service
|
||||
from core.models import Service
|
||||
|
||||
|
||||
class ServiceForm(forms.ModelForm):
|
0
shynet/dashboard/migrations/__init__.py
Normal file
0
shynet/dashboard/migrations/__init__.py
Normal file
@ -11,7 +11,7 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/litepicker/dist/js/main.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/apexcharts@3.18.1/dist/apexcharts.min.js"
|
||||
integrity="sha256-RalQXBZdisB04aaBsm+6YZ0b/iRYjX1MZn90m19AnCY=" crossorigin="anonymous"></script>
|
||||
<link rel="stylesheet" href="{% static 'core/css/global.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'dashboard/css/global.css' %}">
|
||||
{% block extra_head %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
<section class="max-w-screen-xl mx-auto px-4 md:px-0 py-4 md:py-12 md:flex">
|
||||
<aside class="mb-8 md:w-2/12 md:pr-6 relative flex flex-wrap md:block justify-between items-center">
|
||||
<a class="icon ~urge ml-2 md:ml-6 md:mb-8 md:mt-3" href="{% url 'core:dashboard' %}">
|
||||
<a class="icon ~urge ml-2 md:ml-6 md:mb-8 md:mt-3" href="{% url 'dashboard:dashboard' %}">
|
||||
<i class="fas fa-binoculars fa-3x text-purple-600 hidden md:block"></i>
|
||||
<i class="fas fa-binoculars fa-2x text-purple-600 md:hidden"></i>
|
||||
</a>
|
||||
@ -38,16 +38,16 @@
|
||||
<p class="ml-2 mb-1 supra font-medium text-gray-500 pointer-events-none">Services</p>
|
||||
|
||||
{% for service in user.owning_services.all %}
|
||||
{% url 'core:service' service.uuid as url %}
|
||||
{% include 'core/includes/sidebar_portal.html' with label=service.name url=url %}
|
||||
{% url 'dashboard:service' service.uuid as url %}
|
||||
{% include 'dashboard/includes/sidebar_portal.html' with label=service.name url=url %}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% has_perm 'core.create_service' user as can_create %}
|
||||
{% if can_create %}
|
||||
{% url 'core:service_create' as url %}
|
||||
{% include 'core/includes/sidebar_portal.html' with label="+ Create" url=url %}
|
||||
{% url 'dashboard:service_create' as url %}
|
||||
{% include 'dashboard/includes/sidebar_portal.html' with label="+ Create" url=url %}
|
||||
|
||||
<hr class="sep h-8">
|
||||
{% endif %}
|
||||
@ -57,8 +57,8 @@
|
||||
<p class="ml-2 mb-1 supra font-medium text-gray-500 pointer-events-none">Collaborations</p>
|
||||
|
||||
{% for service in user.collaborating_services.all %}
|
||||
{% url 'core:service' service.uuid as url %}
|
||||
{% include 'core/includes/sidebar_portal.html' with label=service.name url=url %}
|
||||
{% url 'dashboard:service' service.uuid as url %}
|
||||
{% include 'dashboard/includes/sidebar_portal.html' with label=service.name url=url %}
|
||||
{% endfor %}
|
||||
|
||||
<hr class="sep h-8">
|
||||
@ -69,21 +69,21 @@
|
||||
{% if user.is_authenticated %}
|
||||
|
||||
{% url 'account_email' as url %}
|
||||
{% include 'core/includes/sidebar_portal.html' with label="Emails" url=url %}
|
||||
{% include 'dashboard/includes/sidebar_portal.html' with label="Emails" url=url %}
|
||||
|
||||
{% url 'account_set_password' as url %}
|
||||
{% include 'core/includes/sidebar_portal.html' with label="Security" url=url %}
|
||||
{% include 'dashboard/includes/sidebar_portal.html' with label="Security" url=url %}
|
||||
|
||||
{% url 'account_logout' as url %}
|
||||
{% include 'core/includes/sidebar_portal.html' with label="Sign Out" url=url %}
|
||||
{% include 'dashboard/includes/sidebar_portal.html' with label="Sign Out" url=url %}
|
||||
|
||||
{% else %}
|
||||
|
||||
{% url 'account_login' as url %}
|
||||
{% include 'core/includes/sidebar_portal.html' with label="Log In" url=url %}
|
||||
{% include 'dashboard/includes/sidebar_portal.html' with label="Log In" url=url %}
|
||||
|
||||
{% url 'account_signup' as url %}
|
||||
{% include 'core/includes/sidebar_portal.html' with label="Sign Up" url=url %}
|
||||
{% include 'dashboard/includes/sidebar_portal.html' with label="Sign Up" url=url %}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
@ -1,13 +1,13 @@
|
||||
{% load humanize helpers %}
|
||||
|
||||
<a class="card ~neutral !low service mb-6 p-0" href="{% url 'core:service' object.uuid %}">
|
||||
<a class="card ~neutral !low service mb-6 p-0" href="{% url 'dashboard:service' object.uuid %}">
|
||||
{% with stats=object.stats %}
|
||||
<div class="p-4 md:flex justify-between">
|
||||
<div class="md:w-4/12 flex items-center mb-4 md:mb-0">
|
||||
<h3 class="heading text-xl md:text-2xl mr-2 mb-1 text-purple-600">
|
||||
{{object.name}}
|
||||
</h3>
|
||||
{% include 'core/includes/stats_status_chip.html' %}
|
||||
{% include 'dashboard/includes/stats_status_chip.html' %}
|
||||
</div>
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-6">
|
||||
<div>
|
||||
@ -42,7 +42,7 @@
|
||||
</div>
|
||||
<hr class="sep h-4">
|
||||
<div style="bottom: -1px;">
|
||||
{% include 'core/includes/time_chart.html' with data=stats.session_chart_data sparkline=True height=100 name=object.uuid %}
|
||||
{% include 'dashboard/includes/time_chart.html' with data=stats.session_chart_data sparkline=True height=100 name=object.uuid %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
</a>
|
@ -12,7 +12,7 @@
|
||||
{% for session in object_list %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'core:service_session' object.pk session.pk %}" class="font-medium text-purple-700">
|
||||
<a href="{% url 'dashboard:service_session' object.pk session.pk %}" class="font-medium text-purple-700">
|
||||
{{session.start_time|date:"M j Y, g:i a"|capfirst}}
|
||||
{% if session.is_currently_active %}
|
||||
<span class="badge ~positive">Online</span>
|
@ -9,6 +9,9 @@
|
||||
},
|
||||
colors: ["#805AD5"],
|
||||
chart: {
|
||||
zoom: {
|
||||
enabled: false,
|
||||
},
|
||||
toolbar: {
|
||||
show: false,
|
||||
},
|
@ -9,17 +9,17 @@
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<div class="mr-1">
|
||||
{% include 'core/includes/date_range.html' %}
|
||||
{% include 'dashboard/includes/date_range.html' %}
|
||||
</div>
|
||||
{% has_perm "core.create_service" user as can_create %}
|
||||
{% if can_create %}
|
||||
<a href="{% url 'core:service_create' %}" class="button field w-auto">+ New Service</a>
|
||||
<a href="{% url 'dashboard:service_create' %}" class="button field w-auto">+ New Service</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<hr class="sep">
|
||||
{% for object in services %}
|
||||
{% include 'core/includes/service_overview.html' %}
|
||||
{% include 'dashboard/includes/service_overview.html' %}
|
||||
{% empty %}
|
||||
<p>You don't have any services on this Shynet instance yet.</p>
|
||||
{% endfor %}
|
@ -1,12 +1,12 @@
|
||||
{% extends "core/service_base.html" %}
|
||||
{% extends "dashboard/service_base.html" %}
|
||||
|
||||
{% load humanize helpers rules %}
|
||||
|
||||
{% block service_actions %}
|
||||
<div class="mr-2">{% include 'core/includes/date_range.html' %}</div>
|
||||
<div class="mr-2">{% include 'dashboard/includes/date_range.html' %}</div>
|
||||
{% has_perm 'core.change_service' user object as can_update %}
|
||||
{% if can_update %}
|
||||
<a href="{% url 'core:service_update' service.uuid %}" class="button field ~neutral w-auto">Manage →</a>
|
||||
<a href="{% url 'dashboard:service_update' service.uuid %}" class="button field ~neutral w-auto">Manage →</a>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@ -66,7 +66,7 @@
|
||||
</article>
|
||||
</div>
|
||||
<div class="card ~neutral !low py-0 mb-6">
|
||||
{% include 'core/includes/time_chart.html' with data=stats.session_chart_data %}
|
||||
{% include 'dashboard/includes/time_chart.html' with data=stats.session_chart_data %}
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
|
||||
<div class="card ~neutral !low limited-height py-2">
|
||||
@ -179,9 +179,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="card ~neutral !low">
|
||||
{% include 'core/includes/session_list.html' %}
|
||||
{% include 'dashboard/includes/session_list.html' %}
|
||||
<hr class="sep h-8">
|
||||
<a href="{% url 'core:service_session_list' service.uuid %}" class="button ~neutral w-auto">View more sessions
|
||||
<a href="{% url 'dashboard:service_session_list' service.uuid %}" class="button ~neutral w-auto">View more sessions
|
||||
→</a>
|
||||
</div>
|
||||
{% endblock %}
|
@ -14,7 +14,7 @@
|
||||
</div>
|
||||
<div class="section ~urge !normal p-4">
|
||||
<button type="submit" class="button ~urge !high">Create</button>
|
||||
<a href="{% url 'core:dashboard' %}" class="button ~urge !low">Cancel</a>
|
||||
<a href="{% url 'dashboard:dashboard' %}" class="button ~urge !low">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
@ -1,4 +1,4 @@
|
||||
{% extends "core/service_base.html" %}
|
||||
{% extends "dashboard/service_base.html" %}
|
||||
|
||||
{% load a17t_tags %}
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
</div>
|
||||
<div class="section ~critical !normal p-4">
|
||||
<button type="submit" class="button ~critical !high">Delete</button>
|
||||
<a href="{% url 'core:service' object.uuid %}" class="button ~critical !low">Cancel</a>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}" class="button ~critical !low">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
@ -1,11 +1,11 @@
|
||||
{% extends "core/service_base.html" %}
|
||||
{% extends "dashboard/service_base.html" %}
|
||||
|
||||
{% load a17t_tags pagination humanize helpers %}
|
||||
|
||||
{% block head_title %}{{object.name}} Session{% endblock %}
|
||||
|
||||
{% block service_actions %}
|
||||
<a href="{% url 'core:service' object.uuid %}" class="button field ~neutral w-auto">Analytics →</a>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}" class="button field ~neutral w-auto">Analytics →</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block service_content %}
|
@ -0,0 +1,17 @@
|
||||
{% extends "dashboard/service_base.html" %}
|
||||
|
||||
{% load a17t_tags pagination humanize helpers %}
|
||||
|
||||
{% block head_title %}{{object.name}} Sessions{% endblock %}
|
||||
|
||||
{% block service_actions %}
|
||||
<div class="mr-2">{% include 'dashboard/includes/date_range.html' %}</div>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}" class="button field ~neutral w-auto">Analytics →</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block service_content %}
|
||||
<div class="card ~neutral !low mb-8 pt-2 max-w-full overflow-x-scroll">
|
||||
{% include 'dashboard/includes/session_list.html' %}
|
||||
</div>
|
||||
{% pagination page_obj request %}
|
||||
{% endblock %}
|
@ -1,11 +1,11 @@
|
||||
{% extends "core/service_base.html" %}
|
||||
{% extends "dashboard/service_base.html" %}
|
||||
|
||||
{% load a17t_tags %}
|
||||
|
||||
{% block head_title %}{{object.name}} Management{% endblock %}
|
||||
|
||||
{% block service_actions %}
|
||||
<a href="{% url 'core:service' object.uuid %}" class="button field ~neutral w-auto">View →</a>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}" class="button field ~neutral w-auto">View →</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block service_content %}
|
||||
@ -28,10 +28,10 @@
|
||||
<div class="section ~neutral !normal p-4 flex justify-between">
|
||||
<div>
|
||||
<button type="submit" class="button ~neutral !high">Save</button>
|
||||
<a href="{% url 'core:service' object.uuid %}" class="button ~neutral !low">Cancel</a>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}" class="button ~neutral !low">Cancel</a>
|
||||
</div>
|
||||
<div>
|
||||
<a href="{% url 'core:service_delete' object.uuid %}" class="button ~critical !high">Delete</a>
|
||||
<a href="{% url 'dashboard:service_delete' object.uuid %}" class="button ~critical !high">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
@ -6,12 +6,12 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="md:flex justify-between items-center" id="heading">
|
||||
<a class="flex items-center mb-4 md:mb-0" href="{% url 'core:service' object.uuid %}">
|
||||
<a class="flex items-center mb-4 md:mb-0" href="{% url 'dashboard:service' object.uuid %}">
|
||||
<h3 class="heading leading-none mr-4">
|
||||
{{object.name}}
|
||||
</h3>
|
||||
<div class='text-3xl'>
|
||||
{% include 'core/includes/stats_status_chip.html' %}
|
||||
{% include 'dashboard/includes/stats_status_chip.html' %}
|
||||
</div>
|
||||
</a>
|
||||
<div class="flex items-center">
|
0
shynet/dashboard/templatetags/__init__.py
Normal file
0
shynet/dashboard/templatetags/__init__.py
Normal file
31
shynet/dashboard/urls.py
Normal file
31
shynet/dashboard/urls.py
Normal file
@ -0,0 +1,31 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.DashboardView.as_view(), name="dashboard"),
|
||||
path("service/new/", views.ServiceCreateView.as_view(), name="service_create"),
|
||||
path("service/<pk>/", views.ServiceView.as_view(), name="service"),
|
||||
path(
|
||||
"service/<pk>/manage/",
|
||||
views.ServiceUpdateView.as_view(),
|
||||
name="service_update",
|
||||
),
|
||||
path(
|
||||
"service/<pk>/delete/",
|
||||
views.ServiceDeleteView.as_view(),
|
||||
name="service_delete",
|
||||
),
|
||||
path(
|
||||
"service/<pk>/sessions/",
|
||||
views.ServiceSessionsListView.as_view(),
|
||||
name="service_session_list",
|
||||
),
|
||||
path(
|
||||
"service/<pk>/sessions/<session_pk>/",
|
||||
views.ServiceSessionView.as_view(),
|
||||
name="service_session",
|
||||
),
|
||||
]
|
122
shynet/dashboard/views.py
Normal file
122
shynet/dashboard/views.py
Normal file
@ -0,0 +1,122 @@
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import get_object_or_404, reverse
|
||||
from django.utils import timezone
|
||||
from django.views.generic import (
|
||||
CreateView,
|
||||
DeleteView,
|
||||
DetailView,
|
||||
ListView,
|
||||
TemplateView,
|
||||
UpdateView,
|
||||
)
|
||||
from rules.contrib.views import PermissionRequiredMixin
|
||||
from django.db.models import Q
|
||||
|
||||
from analytics.models import Session
|
||||
|
||||
from .forms import ServiceForm
|
||||
from .mixins import BaseUrlMixin, DateRangeMixin
|
||||
from core.models import Service
|
||||
|
||||
class DashboardView(LoginRequiredMixin, DateRangeMixin, TemplateView):
|
||||
template_name = "dashboard/pages/dashboard.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["services"] = Service.objects.filter(
|
||||
Q(owner=self.request.user) | Q(collaborators__in=[self.request.user])
|
||||
)
|
||||
for service in data["services"]:
|
||||
service.stats = service.get_core_stats(data["start_date"], data["end_date"])
|
||||
return data
|
||||
|
||||
|
||||
class ServiceCreateView(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
|
||||
model = Service
|
||||
form_class = ServiceForm
|
||||
template_name = "dashboard/pages/service_create.html"
|
||||
permission_required = "core.create_service"
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("dashboard:service", kwargs={"pk": self.object.uuid})
|
||||
|
||||
|
||||
class ServiceView(
|
||||
LoginRequiredMixin, PermissionRequiredMixin, DateRangeMixin, DetailView
|
||||
):
|
||||
model = Service
|
||||
template_name = "dashboard/pages/service.html"
|
||||
permission_required = "core.view_service"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["stats"] = self.object.get_core_stats(data["start_date"], data["end_date"])
|
||||
data["object_list"] = Session.objects.filter(
|
||||
service=self.get_object(),
|
||||
start_time__lt=self.get_end_date(),
|
||||
start_time__gt=self.get_start_date(),
|
||||
).order_by("-start_time")[:10]
|
||||
return data
|
||||
|
||||
|
||||
class ServiceUpdateView(
|
||||
LoginRequiredMixin, PermissionRequiredMixin, BaseUrlMixin, UpdateView
|
||||
):
|
||||
model = Service
|
||||
form_class = ServiceForm
|
||||
template_name = "dashboard/pages/service_update.html"
|
||||
permission_required = "core.change_service"
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("dashboard:service", kwargs={"pk": self.object.uuid})
|
||||
|
||||
|
||||
class ServiceDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteView):
|
||||
model = Service
|
||||
form_class = ServiceForm
|
||||
template_name = "dashboard/pages/service_delete.html"
|
||||
permission_required = "core.delete_service"
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("dashboard:dashboard")
|
||||
|
||||
|
||||
class ServiceSessionsListView(
|
||||
LoginRequiredMixin, PermissionRequiredMixin, DateRangeMixin, ListView
|
||||
):
|
||||
model = Session
|
||||
template_name = "dashboard/pages/service_session_list.html"
|
||||
paginate_by = 20
|
||||
permission_required = "core.view_service"
|
||||
|
||||
def get_object(self):
|
||||
return get_object_or_404(Service, pk=self.kwargs.get("pk"))
|
||||
|
||||
def get_queryset(self):
|
||||
return Session.objects.filter(
|
||||
service=self.get_object(),
|
||||
start_time__lt=self.get_end_date(),
|
||||
start_time__gt=self.get_start_date(),
|
||||
).order_by("-start_time")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["object"] = self.get_object()
|
||||
return data
|
||||
|
||||
|
||||
class ServiceSessionView(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
|
||||
model = Session
|
||||
template_name = "dashboard/pages/service_session.html"
|
||||
pk_url_kwarg = "session_pk"
|
||||
context_object_name = "session"
|
||||
permission_required = "core.view_service"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["object"] = get_object_or_404(Service, pk=self.kwargs.get("pk"))
|
||||
return data
|
@ -45,6 +45,7 @@ INSTALLED_APPS = [
|
||||
"rules.apps.AutodiscoverRulesConfig",
|
||||
"a17t",
|
||||
"core",
|
||||
"dashboard",
|
||||
"analytics",
|
||||
"allauth",
|
||||
"allauth.account",
|
||||
|
@ -20,5 +20,6 @@ urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("accounts/", include("allauth.urls")),
|
||||
path("ingress/", include("analytics.ingress_urls"), name="ingress"),
|
||||
path("dashboard/", include(("dashboard.urls", "dashboard"), namespace="dashboard")),
|
||||
path("", include(("core.urls", "core"), namespace="core")),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user