summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2020-09-30 19:05:12 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:20 +0100
commitb0b9cb123f9dfcc2584e80eef5fdfb77af24cacd (patch)
tree85df1e328015c57cc064e8ccdae78cf0e1a4e72d /archaeological_operations
parentcf38e81844d6828825c0cf5810cc9186b58174f9 (diff)
downloadIshtar-b0b9cb123f9dfcc2584e80eef5fdfb77af24cacd.tar.bz2
Ishtar-b0b9cb123f9dfcc2584e80eef5fdfb77af24cacd.zip
Stats: generation on demand
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html19
-rw-r--r--archaeological_operations/urls.py4
-rw-r--r--archaeological_operations/views.py37
3 files changed, 58 insertions, 2 deletions
diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html
index ef5de7f59..868040666 100644
--- a/archaeological_operations/templates/ishtar/sheet_operation.html
+++ b/archaeological_operations/templates/ishtar/sheet_operation.html
@@ -408,7 +408,24 @@
<div class="tab-pane fade" id="{{window_id}}-statistics"
role="tabpanel" aria-labelledby="{{window_id}}-statistics-tab">
<h3>{% trans "Statistics" %}</h3>
- <small class="centered"><em>{% trans "These numbers are updated hourly" %}</em></small>
+
+ <div class="row mt-2 mb-2">
+ <div class="col">
+ <div class="btn-group btn-group-sm" role="group"
+ aria-label="{% trans 'Export' %}">
+ <a class="btn btn-success"
+ onclick="long_wait();return true;"
+ href="{% url 'generate-stats-operation' item.pk %}">
+
+ {% trans "Regenerate statistics" %}
+ </a>
+ </div>
+ {% with item.last_stats_update as last_stats_update%}
+ {% if last_stats_update %}<small class="ml-2">
+ <em>{% trans "Last update:" %} {{last_stats_update}}</em>
+ </small>{% endif %}{% endwith %}
+ </div>
+ </div>
<h4>{% trans "Administrative acts" %}</h4>
<div class='row'>
diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py
index 77791058a..72e06641d 100644
--- a/archaeological_operations/urls.py
+++ b/archaeological_operations/urls.py
@@ -212,4 +212,8 @@ urlpatterns = [
'change_own_archaeologicalsite'])(
views.QAArchaeologicalSiteForm.as_view()),
name='site-qa-bulk-update-confirm', kwargs={"confirm": True}),
+
+ url(r'generate-stats-operation/(?P<pk>.+)/',
+ views.GenerateStatsOperation.as_view(),
+ name='generate-stats-operation'),
]
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index ecacdb560..897302828 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -25,6 +25,7 @@ from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render, redirect
+from django.views.generic import RedirectView
from ishtar_common.utils import ugettext_lazy as _, pgettext_lazy
from archaeological_operations import models
@@ -36,7 +37,8 @@ from ishtar_common.models import get_current_profile, IshtarSiteProfile, \
DocumentTemplate
from ishtar_common.utils import put_session_message, check_rights_condition
from ishtar_common.views import gen_generate_doc, QAItemEditForm, \
- QABaseLockView, wizard_is_available, QAItemForm
+ QABaseLockView, wizard_is_available, QAItemForm, IshtarMixin, \
+ LoginRequiredMixin
from ishtar_common.views_item import get_item, show_item, revert_item, \
new_qa_item
from ishtar_common.wizards import SearchWizard
@@ -644,3 +646,36 @@ class QAArchaeologicalSiteDuplicateFormView(QAItemForm):
class QAArchaeologicalSiteForm(QAItemEditForm):
model = models.ArchaeologicalSite
form_class = forms.QAArchaeologicalSiteFormMulti
+
+
+class GenerateStatsOperation(IshtarMixin, LoginRequiredMixin, RedirectView):
+ model = models.Operation
+
+ def get_redirect_url(self, *args, **kwargs):
+ return reverse('display-item',
+ args=[self.model.SLUG, self.item.pk]) + "#statistics"
+
+ def get(self, request, *args, **kwargs):
+ self.item = self.model.objects.get(pk=kwargs['pk'])
+ self.item._get_or_set_stats('_nb_acts', update=True)
+ self.item._get_or_set_stats('_nb_indexed_acts', update=True)
+ self.item._get_or_set_stats('_nb_context_records', update=True)
+ self.item._get_or_set_stats('_nb_context_records_by_type', update=True,
+ expected_type=list)
+ self.item._get_or_set_stats('_nb_context_records_by_periods',
+ update=True, expected_type=list)
+ self.item._get_or_set_stats('_nb_finds', update=True)
+ self.item._get_or_set_stats('_nb_finds_by_material_type', update=True,
+ expected_type=list)
+ self.item._get_or_set_stats('_nb_finds_by_types', update=True,
+ expected_type=list)
+ self.item._get_or_set_stats('_nb_finds_by_periods', update=True,
+ expected_type=list)
+ self.item._get_or_set_stats('_nb_documents', update=True)
+ self.item._get_or_set_stats('_nb_documents_by_types', update=True,
+ expected_type=list)
+ self.item._get_or_set_stats('_nb_stats_finds_by_ue', update=True)
+
+ return super(GenerateStatsOperation, self).get(request, *args, **kwargs)
+
+