diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-11-16 18:05:49 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:19 +0100 |
commit | 2e15f5fd3525120d22336faf10e960050aaefb67 (patch) | |
tree | 11cf75140bc4296fc5c936d4f7b6a3a640d4dbce /archaeological_files | |
parent | b46aa637fa1018a151f623138c94e145efa8288c (diff) | |
download | Ishtar-2e15f5fd3525120d22336faf10e960050aaefb67.tar.bz2 Ishtar-2e15f5fd3525120d22336faf10e960050aaefb67.zip |
Remove deadcode (old dashboards) - clean css
Diffstat (limited to 'archaeological_files')
-rw-r--r-- | archaeological_files/models.py | 148 | ||||
-rw-r--r-- | archaeological_files/templates/ishtar/dashboards/dashboard_file.html | 251 | ||||
-rw-r--r-- | archaeological_files/tests.py | 18 | ||||
-rw-r--r-- | archaeological_files/urls.py | 1 | ||||
-rw-r--r-- | archaeological_files/views.py | 8 |
5 files changed, 0 insertions, 426 deletions
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 %} -<h2>{% trans "Archaeological files" %}</h2> -<div class='dashboard' id='dashboard-files'> - - <h3>{% trans "Global informations" %}</h3> - <div> - <table class="table table-striped"> - <tr> - <th>{% trans "Total" %}</th> - <td>{{dashboard.total_number|intcomma}}</td> - </tr> - {% for type in dashboard.types %} - <tr> - <th>{{type.file_type__label}}</th> - <td>{{type.number|intcomma}}</td> - </tr> - {% endfor %} - </table> - - <div class='clean-table'> - <h4>{% trans "by year"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for year in dashboard.by_year %}<th>{% if year.date.year %}{{year.date.year}}{% else %}{% trans "no year" %}{% endif %}</th>{% endfor %} - </tr> - <tr> - {% for year in dashboard.by_year %}<td>{{year.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <div class='clean-table'> - <h4>{% trans "by month"%}</h4> - <table class="table table-striped"> - <tr> - {% for month in dashboard.by_month %}<th>{{month.date|date:"N Y"|capfirst}}</th>{% endfor %} - </tr> - <tr> - {% for month in dashboard.by_month %}<td>{{month.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - - </div> - - <h3>{% trans "Research archaeology" %}</h3> - <div> - <p><label>{% trans "Total:" %}</label><span class='value numeric'>{{dashboard.research.total_number|intcomma}}</span></p> - <div class='clean-table'> - <h4>{% trans "by year"%}</h4> - <table class="table table-striped"> - <tr> - {% for year in dashboard.research.by_year %}<th>{{year.date.year}}</th>{% endfor %} - </tr> - <tr> - {% for year in dashboard.research.by_year %}<td>{{year.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - - <div class='clean-table'> - <h4>{% trans "by month"%}</h4> - <table class="table table-striped"> - <tr> - {% for month in dashboard.research.by_month %}<th>{{month.date|date:"F Y"|capfirst}}</th>{% endfor %} - </tr> - <tr> - {% for month in dashboard.research.by_month %}<td>{{month.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - - <div class='clean-table'> - <h4>{% trans "by department"%}</h4> - <table class="table table-striped"> - <tr> - {% for dpt in dashboard.research.by_dpt %}<th>{{dpt.department__label}}</th>{% endfor %} - </tr> - <tr> - {% for dpt in dashboard.research.by_dpt %}<td>{{dpt.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - - <div class='clean-table'> - <h4>{% trans "main towns"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for town in dashboard.research.towns %}<th>{{town.town__name}}</th>{% endfor %} - </tr> - <tr> - {% for town in dashboard.research.towns %}<td>{{town.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - </div> - - <h3>{% trans "Rescue archaeology" %}</h3> - <div> - <p><label>{% trans "Total:" %}</label> <span class='value numeric'>{{dashboard.rescue.total_number|intcomma}}</span></p> - - <div class='clean-table'> - <h4>{% trans "by saisine type"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for saisine in dashboard.rescue.saisine %}<th>{{saisine.saisine_type__label}}</th>{% endfor %} - </tr> - <tr> - {% for saisine in dashboard.rescue.saisine %}<td>{{saisine.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <div class='clean-table'> - <h4>{% trans "by administrative act"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for act in dashboard.rescue.administrative_act %}<th>{{act.act_type__label}}</th>{% endfor %} - </tr> - <tr> - {% for act in dashboard.rescue.administrative_act %}<td>{{act.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <div class='clean-table'> - <h4>{% trans "by year"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for year in dashboard.rescue.by_year %}<th>{{year.date.year}}</th>{% endfor %} - </tr> - <tr> - {% for year in dashboard.rescue.by_year %}<td>{{year.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <div class='clean-table'> - <h4>{% trans "by month"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for month in dashboard.rescue.by_month %}<th>{{month.date|date:"F Y"|capfirst}}</th>{% endfor %} - </tr> - <tr> - {% for month in dashboard.rescue.by_month %}<td>{{month.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <p><label>{% trans "Archaeological files linked to at least one operation:" %}</label> <span class='value numeric'>{{dashboard.rescue.with_associated_operation|intcomma}}</span></p> - <p><label>{% trans "Archaeological files linked to at least one operation (%):" %}</label> <span class='value numeric'>{{dashboard.rescue.with_associated_operation_percent|intcomma}}</span></p> - - <div class='clean-table'> - <h4>{% trans "archaeological files linked to at least one operation (%)"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for year in dashboard.rescue.operational_by_year %}<th>{{year.date.year}}</th>{% endfor %} - </tr> - <tr> - {% for year in dashboard.rescue.operational_by_year %}<td>{{year.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <div class='clean-table'> - <h4>{% trans "by department"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for dpt in dashboard.rescue.by_dpt %}<th>{{dpt.department__label}}</th>{% endfor %} - </tr> - <tr> - {% for dpt in dashboard.rescue.by_dpt %}<td>{{dpt.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <div class='clean-table'> - <h4>{% trans "surface by department (ha)"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for dpt in dashboard.rescue.surface_by_dpt %}<th>{{dpt.department__label}}</th>{% endfor %} - </tr> - <tr> - {% for dpt in dashboard.rescue.surface_by_dpt %}<td>{{dpt.number|m2_to_ha|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <div class='clean-table'> - <h4>{% trans "main towns by number"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for town in dashboard.rescue.towns %}<th>{{town.town__name}}</th>{% endfor %} - </tr> - <tr> - {% for town in dashboard.rescue.towns %}<td>{{town.number|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - <div class='clean-table'> - <h4>{% trans "main towns by surface (ha)"%}</h4> - <div class='clean-table-wrap'> - <table class="table table-striped"> - <tr> - {% for town in dashboard.rescue.surface_by_town %}<th>{{town.town__name}}</th>{% endfor %} - </tr> - <tr> - {% for town in dashboard.rescue.surface_by_town %}<td>{{town.number|m2_to_ha|intcomma}}</td>{% endfor%} - </tr> - </table> - </div> - </div> - - </div> -</div> -<script> - $( function() { - $( "#dashboard-files" ).accordion({ - collapsible: true, - heightStyle: "content" - }); - } ); -</script> -{% 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"), |