From 4746cd2938df3cf87ae338d22eb4f67f35bac960 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 14 Nov 2022 18:58:48 +0100 Subject: Remove dead code about dashboards --- .../ishtar/dashboards/dashboard_main.html | 52 ----- .../ishtar/dashboards/dashboard_main_detail.html | 250 --------------------- .../dashboards/dashboard_main_detail_users.html | 32 --- ishtar_common/tests.py | 38 ---- ishtar_common/urls.py | 6 - ishtar_common/views.py | 120 ---------- 6 files changed, 498 deletions(-) delete mode 100644 ishtar_common/templates/ishtar/dashboards/dashboard_main.html delete mode 100644 ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html delete mode 100644 ishtar_common/templates/ishtar/dashboards/dashboard_main_detail_users.html (limited to 'ishtar_common') diff --git a/ishtar_common/templates/ishtar/dashboards/dashboard_main.html b/ishtar_common/templates/ishtar/dashboards/dashboard_main.html deleted file mode 100644 index 692e435a3..000000000 --- a/ishtar_common/templates/ishtar/dashboards/dashboard_main.html +++ /dev/null @@ -1,52 +0,0 @@ -{% extends "base.html" %} -{% load i18n %} -{% block extra_head %} -{{form.media}} - - - - - - - - - -{% endblock %} -{% block content %} - -
-
- -
-
- {% for label, app in app_list %} -
{% endfor %} -
-
-
- -{% endblock %} diff --git a/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html b/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html deleted file mode 100644 index 75a7aa542..000000000 --- a/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html +++ /dev/null @@ -1,250 +0,0 @@ -{% load i18n date_formating humanize table_form %} -
-

{% trans "Numbers" %}

- {% if form %} -
-
- {% csrf_token %} - {% bs_form form %} -
- -
-
-
- {% endif %} -

{% trans "Total:" %} {{dashboard.total_number|intcomma}}

-
-
-

- {% trans 'Draw rectangle on the graph to zoom. Double-click to reinitialize.' %} -

-
-
- -
-
-
-
-
-
- {% trans 'Right-click on this image to save it.' %} -
-
-
-
-
-
-
- - {% for idx, lbl, values in dashboard.values %} - - - {% for value in values reversed %}{% if forloop.parentloop.counter0 %}{%endif%}{% endfor%} - - {% endfor%} -
{{lbl}}{% else %}{%endif%}{{value|date_formating }}{% if forloop.parentloop.counter0 %}{% else %}
-
- {% if dashboard.periods %} -

{% trans "By years" %}

-
-
- {% trans "Average:" %} -
-
- {{dashboard.average}} -
- -
- {% trans "Variance:" %} -
-
- {{dashboard.variance}} -
- -
- {% trans "Standard deviation:" %} -
-
- {{dashboard.standard_deviation}} -
-
- {% trans "Median:" %} -
-
- {{dashboard.median}} -
-
- {% trans "Mode:" %} -
-
- {{dashboard.mode}} -
-
-
- {% endif %} - {% if dashboard.operation_average %} -

{% trans "By operations" %}

-
-
- {% trans "Average:" %} -
-
- {{dashboard.operation_average}} -
- -
- {% trans "Variance:" %} -
-
- {{dashboard.operation_variance}} -
- -
- {% trans "Standard deviation:" %} -
-
- {{dashboard.operation_standard_deviation}} -
-
- {% trans "Median:" %} -
-
- {{dashboard.operation_median}} -
-
- {% trans "Mode:" %} -
-
- {{dashboard.operation_mode}} -
-
-
- {% endif %} -

{% trans "Created last" %}

- - - {% for item in dashboard.lasts %} - - - - {% endfor %} -
{{lbl}}{% trans "Created" %}
{{item}}{{item.history_date}}{% if item.get_show_url %} - - {%endif%}
-
-

{% trans "Recent changes" %}

- - - {% for item in dashboard.recents %} - - - - {% endfor %} -
{{lbl}}{% trans "Modified" %}
{{item}}{{item.history_date}}{% if item.get_show_url %} - - {%endif%}
-
- diff --git a/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail_users.html b/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail_users.html deleted file mode 100644 index f6ead643a..000000000 --- a/ishtar_common/templates/ishtar/dashboards/dashboard_main_detail_users.html +++ /dev/null @@ -1,32 +0,0 @@ -{% load i18n %} -
-
- - - {% for user_type in ishtar_users.types %} - - - - - {% endfor %} -
{% trans "User type" %}{% trans "Number" %}
{{user_type.person__person_types__label}}{#TODO: Display all#}{{user_type.number}}
-
- \ No newline at end of file diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index c5d9f5c67..f624314e0 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -3607,44 +3607,6 @@ class AccountWizardTest(WizardTest, TestCase): self.assertEqual(models.IshtarUser.objects.count(), self.account_number + 1) -class DashboardTest(TestCase): - def setUp(self): - self.username, self.password, self.user = create_superuser() - profile, created = models.IshtarSiteProfile.objects.get_or_create( - slug="default", active=True - ) - profile.files = True - profile.context_record = True - profile.find = True - profile.warehouse = True - profile.save() - - def test_dashboard(self): - c = Client() - c.login(username=self.username, password=self.password) - - url = "dashboard-main-detail" - - response = c.get(reverse(url, kwargs={"item_name": "zorglub"})) - self.assertEqual(response.status_code, 404) - - for item in [ - "users", - "files", - "treatmentfiles", - "treatments", - "operations", - "contextrecords", - "finds", - ]: - response = c.get(reverse(url, kwargs={"item_name": item})) - self.assertEqual( - response.status_code, - 200, - "Reaching dashboard for item: {} return an error.".format(url), - ) - - class CleanMedia(TestCase): def test_rename(self): test_names = [ diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index b7e5f46d1..8a0886551 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -297,12 +297,6 @@ actions = r"|".join(actions) # other views urlpatterns += [ # General - url(r"dashboard-main/$", views.dashboard_main, name="dashboard-main"), - url( - r"dashboard-main/(?P[a-z-]+)/$", - views.dashboard_main_detail, - name="dashboard-main-detail", - ), url( r"update-current-item/$", views.update_current_item, name="update-current-item" ), diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 4cdbcf8c9..9e4177f45 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -55,14 +55,8 @@ from markdown import markdown from . import models from archaeological_context_records.models import ContextRecord -from archaeological_files.forms import DashboardForm as DashboardFormFile from archaeological_files.models import File -from archaeological_finds.forms import ( - DashboardTreatmentForm, - DashboardTreatmentFileForm, -) from archaeological_finds.models import Find, Treatment, TreatmentFile -from archaeological_operations.forms import DashboardForm as DashboardFormOpe from archaeological_operations.models import Operation, ArchaeologicalSite from archaeological_warehouse.models import Warehouse from ishtar_common import forms_common as forms @@ -991,120 +985,6 @@ def action(request, action_slug, obj_id=None, *args, **kwargs): return render(request, "index.html", dct) -def dashboard_main(request, dct, obj_id=None, *args, **kwargs): - """ - Main dashboard - """ - app_list = [] - profile = models.get_current_profile() - if profile.files: - app_list.append((_("Archaeological files"), "files")) - app_list.append((_("Operations"), "operations")) - if profile.context_record: - app_list.append((_("Context records"), "contextrecords")) - if profile.find: - app_list.append((_("Finds"), "finds")) - if profile.warehouse: - app_list.append((_("Treatment requests"), "treatmentfiles")) - app_list.append((_("Treatments"), "treatments")) - dct = {"app_list": app_list} - return render(request, "ishtar/dashboards/dashboard_main.html", dct) - - -DASHBOARD_FORMS = { - "files": DashboardFormFile, - "operations": DashboardFormOpe, - "treatments": DashboardTreatmentForm, - "treatmentfiles": DashboardTreatmentFileForm, -} - - -def dashboard_main_detail(request, item_name): - """ - Specific tab of the main dashboard - """ - if item_name == "users": - dct = {"ishtar_users": models.UserDashboard()} - return render( - request, "ishtar/dashboards/dashboard_main_detail_users.html", dct - ) - form = None - slicing, date_source, fltr, show_detail = "year", None, {}, False - profile = models.get_current_profile() - has_form = ( - (item_name == "files" and profile.files) - or item_name == "operations" - or (item_name in ("treatmentfiles", "treatments") and profile.warehouse) - ) - if has_form: - slicing = "month" - if item_name in DASHBOARD_FORMS: - if request.method == "POST": - form = DASHBOARD_FORMS[item_name](request.POST) - if form.is_valid(): - slicing = form.cleaned_data["slicing"] - fltr = form.get_filter() - if hasattr(form, "get_date_source"): - date_source = form.get_date_source() - if hasattr(form, "get_show_detail"): - show_detail = form.get_show_detail() - else: - form = DASHBOARD_FORMS[item_name]() - lbl, dashboard = None, None - dashboard_kwargs = {} - if has_form: - dashboard_kwargs = {"slice": slicing, "fltr": fltr, "show_detail": show_detail} - # date_source is only relevant when the form has set one - if date_source: - dashboard_kwargs["date_source"] = date_source - if item_name == "files" and profile.files: - lbl, dashboard = ( - _("Archaeological files"), - models.Dashboard(File, **dashboard_kwargs), - ) - elif item_name == "operations": - from archaeological_operations.models import Operation - - lbl, dashboard = ( - _("Operations"), - models.Dashboard(Operation, **dashboard_kwargs), - ) - elif item_name == "contextrecords" and profile.context_record: - lbl, dashboard = ( - _("Context records"), - models.Dashboard(ContextRecord, slice=slicing, fltr=fltr), - ) - elif item_name == "finds" and profile.find: - lbl, dashboard = (_("Finds"), models.Dashboard(Find, slice=slicing, fltr=fltr)) - elif item_name == "treatmentfiles" and profile.warehouse: - lbl, dashboard = ( - _("Treatment requests"), - models.Dashboard(TreatmentFile, **dashboard_kwargs), - ) - elif item_name == "treatments" and profile.warehouse: - if "date_source" not in dashboard_kwargs: - dashboard_kwargs["date_source"] = "start" - lbl, dashboard = ( - _("Treatments"), - models.Dashboard(Treatment, **dashboard_kwargs), - ) - if not lbl: - raise Http404 - dct = { - "lbl": lbl, - "dashboard": dashboard, - "item_name": item_name.replace("-", "_"), - "VALUE_QUOTE": "" if slicing == "year" else "'", - "form": form, - "slicing": slicing, - } - n = datetime.datetime.now() - dct["unique_id"] = ( - dct["item_name"] + "_" + "%d_%d_%d" % (n.minute, n.second, n.microsecond) - ) - return render(request, "ishtar/dashboards/dashboard_main_detail.html", dct) - - def reset_wizards(request): # dynamically execute each reset_wizards of each ishtar app for app in settings.INSTALLED_APPS: -- cgit v1.2.3