From 2e15f5fd3525120d22336faf10e960050aaefb67 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 16 Nov 2022 18:05:49 +0100 Subject: Remove deadcode (old dashboards) - clean css --- archaeological_files/models.py | 148 ------------ .../ishtar/dashboards/dashboard_file.html | 251 --------------------- archaeological_files/tests.py | 18 -- archaeological_files/urls.py | 1 - archaeological_files/views.py | 8 - 5 files changed, 426 deletions(-) delete mode 100644 archaeological_files/templates/ishtar/dashboards/dashboard_file.html (limited to 'archaeological_files') diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 9b878ab35..c2992935b 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -1354,154 +1354,6 @@ class FileByDepartment(models.Model): return "{} - {}".format(self.file, self.department) -class FileDashboard: - def __init__(self): - from archaeological_operations.models import AdministrativeAct - - main_dashboard = Dashboard(File) - - self.total_number = main_dashboard.total_number - - types = File.objects.values("file_type", "file_type__label") - self.types = types.annotate(number=Count("pk")).order_by("file_type") - - by_year = File.objects.extra({"date": "date_trunc('year', creation_date)"}) - self.by_year = ( - by_year.values("date").annotate(number=Count("pk")).order_by("-date") - ) - - now = datetime.date.today() - limit = datetime.date(now.year, now.month, 1) - datetime.timedelta(365) - by_month = File.objects.filter(creation_date__gt=limit).extra( - {"date": "date_trunc('month', creation_date)"} - ) - self.by_month = ( - by_month.values("date").annotate(number=Count("pk")).order_by("-date") - ) - - # research - self.research = {} - prog_type = FileType.objects.get(txt_idx="prog") - researchs = File.objects.filter(file_type=prog_type) - self.research["total_number"] = researchs.count() - by_year = researchs.extra({"date": "date_trunc('year', creation_date)"}) - self.research["by_year"] = ( - by_year.values("date").annotate(number=Count("pk")).order_by("-date") - ) - by_month = researchs.filter(creation_date__gt=limit).extra( - {"date": "date_trunc('month', creation_date)"} - ) - self.research["by_month"] = ( - by_month.values("date").annotate(number=Count("pk")).order_by("-date") - ) - - self.research["by_dpt"] = ( - FileByDepartment.objects.filter( - file__file_type=prog_type, department__isnull=False - ) - .values("department__label") - .annotate(number=Count("file")) - .order_by("department__label") - ) - FileTown = File.towns.through - self.research["towns"] = ( - FileTown.objects.filter(file__file_type=prog_type) - .values("town__name") - .annotate(number=Count("file")) - .order_by("-number", "town__name")[:10] - ) - - # rescue - rescue_type = FileType.objects.get(txt_idx="preventive") - rescues = File.objects.filter(file_type=rescue_type) - self.rescue = {} - self.rescue["total_number"] = rescues.count() - self.rescue["saisine"] = ( - rescues.values("saisine_type__label") - .annotate(number=Count("pk")) - .order_by("saisine_type__label") - ) - self.rescue["administrative_act"] = ( - AdministrativeAct.objects.filter(associated_file__isnull=False) - .values("act_type__label") - .annotate(number=Count("pk")) - .order_by("act_type__pk") - ) - - by_year = rescues.extra({"date": "date_trunc('year', creation_date)"}) - self.rescue["by_year"] = ( - by_year.values("date").annotate(number=Count("pk")).order_by("-date") - ) - by_month = rescues.filter(creation_date__gt=limit).extra( - {"date": "date_trunc('month', creation_date)"} - ) - self.rescue["by_month"] = ( - by_month.values("date").annotate(number=Count("pk")).order_by("-date") - ) - - self.rescue["by_dpt"] = ( - FileByDepartment.objects.filter( - file__file_type=rescue_type, department__isnull=False - ) - .values("department__label") - .annotate(number=Count("file")) - .order_by("department__label") - ) - self.rescue["towns"] = ( - FileTown.objects.filter(file__file_type=rescue_type) - .values("town__name") - .annotate(number=Count("file")) - .order_by("-number", "town__name")[:10] - ) - - self.rescue["with_associated_operation"] = rescues.filter( - operations__isnull=False - ).count() - - if self.rescue["total_number"]: - self.rescue["with_associated_operation_percent"] = round( - float(self.rescue["with_associated_operation"]) - / self.rescue["total_number"] - * 100, - 2, - ) - - by_year_operationnal = rescues.filter(operations__isnull=False).extra( - {"date": "date_trunc('year', " '"archaeological_files_file".creation_date)'} - ) - by_year_operationnal = ( - by_year_operationnal.values("date") - .annotate(number=Count("pk")) - .order_by("-date") - ) - percents, idx = [], 0 - for dct in self.rescue["by_year"]: - if idx >= len(by_year_operationnal): - break - if by_year_operationnal[idx]["date"] != dct["date"] or not dct["number"]: - continue - val = round( - float(by_year_operationnal[idx]["number"]) / dct["number"] * 100, 2 - ) - percents.append({"date": dct["date"], "number": val}) - self.rescue["operational_by_year"] = percents - - self.rescue["surface_by_town"] = ( - FileTown.objects.filter(file__file_type=rescue_type) - .values("town__name") - .annotate(number=Sum("file__total_surface")) - .order_by("-number", "town__name")[:10] - ) - self.rescue["surface_by_dpt"] = ( - FileByDepartment.objects.filter( - file__file_type=rescue_type, department__isnull=False - ) - .values("department__label") - .annotate(number=Sum("file__total_surface")) - .order_by("department__label") - ) - - class ManDays(models.Model): man_by_day_planned = models.FloatField( _("Man by day - planned"), null=True, blank=True diff --git a/archaeological_files/templates/ishtar/dashboards/dashboard_file.html b/archaeological_files/templates/ishtar/dashboards/dashboard_file.html deleted file mode 100644 index 127c9f2f8..000000000 --- a/archaeological_files/templates/ishtar/dashboards/dashboard_file.html +++ /dev/null @@ -1,251 +0,0 @@ -{% extends "base.html" %} -{% load i18n range units humanize %} -{% block extra_head %} -{{form.media}} -{% endblock %} -{% block content %} -

{% trans "Archaeological files" %}

-
- -

{% trans "Global informations" %}

-
- - - - - - {% for type in dashboard.types %} - - - - - {% endfor %} -
{% trans "Total" %}{{dashboard.total_number|intcomma}}
{{type.file_type__label}}{{type.number|intcomma}}
- -
-

{% trans "by year"%}

-
- - - {% for year in dashboard.by_year %}{% endfor %} - - - {% for year in dashboard.by_year %}{% endfor%} - -
{% if year.date.year %}{{year.date.year}}{% else %}{% trans "no year" %}{% endif %}
{{year.number|intcomma}}
-
-
- -
-

{% trans "by month"%}

- - - {% for month in dashboard.by_month %}{% endfor %} - - - {% for month in dashboard.by_month %}{% endfor%} - -
{{month.date|date:"N Y"|capfirst}}
{{month.number|intcomma}}
-
- -
- -

{% trans "Research archaeology" %}

-
-

{{dashboard.research.total_number|intcomma}}

-
-

{% trans "by year"%}

- - - {% for year in dashboard.research.by_year %}{% endfor %} - - - {% for year in dashboard.research.by_year %}{% endfor%} - -
{{year.date.year}}
{{year.number|intcomma}}
-
- -
-

{% trans "by month"%}

- - - {% for month in dashboard.research.by_month %}{% endfor %} - - - {% for month in dashboard.research.by_month %}{% endfor%} - -
{{month.date|date:"F Y"|capfirst}}
{{month.number|intcomma}}
-
- -
-

{% trans "by department"%}

- - - {% for dpt in dashboard.research.by_dpt %}{% endfor %} - - - {% for dpt in dashboard.research.by_dpt %}{% endfor%} - -
{{dpt.department__label}}
{{dpt.number|intcomma}}
-
- -
-

{% trans "main towns"%}

-
- - - {% for town in dashboard.research.towns %}{% endfor %} - - - {% for town in dashboard.research.towns %}{% endfor%} - -
{{town.town__name}}
{{town.number|intcomma}}
-
-
- -
- -

{% trans "Rescue archaeology" %}

-
-

{{dashboard.rescue.total_number|intcomma}}

- -
-

{% trans "by saisine type"%}

-
- - - {% for saisine in dashboard.rescue.saisine %}{% endfor %} - - - {% for saisine in dashboard.rescue.saisine %}{% endfor%} - -
{{saisine.saisine_type__label}}
{{saisine.number|intcomma}}
-
-
- -
-

{% trans "by administrative act"%}

-
- - - {% for act in dashboard.rescue.administrative_act %}{% endfor %} - - - {% for act in dashboard.rescue.administrative_act %}{% endfor%} - -
{{act.act_type__label}}
{{act.number|intcomma}}
-
-
- -
-

{% trans "by year"%}

-
- - - {% for year in dashboard.rescue.by_year %}{% endfor %} - - - {% for year in dashboard.rescue.by_year %}{% endfor%} - -
{{year.date.year}}
{{year.number|intcomma}}
-
-
- -
-

{% trans "by month"%}

-
- - - {% for month in dashboard.rescue.by_month %}{% endfor %} - - - {% for month in dashboard.rescue.by_month %}{% endfor%} - -
{{month.date|date:"F Y"|capfirst}}
{{month.number|intcomma}}
-
-
- -

{{dashboard.rescue.with_associated_operation|intcomma}}

-

{{dashboard.rescue.with_associated_operation_percent|intcomma}}

- -
-

{% trans "archaeological files linked to at least one operation (%)"%}

-
- - - {% for year in dashboard.rescue.operational_by_year %}{% endfor %} - - - {% for year in dashboard.rescue.operational_by_year %}{% endfor%} - -
{{year.date.year}}
{{year.number|intcomma}}
-
-
- -
-

{% trans "by department"%}

-
- - - {% for dpt in dashboard.rescue.by_dpt %}{% endfor %} - - - {% for dpt in dashboard.rescue.by_dpt %}{% endfor%} - -
{{dpt.department__label}}
{{dpt.number|intcomma}}
-
-
- -
-

{% trans "surface by department (ha)"%}

-
- - - {% for dpt in dashboard.rescue.surface_by_dpt %}{% endfor %} - - - {% for dpt in dashboard.rescue.surface_by_dpt %}{% endfor%} - -
{{dpt.department__label}}
{{dpt.number|m2_to_ha|intcomma}}
-
-
- -
-

{% trans "main towns by number"%}

-
- - - {% for town in dashboard.rescue.towns %}{% endfor %} - - - {% for town in dashboard.rescue.towns %}{% endfor%} - -
{{town.town__name}}
{{town.number|intcomma}}
-
-
- -
-

{% trans "main towns by surface (ha)"%}

-
- - - {% for town in dashboard.rescue.surface_by_town %}{% endfor %} - - - {% for town in dashboard.rescue.surface_by_town %}{% endfor%} - -
{{town.town__name}}
{{town.number|m2_to_ha|intcomma}}
-
-
- -
-
- -{% endblock %} diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py index f0684c756..75a6ca7cd 100644 --- a/archaeological_files/tests.py +++ b/archaeological_files/tests.py @@ -729,24 +729,6 @@ class FileOperationTest(TestCase, OperationInitTest, FileInit): self.assertEqual(q.count(), 1) -class DashboardTest(TestCase, FileInit): - fixtures = FILE_TOWNS_FIXTURES - model = models.File - - def setUp(self): - self.username, self.password, self.user = create_superuser() - IshtarSiteProfile.objects.create() - self.create_file() - - def test_dashboard(self): - url = "dashboard-file" - c = Client() - c.login(username=self.username, password=self.password) - - response = c.get(reverse(url)) - self.assertEqual(response.status_code, 200) - - class AutocompleteTest(AutocompleteTestBase, TestCase): fixtures = FILE_TOWNS_FIXTURES models = [ diff --git a/archaeological_files/urls.py b/archaeological_files/urls.py index fd2059bbe..0d1ae7632 100644 --- a/archaeological_files/urls.py +++ b/archaeological_files/urls.py @@ -126,7 +126,6 @@ urlpatterns = [ check_rights(["add_administrativeact"])(views.file_adminact_add), name="file-add-adminact", ), - url(r"dashboard_file/$", views.dashboard_file, name="dashboard-file"), url( r"file_administrativeact_document/$", administrativeactfile_document, diff --git a/archaeological_files/views.py b/archaeological_files/views.py index 117f9849c..2e6cf9aff 100644 --- a/archaeological_files/views.py +++ b/archaeological_files/views.py @@ -120,14 +120,6 @@ get_administrativeactfile = get_item( ) -def dashboard_file(request, *args, **kwargs): - """ - Main dashboard - """ - dct = {"dashboard": models.FileDashboard()} - return render(request, "ishtar/dashboards/dashboard_file.html", dct) - - file_search_wizard = wizards.FileSearch.as_view( [("general-file_search", forms.FileFormSelection)], label=_("File search"), -- cgit v1.2.3