|
1 | 1 | import json |
2 | 2 | from datetime import timedelta |
3 | 3 |
|
| 4 | +import pytz |
4 | 5 | import re2 as re # type: ignore[import-untyped] |
5 | 6 | from django.conf import settings |
6 | 7 | from django.contrib.admin.views.decorators import staff_member_required |
|
15 | 16 | ) |
16 | 17 | from django.shortcuts import get_object_or_404 |
17 | 18 | from django.template import loader |
18 | | -from django.urls import reverse, reverse_lazy |
| 19 | +from django.urls import reverse |
19 | 20 | from django.utils import timezone |
20 | 21 | from django.utils.decorators import method_decorator |
21 | 22 | from django.utils.safestring import mark_safe |
22 | | -from django.views.generic import ListView |
23 | | -from django.views.generic.edit import FormView |
| 23 | +from django.views.generic import ListView, TemplateView |
24 | 24 |
|
25 | 25 | from app_analytics.influxdb_wrapper import ( |
26 | 26 | get_event_list_for_organisation, |
27 | 27 | get_events_for_organisation, |
28 | 28 | ) |
| 29 | +from core.helpers import get_current_site_url |
29 | 30 | from environments.dynamodb.migrator import IdentityMigrator |
30 | 31 | from environments.identities.models import Identity |
| 32 | +from environments.models import Environment |
| 33 | +from features.models import Feature |
31 | 34 | from import_export.export import full_export |
32 | 35 | from organisations.chargebee.tasks import update_chargebee_cache |
33 | 36 | from organisations.models import ( |
|
39 | 42 | update_organisation_subscription_information_cache, |
40 | 43 | update_organisation_subscription_information_influx_cache, |
41 | 44 | ) |
| 45 | +from projects.models import Project |
42 | 46 | from users.models import FFAdminUser |
43 | 47 |
|
44 | 48 | from .forms import ( |
45 | | - EmailUsageForm, |
46 | 49 | EndTrialForm, |
47 | 50 | MaxAPICallsForm, |
48 | 51 | MaxSeatsForm, |
@@ -295,18 +298,21 @@ def migrate_identities_to_edge(request, project_id): # type: ignore[no-untyped- |
295 | 298 | name="get", |
296 | 299 | decorator=staff_member_required(), |
297 | 300 | ) |
298 | | -@method_decorator( |
299 | | - name="post", |
300 | | - decorator=staff_member_required(), |
301 | | -) |
302 | | -class EmailUsage(FormView): # type: ignore[type-arg] |
303 | | - form_class = EmailUsageForm |
304 | | - template_name = "sales_dashboard/email-usage.html" |
305 | | - success_url = reverse_lazy("sales_dashboard:index") |
306 | | - |
307 | | - def form_valid(self, form): # type: ignore[no-untyped-def] |
308 | | - form.save() |
309 | | - return super().form_valid(form) |
| 301 | +class UsageReport(TemplateView): # pragma: no cover |
| 302 | + template_name = "sales_dashboard/usage.html" |
| 303 | + |
| 304 | + def get_context_data(self, **kwargs): # type: ignore[no-untyped-def] |
| 305 | + context = super().get_context_data(**kwargs) |
| 306 | + context["stats"] = { |
| 307 | + "site_url": get_current_site_url(), |
| 308 | + "total_organisations": Organisation.objects.all().count(), |
| 309 | + "total_projects": Project.objects.all().count(), |
| 310 | + "total_environments": Environment.objects.all().count(), |
| 311 | + "total_features": Feature.objects.all().count(), |
| 312 | + "total_seats": FFAdminUser.objects.all().count(), |
| 313 | + "report_date": timezone.now().astimezone(pytz.UTC), |
| 314 | + } |
| 315 | + return context |
310 | 316 |
|
311 | 317 |
|
312 | 318 | @staff_member_required() # type: ignore[misc] |
|
0 commit comments