summaryrefslogtreecommitdiff
path: root/ishtar_common/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/views.py')
-rw-r--r--ishtar_common/views.py60
1 files changed, 54 insertions, 6 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 5627f4a93..2772bd44f 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -142,11 +142,48 @@ def tiny_redirect(request, url_id):
return redirect(link_db.link)
+def _count_stats(model):
+ cache_key = f"{settings.PROJECT_SLUG}-stats-{model.__name__}"
+ value = cache.get(cache_key)
+ if value:
+ return value
+ value = model.objects.count()
+ cache.set(cache_key, value, settings.CACHE_TIMEOUT)
+ return value
+
+
+def _get_statistics(profile):
+ stats = [
+ (_("Operations"), _count_stats(apps.get_model("archaeological_operations", "Operation")))
+ ]
+ if profile.archaeological_site:
+ stats.append((_("Archaeological sites"),
+ _count_stats(apps.get_model("archaeological_operations", "ArchaeologicalSite"))))
+ if profile.context_record:
+ stats.append((_("Context records"),
+ _count_stats(apps.get_model("archaeological_context_records", "ContextRecord"))))
+ if profile.find:
+ stats.append((_("Finds"),
+ _count_stats(apps.get_model("archaeological_finds", "Find"))))
+ if profile.warehouse:
+ stats.append((_("Warehouses"),
+ _count_stats(apps.get_model("archaeological_warehouse", "Warehouse"))))
+ stats.append((_("Containers"),
+ _count_stats(apps.get_model("archaeological_warehouse", "Container"))))
+ if profile.files:
+ stats.append((_("Archaeological files"), _count_stats(apps.get_model("archaeological_files", "File"))))
+ stats.append((_("Administrative acts"),
+ _count_stats(apps.get_model("archaeological_operations", "AdministrativeAct"))))
+ return stats
+
+
def index(request):
"""
Main page
"""
- dct = {"warnings": [], "extra_form_modals": wizards.EXTRA_FORM_MODALS}
+ profile = get_current_profile()
+ dct = {"warnings": [], "extra_form_modals": wizards.EXTRA_FORM_MODALS,
+ "welcome_title": profile.homepage_title}
if settings.PROJECT_SLUG == "default":
dct["warnings"].append(
_(
@@ -154,7 +191,6 @@ def index(request):
"local_settings (or ask your admin to do it)."
)
)
- profile = get_current_profile()
if profile.slug == "default":
dct["warnings"].append(
_(
@@ -162,13 +198,25 @@ def index(request):
"on the administration page (or ask your admin to do it)."
)
)
- image = get_random_item_image_link(request)
+ authenticated = request.user.is_authenticated
+ display_random_image = authenticated and profile.homepage_random_image_available
+ if display_random_image:
+ dct["display_random_image"] = True
+ dct["random_image"] = get_random_item_image_link(request)
+
if hasattr(profile, "homepage") and profile.homepage:
dct["homepage"] = markdown(profile.homepage)
+ # remove old hardcoded "{random_image}" from custom templates
if "{random_image}" in dct["homepage"]:
- dct["homepage"] = dct["homepage"].replace("{random_image}", image)
- else:
- dct["random_image"] = image
+ dct["homepage"] = dct["homepage"].replace("{random_image}", "")
+
+ display_statistics = profile.homepage_statistics_available and (
+ authenticated or profile.homepage_statistics_available_offline
+ )
+ if display_statistics:
+ dct["display_statistics"] = True
+ dct["statistics"] = _get_statistics(profile)
+
try:
return render(request, "index.html", dct)
except NoReverseMatch: