diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-11-14 18:58:48 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:19 +0100 |
commit | 4746cd2938df3cf87ae338d22eb4f67f35bac960 (patch) | |
tree | 1b823f5e78e7214f84da3892e0729c0c2706ad6d | |
parent | 2fd7a306df69b723036a94346baa7ea17c9b7364 (diff) | |
download | Ishtar-4746cd2938df3cf87ae338d22eb4f67f35bac960.tar.bz2 Ishtar-4746cd2938df3cf87ae338d22eb4f67f35bac960.zip |
Remove dead code about dashboards
-rw-r--r-- | .coveragerc | 4 | ||||
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile.example | 4 | ||||
-rw-r--r-- | archaeological_files/admin.py | 6 | ||||
-rw-r--r-- | archaeological_files/forms.py | 51 | ||||
-rw-r--r-- | archaeological_files/ishtar_menu.py | 31 | ||||
-rw-r--r-- | archaeological_files/models.py | 4 | ||||
-rw-r--r-- | archaeological_files/tests.py | 79 | ||||
-rw-r--r-- | archaeological_finds/forms.py | 4 | ||||
-rw-r--r-- | archaeological_finds/forms_treatments.py | 90 | ||||
-rw-r--r-- | archaeological_operations/forms.py | 78 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/dashboards/dashboard_main.html | 52 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/dashboards/dashboard_main_detail.html | 250 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/dashboards/dashboard_main_detail_users.html | 32 | ||||
-rw-r--r-- | ishtar_common/tests.py | 38 | ||||
-rw-r--r-- | ishtar_common/urls.py | 6 | ||||
-rw-r--r-- | ishtar_common/views.py | 120 |
17 files changed, 88 insertions, 763 deletions
diff --git a/.coveragerc b/.coveragerc index 9fdc077d0..a0ec2734c 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,7 @@ [run] omit = - /management/* - /migrations/* + */management/* + */migrations/* [report] exclude_lines = diff --git a/.gitignore b/.gitignore index f1a44df9f..49299d597 100644 --- a/.gitignore +++ b/.gitignore @@ -46,4 +46,4 @@ scripts .pydevproject .settings src/ -.coverage-result* +coverage/ diff --git a/Makefile.example b/Makefile.example index 936a76d3a..346f3cd2f 100644 --- a/Makefile.example +++ b/Makefile.example @@ -120,12 +120,12 @@ run_libreoffice: coverage: clean ## launch test coverage cd $(project); coverage run --source="ishtar_common,archaeological_operations,\ archaeological_context_records,archaeological_files,archaeological_finds,archaeological_warehouse,\ - archaeological_files_pdl" ./manage.py test $(apps) && coverage report + archaeological_files_pdl" ./manage.py test $(apps) && coverage report -m > ../coverage/result-`date '+%Y-%m-%d-%H%M'` soft_coverage: clean ## launch test coverage (no db reinit) cd $(project); coverage run --rcfile=../.coveragerc --source="ishtar_common,archaeological_operations,\ archaeological_context_records,archaeological_files,archaeological_finds,archaeological_warehouse,\ - archaeological_files_pdl" ./manage.py test -k $(apps) && coverage report > ../.coverage-result + archaeological_files_pdl" ./manage.py test -k $(apps) && coverage report -m > ../coverage/result-`date '+%Y-%m-%d-%H%M'` pep8: pep8 --filename=*.py --ignore=W --exclude="manage.py,settings.py,migrations" --statistics --repeat . diff --git a/archaeological_files/admin.py b/archaeological_files/admin.py index 4f3bc5333..6f73c1340 100644 --- a/archaeological_files/admin.py +++ b/archaeological_files/admin.py @@ -174,6 +174,12 @@ class CopyPriceAgreementAdmin(GeneralTypeAdmin): def copy_price_agreement(self, request): form = None + if not hasattr(request.user, "ishtaruser") or request.user.ishtaruser.has_right( + "change_priceagreement", session=request.session): + self.message_user( + request, str(_("Cannot change price agreement.")) + ) + return HttpResponseRedirect(reverse("admin:login")) if "apply" in request.POST: form = CopyPriceForm(request.POST) diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index eb366b927..a75e5bf34 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -64,7 +64,6 @@ from ishtar_common.forms_common import get_town_field from archaeological_operations.forms import ( AdministrativeActForm, AdministrativeActOpeFormSelection, - SLICING, AdministrativeActModifForm, ParcelForm, ParcelFormSet, @@ -195,56 +194,6 @@ class FileFormMultiSelection(LockForm, MultiSearchForm): ) -DATE_SOURCE = (("creation", _("Creation date")), ("reception", _("Reception date"))) - - -class DashboardForm(IshtarForm): - slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, required=False) - department_detail = forms.BooleanField(label=_("Department detail"), required=False) - date_source = forms.ChoiceField( - label=_("Date get from"), choices=DATE_SOURCE, required=False - ) - file_type = forms.ChoiceField(label=_("File type"), choices=[], required=False) - saisine_type = forms.ChoiceField( - label=_("Saisine type"), choices=[], required=False - ) - after = forms.DateField(label=_("Date after"), widget=DatePicker, required=False) - before = forms.DateField(label=_("Date before"), widget=DatePicker, required=False) - - def __init__(self, *args, **kwargs): - if "prefix" not in kwargs: - kwargs["prefix"] = "files" - super(DashboardForm, self).__init__(*args, **kwargs) - self.fields["saisine_type"].choices = models.SaisineType.get_types() - self.fields["file_type"].choices = models.FileType.get_types() - - def get_show_detail(self): - return hasattr(self, "cleaned_data") and self.cleaned_data.get( - "department_detail" - ) - - def get_date_source(self): - date_source = "creation" - if hasattr(self, "cleaned_data") and self.cleaned_data.get("date_source"): - date_source = self.cleaned_data["date_source"] - return date_source - - def get_filter(self): - if not hasattr(self, "cleaned_data") or not self.cleaned_data: - return {} - date_source = self.get_date_source() - fltr = {} - if self.cleaned_data.get("saisine_type"): - fltr["saisine_type_id"] = self.cleaned_data["saisine_type"] - if self.cleaned_data.get("file_type"): - fltr["file_type_id"] = self.cleaned_data["file_type"] - if self.cleaned_data.get("after"): - fltr[date_source + "_date__gte"] = self.cleaned_data["after"] - if self.cleaned_data.get("before"): - fltr[date_source + "_date__lte"] = self.cleaned_data["before"] - return fltr - - class FileFormGeneral(ManageOldType): form_label = _("General") associated_models = { diff --git a/archaeological_files/ishtar_menu.py b/archaeological_files/ishtar_menu.py index 3d6b85466..517b0276d 100644 --- a/archaeological_files/ishtar_menu.py +++ b/archaeological_files/ishtar_menu.py @@ -100,34 +100,3 @@ MENU_SECTIONS = [ ), ), ] -""" - (100, - SectionItem( - 'dashboard', _("Dashboard"), - profile_restriction='files', - css='menu-file', - childs=[MenuItem('dashboard_main', _("General informations"), - model=models.File, - access_controls=['change_file', 'change_own_file']), - MenuItem('dashboard_file', _("Archaeological files"), - model=models.File, - access_controls=['change_file', 'change_own_file']), - ]), - ), - SectionItem('dashboard', _("Dashboard"), - childs=[ - MenuItem('dashboard_main', _("General informations"), - model=models.File, - access_controls=['change_file', 'change_own_file']), - MenuItem('dashboard_file', _("Archaeological files"), - model=models.File, - access_controls=['change_file', 'change_own_file']), - #MenuItem('dashboard_treatment', _("Treatments"), - # model=models.Treatment, - # access_controls=['change_treatment',]), - #MenuItem('dashboard_warehouse', _("Warehouses"), - # model=models.Warehouse, - # access_controls=['change_warehouse',]), - ]), - ] -""" diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 2cd42d5ba..bcc90ab4f 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -89,7 +89,7 @@ class PriceAgreement(GeneralType): class Job(GeneralType): price_agreement = models.ForeignKey( PriceAgreement, verbose_name=_("Price agreement"), blank=True, null=True, - on_delete=models.CASCADE + on_delete=models.CASCADE, related_name="jobs" ) ground_daily_cost = models.FloatField(_("Ground daily cost"), blank=True, null=True) daily_cost = models.FloatField(_("Daily cost"), blank=True, null=True) @@ -199,7 +199,7 @@ ES_UNITS_DAYS = { class EquipmentServiceCost(models.Model): price_agreement = models.ForeignKey( PriceAgreement, verbose_name=_("Price agreement"), blank=True, null=True, - on_delete=models.CASCADE + on_delete=models.CASCADE, related_name="equipment_service_costs" ) equipment_service_type = models.ForeignKey( EquipmentServiceType, verbose_name=_("Equipment/Service"), on_delete=models.CASCADE diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py index 1d54584da..7145cb836 100644 --- a/archaeological_files/tests.py +++ b/archaeological_files/tests.py @@ -27,13 +27,15 @@ from django.urls import reverse from ishtar_common.tests import ( TestCase, - COMMON_FIXTURES, create_superuser, AutocompleteTestBase, AcItem, + FILE_TOWNS_FIXTURES, ) from ishtar_common.models import Town, IshtarSiteProfile +from ishtar_common.utils import ugettext_lazy as _ + from archaeological_files import models, views from archaeological_operations.models import ( Parcel, @@ -41,7 +43,6 @@ from archaeological_operations.models import ( ActType, AdministrativeAct, ) -from ishtar_common.tests import FILE_TOWNS_FIXTURES from archaeological_operations.tests import OperationInitTest, FileInit @@ -65,7 +66,7 @@ class FileTest(TestCase, FileInit): model = models.File def setUp(self): - IshtarSiteProfile.objects.create() + self.profile = IshtarSiteProfile.objects.create() self.create_file() def test_external_id(self): @@ -246,6 +247,77 @@ class FileTest(TestCase, FileInit): self.assertEqual(response.status_code, 200) self.assertIn('class="card sheet"', response.content.decode()) + def test_select_page(self): + url = "file_search" + # need auth + response = self.client.get(reverse(url)) + self.assertRedirects(response, "/", status_code=302) + # need file module + self.login_as_superuser() + response = self.client.get(reverse(url)) + self.assertRedirects(response, "/file_search/general-file_search", + status_code=302) + + +class FileCostTest(TestCase, FileInit): + fixtures = FILE_TOWNS_FIXTURES + model = models.File + + def setUp(self): + IshtarSiteProfile.objects.create() + self.create_file() + + def test_admin_copy_cost(self): + default = models.PriceAgreement.objects.all()[0] + new = models.PriceAgreement.objects.create(label="New") + ln_equipment_service_costs = default.equipment_service_costs.count() + self.assertNotEqual(ln_equipment_service_costs, 0) + self.assertEqual(new.equipment_service_costs.count(), 0) + ln_jobs = default.jobs.count() + self.assertNotEqual(ln_jobs, 0) + self.assertEqual(new.jobs.count(), 0) + url = "/admin/archaeological_files/priceagreement/copy-price-agreement/" + response = self.client.get(url) + self.assertRedirects( + response, + reverse("admin:login"), + status_code=302, + ) + self.login_as_superuser() + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + response = self.client.post( + url, + {"source": default.pk, "destination": default.pk, + "action": "import_generic", "apply": "1"} + ) + # cannot copy on same price agreement (nonsense) + self.assertContains( + response, + str(_("Source and destination must be different.")) + ) + response = self.client.post( + url, + {"source": default.pk, "destination": new.pk, + "action": "import_generic", "apply": "1"} + ) + self.assertEqual(response.status_code, 302) + new = models.PriceAgreement.objects.get(pk=new.pk) + self.assertEqual(new.jobs.count(), ln_jobs) + self.assertEqual(new.equipment_service_costs.count(), + ln_equipment_service_costs) + # repost - verify no duplication + response = self.client.post( + url, + {"source": default.pk, "destination": new.pk, + "action": "import_generic", "apply": "1"} + ) + self.assertEqual(response.status_code, 302) + new = models.PriceAgreement.objects.get(pk=new.pk) + self.assertEqual(new.jobs.count(), ln_jobs) + self.assertEqual(new.equipment_service_costs.count(), + ln_equipment_service_costs) + def test_preventive_price_agreement(self): pk = self.item.pk self.login_as_superuser() @@ -303,7 +375,6 @@ class FileTest(TestCase, FileInit): self.assertEqual(q_equip.count(), 0) self.assertEqual(q_job.count(), 0) - def test_preventive(self): pk = self.item.pk self.item.price_agreement_id = models.PriceAgreement.objects.all()[0] diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 5fa648962..0b3c842d4 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -58,9 +58,7 @@ from archaeological_finds.forms_treatments import ( AdministrativeActTreatmentFileForm, AdministrativeActTreatmentFileFormSelection, AdministrativeActTreatmentFileModifForm, - DashboardForm as DashboardTreatmentForm, N1TreatmentForm, - DashboardTreatmentFileForm, QAFindTreatmentForm, OneNTreatmentForm, ) @@ -126,8 +124,6 @@ __all__ = [ "AdministrativeActTreatmentFileFormSelection", "AdministrativeActTreatmentFormSelection", "AdministrativeActTreatmentFileModifForm", - "DashboardTreatmentForm", - "DashboardTreatmentFileForm", "RecordFormSelection", "FindForm", "SimpleFindForm", diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index 907ea17b4..0d87a5eea 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -551,50 +551,6 @@ class QAFindTreatmentForm(IshtarForm): find.history_modifier = user find.save() - -SLICING = (("month", _("months")), ('year', _("years")),) -DATE_SOURCE = (("start", _("Start date")), ("end", _("Closing date")),) - - -class DashboardForm(IshtarForm): - slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, - required=False) - date_source = forms.ChoiceField( - label=_("Date get from"), choices=DATE_SOURCE, required=False) - treatment_type = forms.ChoiceField(label=_("Treatment type"), choices=[], - required=False) - after = forms.DateField(label=_("Date after"), - widget=DatePicker, required=False) - before = forms.DateField(label=_("Date before"), - widget=DatePicker, required=False) - - def __init__(self, *args, **kwargs): - if 'prefix' not in kwargs: - kwargs['prefix'] = 'treatments' - super(DashboardForm, self).__init__(*args, **kwargs) - self.fields['treatment_type'].choices = \ - models.TreatmentType.get_types() - - def get_date_source(self): - date_source = 'start' - if hasattr(self, 'cleaned_data') and \ - self.cleaned_data.get('date_source'): - date_source = self.cleaned_data['date_source'] - return date_source - - def get_filter(self): - if not hasattr(self, 'cleaned_data') or not self.cleaned_data: - return {} - fltr = {} - date_source = self.get_date_source() - if self.cleaned_data.get('treatment_type'): - fltr['treatment_types__pk'] = self.cleaned_data['treatment_type'] - if self.cleaned_data.get('after'): - fltr[date_source + '_date__gte'] = self.cleaned_data['after'] - if self.cleaned_data.get('before'): - fltr[date_source + '_date__lte'] = self.cleaned_data['before'] - return fltr - # administrative act treatment @@ -873,52 +829,6 @@ class TreatmentFileDeletionForm(FinalForm): confirm_end_msg = _("Would you like to delete this treatment request?") -DATE_SOURCE_FILE = ( - ("creation", _("Creation date")), - ("reception", _("Reception date")), - ("end", _("Closing date")),) - - -class DashboardTreatmentFileForm(IshtarForm): - slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, - required=False) - date_source = forms.ChoiceField( - label=_("Date get from"), choices=DATE_SOURCE_FILE, required=False) - treatmentfile_type = forms.ChoiceField(label=_("Treatment request type"), - choices=[], required=False) - after = forms.DateField(label=_("Date after"), - widget=DatePicker, required=False) - before = forms.DateField(label=_("Date before"), - widget=DatePicker, required=False) - - def __init__(self, *args, **kwargs): - if 'prefix' not in kwargs: - kwargs['prefix'] = 'treatmentfiles' - super(DashboardTreatmentFileForm, self).__init__(*args, **kwargs) - self.fields['treatmentfile_type'].choices = \ - models.TreatmentFileType.get_types() - - def get_date_source(self): - date_source = 'creation' - if hasattr(self, 'cleaned_data') and \ - self.cleaned_data.get('date_source'): - date_source = self.cleaned_data['date_source'] - return date_source - - def get_filter(self): - if not hasattr(self, 'cleaned_data') or not self.cleaned_data: - return {} - fltr = {} - date_source = self.get_date_source() - if self.cleaned_data.get('treatmentfile_type'): - fltr['type__pk'] = self.cleaned_data['treatmentfile_type'] - if self.cleaned_data.get('after'): - fltr[date_source + '_date__gte'] = self.cleaned_data['after'] - if self.cleaned_data.get('before'): - fltr[date_source + '_date__lte'] = self.cleaned_data['before'] - return fltr - - class AdministrativeActTreatmentFileSelect(TableSelect): _model = AdministrativeAct diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 06ee160d0..7203da6c6 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -673,84 +673,6 @@ class OperationFormFileChoice(IshtarForm): validators=[valid_id(File)], required=False) -SLICING = (("month", _("months")), ('year', _("years")),) - -DATE_SOURCE = (('creation', _("Creation date")), - ("start", _("Start of field work"))) - -PREVENTIVE_RESARCH = (('all', _('All')), - ('preventive', _("Preventive")), - ('research', _("Research")),) - - -class DashboardForm(IshtarForm): - slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, - required=False) - department_detail = forms.BooleanField( - label=_("Department detail"), required=False) - date_source = forms.ChoiceField( - label=_("Date get from"), choices=DATE_SOURCE, required=False) - preventive_research = forms.ChoiceField( - label=_("Preventive/Research"), choices=PREVENTIVE_RESARCH, - required=False) - operation_type = forms.ChoiceField(label=_("Operation type"), choices=[], - required=False) - operator = forms.ChoiceField(label=_("Operator"), choices=[], - required=False) - after = DateField(label=_("Date after"), required=False) - before = DateField(label=_("Date before"), required=False) - with_report = forms.BooleanField(label=_("With reports"), required=False) - with_finds = forms.BooleanField(label=_("With finds"), required=False) - - def __init__(self, *args, **kwargs): - if 'prefix' not in kwargs: - kwargs['prefix'] = 'operations' - super(DashboardForm, self).__init__(*args, **kwargs) - self.fields['operation_type'].choices = \ - models.OperationType.get_types() - self.fields['operator'].choices = [('', '--')] - self.fields['operator'].choices += [ - (orga.pk, orga.name) - for orga in Organization.objects.filter(operator__isnull=False) - .order_by('name').distinct().all()] - - def get_show_detail(self): - return hasattr(self, 'cleaned_data') and \ - self.cleaned_data.get('department_detail') - - def get_date_source(self): - date_source = 'creation' - if hasattr(self, 'cleaned_data') and \ - self.cleaned_data.get('date_source'): - date_source = self.cleaned_data['date_source'] - return date_source - - def get_filter(self): - if not hasattr(self, 'cleaned_data') or not self.cleaned_data: - return {} - date_source = self.get_date_source() - fltr = {} - if self.cleaned_data.get('preventive_research'): - preventive_research = self.cleaned_data['preventive_research'] - if preventive_research == 'preventive': - fltr['operation_type__preventive'] = True - elif preventive_research == 'research': - fltr['operation_type__preventive'] = False - if self.cleaned_data.get('operation_type'): - fltr['operation_type_id'] = self.cleaned_data['operation_type'] - if self.cleaned_data.get('operator'): - fltr['operator_id'] = self.cleaned_data['operator'] - if self.cleaned_data.get('after'): - fltr[date_source + '_date__gte'] = self.cleaned_data['after'] - if self.cleaned_data.get('before'): - fltr[date_source + '_date__lte'] = self.cleaned_data['before'] - if self.cleaned_data.get('with_report'): - fltr['report_delivery_date__isnull'] = False - if self.cleaned_data.get('with_finds'): - fltr['context_record__base_finds__isnull'] = False - return fltr - - class OperationFormGeneral(CustomForm, ManageOldType): HEADERS = {} form_label = _("General") 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}} -<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/jqplot/jquery.jqplot.min.js?ver={{VERSION}}"></script> -<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/jqplot/plugins/jqplot.canvasTextRenderer.min.js?ver={{VERSION}}"></script> -<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/jqplot/plugins/jqplot.canvasAxisLabelRenderer.min.js?ver={{VERSION}}"></script> -<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js?ver={{VERSION}}"></script> -<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/jqplot/plugins/jqplot.highlighter.min.js?ver={{VERSION}}"></script> -<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/jqplot/plugins/jqplot.pieRenderer.min.js?ver={{VERSION}}"></script> -<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/jqplot/plugins/jqplot.dateAxisRenderer.min.js?ver={{VERSION}}"></script> -<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/jqplot/plugins/jqplot.cursor.min.js?ver={{VERSION}}"></script> -<link rel="stylesheet" href="{{STATIC_URL}}js/jqplot/jquery.jqplot.min.css?ver={{VERSION}}" /> -{% endblock %} -{% block content %} -<script type="text/javascript"> -$(function() { - $('#dashboard .nav-link').click(function () { - var url = $(this).attr('data-url'); - dynamic_load(url, "#dashboard .card-body"); - $('#dashboard li').removeClass('active'); - $('#dashboard li').removeClass('show'); - $(this).parent().tab('show'); - }) - $('#dashboard li:first-child a').click(); -}); - -</script> -<div id='dashboard' class="card"> - <div class="card-header"> - <ul class="nav nav-tabs card-header-tabs"> - {% for label, app in app_list %} - <li class="nav-item" id="{{app}}-tab"> - <a class="nav-link" href="#{{app}}-pane" - data-url="{% url 'dashboard-main-detail' app %}">{{label}}</a> - </li>{% endfor %} - <li class="nav-item" id="users-tab"> - <a class="nav-link" href="#users-pane" - data-url="{% url 'dashboard-main-detail' 'users' %}">{% trans "Users" %}</a> - </li> - </ul> - </div> - <div class="card-body tab-content"> - {% for label, app in app_list %} - <div class="tab-pane{% if forloop.counter0 == 0%} active{% endif %}" id="{{app}}-pane" - role="tabpanel" aria-labelledby="{{app}}-tab"></div>{% endfor %} - <div class="tab-pane" id="users-pane" role="tabpanel" - aria-labelledby="users-tab"></div> - </div> -</div> - -{% 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 %} -<div id="{{unique_id}}-tab"> - <h4>{% trans "Numbers" %}</h4> - {% if form %} - <div class='form'> - <form method='post' action="{% url 'dashboard-main-detail' item_name %}" id='{{unique_id}}_form'> - {% csrf_token %} - {% bs_form form %} - <div class="text-center"> - <button type='button' id="search_{{unique_id}}" - class="btn btn-primary"> - {% trans "Change" %}</button> - </div> - </form> - </div> - {% endif %} - <p><strong>{% trans "Total:" %}</strong> {{dashboard.total_number|intcomma}}</p> - <div> - <div id="chart_{{unique_id}}" - style="height:400px; width:700px; margin-right:auto; margin-left:auto"></div> - <p class='alert alert-info'> - {% trans 'Draw rectangle on the graph to zoom. Double-click to reinitialize.' %} - </p> - <div class='form chart-img-form'> - <div class="text-center"> - <button id="chart_img_display_{{unique_id}}" - type='button' class='btn btn-secondary'> - {% trans "Display as an image" %} - </button> - </div> - <div id="chart_img_{{unique_id}}" class='chart-img'> - <div class="card"> - <div id="img_{{unique_id}}" - class="card-img-top text-center"></div> - <div class="card-body"> - <div class='alert alert-info'> - {% trans 'Right-click on this image to save it.' %} - </div> - </div> - </div> - </div> - </div> - </div> - <hr> - <table class="table table-striped"> - {% for idx, lbl, values in dashboard.values %} - <tr> - <th>{{lbl}}</th> - {% for value in values reversed %}{% if forloop.parentloop.counter0 %}<td>{% else %}<th>{%endif%}{{value|date_formating }}{% if forloop.parentloop.counter0 %}</td>{% else %}</th>{%endif%}{% endfor%} - </tr> - {% endfor%} - </table> - <hr> - {% if dashboard.periods %} - <h4>{% trans "By years" %}</h4> - <dl class="row"> - <dt class="col-sm-3"> - {% trans "Average:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.average}} - </dd> - - <dt class="col-sm-3"> - {% trans "Variance:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.variance}} - </dd> - - <dt class="col-sm-3"> - {% trans "Standard deviation:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.standard_deviation}} - </dd> - <dt class="col-sm-3"> - {% trans "Median:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.median}} - </dd> - <dt class="col-sm-3"> - {% trans "Mode:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.mode}} - </dd> - </dl> - <hr> - {% endif %} - {% if dashboard.operation_average %} - <h4>{% trans "By operations" %}</h4> - <dl class="row"> - <dt class="col-sm-3"> - {% trans "Average:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.operation_average}} - </dd> - - <dt class="col-sm-3"> - {% trans "Variance:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.operation_variance}} - </dd> - - <dt class="col-sm-3"> - {% trans "Standard deviation:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.operation_standard_deviation}} - </dd> - <dt class="col-sm-3"> - {% trans "Median:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.operation_median}} - </dd> - <dt class="col-sm-3"> - {% trans "Mode:" %} - </dt> - <dd class="col-sm-9"> - {{dashboard.operation_mode}} - </dd> - </dl> - <hr> - {% endif %} - <h4>{% trans "Created last" %}</h4> - <table class="table table-striped"> - <tr><th>{{lbl}}</th><th>{% trans "Created" %}</th><th></th></tr> - {% for item in dashboard.lasts %}<tr> - <td class='ref'>{{item}}</td> - <td>{{item.history_date}}</td> - <td>{% if item.get_show_url %}<a href="#" onclick='load_window("{{item.get_show_url}}")'> - <i class="fa fa-info-circle" aria-hidden="true"></i> - </a>{%endif%}</td> - </tr>{% endfor %} - </table> - <hr> - <h4>{% trans "Recent changes" %}</h4> - <table class="table table-striped"> - <tr><th>{{lbl}}</th><th>{% trans "Modified" %}</th><th></th></tr> - {% for item in dashboard.recents %}<tr> - <td class='ref'>{{item}}</td> - <td>{{item.history_date}}</td> - <td>{% if item.get_show_url %}<a href="#" onclick='load_window("{{item.get_show_url}}")'> - <i class="fa fa-info-circle" aria-hidden="true"></i> - </a>{%endif%}</td> - </tr>{% endfor %} - </table> -</div> -<script language="javascript" type="text/javascript"> -$(document).ready(function(){ - -{% for idx, lbl, values in dashboard.values %} {% if forloop.counter0 > 0 %} var values_{{forloop.counter0}}_{{unique_id}} = []; {% for idx, lbl, values in dashboard.values %} {% for value in values %} {% if forloop.parentloop.counter0 == 0 %} values_{{forloop.parentloop.parentloop.counter0}}_{{unique_id}}.push([{{VALUE_QUOTE|safe}}{{value}}{{VALUE_QUOTE|safe}}, 0]); {% elif forloop.parentloop.parentloop.counter0 == forloop.parentloop.counter0 %} values_{{forloop.parentloop.parentloop.counter0}}_{{unique_id}}[{{forloop.counter0}}][1] = {{value}}; {% endif %} {% endfor%} {% endfor%} {% endif %} {% endfor %} - -{% comment %} -# less compact version -{% for idx, lbl, values in dashboard.values %} - {% if forloop.counter0 > 0 %} - {% for idx, lbl, values in dashboard.values %} - {% for value in values %} - {% if forloop.parentloop.counter0 == 0 %} - values_{{forloop.parentloop.counter0}}_{{unique_id}}.push([{{VALUE_QUOTE|safe}}{{value}}{{VALUE_QUOTE|safe}}, 0]); - {% elif forloop.parentloop.counter0 == forloop.counter0 %} - values_{{forloop.counter0}}_{{unique_id}}[{{forloop.counter0}}][1] = {{value}}; - {% endif %} - {% endfor%} - {% endfor%} - {% endif %} -{% endfor %} -{% endcomment %} - - -if (typeof values_1_{{unique_id}} === 'undefined' - || values_1_{{unique_id}}.length == 0){ - - $('#chart_img_{{unique_id}}').hide(); - $('#chart_{{unique_id}}').html( - "<p class='alert alert-warning'>{% trans 'No data for these criteria.' %}</p>" - ); - $('#chart_{{unique_id}}').css('height', 'auto'); - -} else { -var showmarker = false; -if (values_1_{{unique_id}}.length < 25){ - var showmarker = true; -} - -var plot_{{unique_id}} = $.jqplot('chart_{{unique_id}}', - [{% for idx, lbl, values in dashboard.values %}{% if forloop.counter0 > 0 %} {% if forloop.counter0 > 1 %}, {% endif%} values_{{forloop.counter0}}_{{unique_id}} {% endif %} {% endfor%}], { - axes:{ {%ifequal slicing 'year'%} - xaxis:{ - label:'{% trans "Year" %}', - tickOptions: { - formatString: "%d" - } - },{%endifequal%}{%ifequal slicing 'month'%} - xaxis:{ - label:'{% trans "Month" %}', - renderer:$.jqplot.DateAxisRenderer, - tickRenderer:$.jqplot.CanvasAxisTickRenderer, - tickOptions:{ - formatString:'%b %Y', - angle:-25 - } - },{%endifequal%} - yaxis:{ - label:'{% trans "Number"%}', - min:0 - } - }, - highlighter: { - show: true, - sizeAdjust: 7.5 - }, - series:[{% for label in dashboard.serie_labels %} - {%if forloop.counter0%}, {% endif %}{label:"{{label}}", showmarker:showmarker}{% endfor %} - ], - cursor:{ - show: true, - zoom:true, - showTooltip:false - }, - legend: { show:true, location: 'nw' } - }); - - $('#chart_img_display_{{unique_id}}').click(function(){ - $('#chart_img_{{unique_id}}').hide(); - $('#img_{{unique_id}}').html( - $('<img/>').attr( - 'src', $('#chart_{{unique_id}}').jqplotToImageStr({}) - ) - ); - $('#chart_img_{{unique_id}}').show('slow'); - }); -} - -$('#search_{{unique_id}}').click(function (){ - $.post("{% url 'dashboard-main-detail' item_name %}", - $("#{{unique_id}}_form").serialize(), - function(data){ - $("#{{unique_id}}-tab").parent().html(data); - }); - return false; -}); -}); -</script> 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 %} -<div class='dashboard centered'> - <div id="user_chart" style="height:300px; width:700px;margin-left: auto;margin-right: auto;"></div> - <table class='table table-striped'> - <tr><th>{% trans "User type" %}</th><th>{% trans "Number" %}</th></tr> - {% for user_type in ishtar_users.types %} - <tr> - <td class='string'>{{user_type.person__person_types__label}}{#TODO: Display all#}</td> - <td>{{user_type.number}}</td> - </tr> - {% endfor %} - </table> -</div> -<script language="javascript" type="text/javascript"> -$(document).ready(function(){ - var values_users = []; - {% for user_type in ishtar_users.types %} - values_users.push(['{{user_type.person__person_types__label}}', {{user_type.number}}]); {% endfor%} - - var plot_users = jQuery.jqplot ('user_chart', [values_users], - { - seriesDefaults: { - renderer: jQuery.jqplot.PieRenderer, - rendererOptions: { - showDataLabels: true - } - }, - legend: { show:true, location: 'e' } - } - ); -}); -</script>
\ 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<item_name>[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: |