summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-26 14:31:54 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-26 17:48:33 +0200
commita44bb4131dd191b4ef5be4e1403fd18bb4987b55 (patch)
tree94aed38b0e4b888cbd299e38a633444d219220ea /ishtar_common
parentf18ffffb54004411ed8cb981aef097d9f1051ead (diff)
downloadIshtar-a44bb4131dd191b4ef5be4e1403fd18bb4987b55.tar.bz2
Ishtar-a44bb4131dd191b4ef5be4e1403fd18bb4987b55.zip
🩹 Welcome page: simplify and init Welcome fields management
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/context_processors.py1
-rw-r--r--ishtar_common/migrations/0251_data_default_welcome.py39
-rw-r--r--ishtar_common/models.py4
-rw-r--r--ishtar_common/templates/index.html4
-rw-r--r--ishtar_common/templates/welcome.html10
-rw-r--r--ishtar_common/utils_migrations.py26
-rw-r--r--ishtar_common/views.py15
7 files changed, 81 insertions, 18 deletions
diff --git a/ishtar_common/context_processors.py b/ishtar_common/context_processors.py
index 4f507b65f..74e38efc4 100644
--- a/ishtar_common/context_processors.py
+++ b/ishtar_common/context_processors.py
@@ -85,7 +85,6 @@ def get_base_context(request):
"URL_PATH": settings.URL_PATH,
"BASE_URL": "",
"ISHTAR_MAP_MAX_ITEMS": settings.ISHTAR_MAP_MAX_ITEMS,
- "ISHTAR_DOCUMENT_VERSION": settings.ISHTAR_DOCUMENT_VERSION
}
if "HTTP_HOST" in request.META:
dct["BASE_URL"] = "{}://{}".format(request.scheme, request.META["HTTP_HOST"])
diff --git a/ishtar_common/migrations/0251_data_default_welcome.py b/ishtar_common/migrations/0251_data_default_welcome.py
new file mode 100644
index 000000000..df1f10a5e
--- /dev/null
+++ b/ishtar_common/migrations/0251_data_default_welcome.py
@@ -0,0 +1,39 @@
+# Generated by Django 2.2.24 on 2024-09-26 11:53
+
+from django.conf import settings
+from django.db import migrations
+from django.template import Context, Template
+from django.utils import translation
+
+from ishtar_common.utils_migrations import HOMEPAGE_DEFAULT, HOMEPAGE_TITLE
+
+
+def default_welcome(apps, __):
+ IshtarSiteProfile = apps.get_model("ishtar_common", "IshtarSiteProfile")
+ old_language = translation.get_language()
+ translation.activate(settings.LANGUAGE_CODE)
+ homepage = Template(HOMEPAGE_DEFAULT).render(Context({}, use_l10n=True))
+ title = str(HOMEPAGE_TITLE)
+ translation.activate(old_language)
+ for profile in IshtarSiteProfile.objects.all():
+ changed = False
+ if not profile.homepage:
+ changed = True
+ profile.homepage = homepage
+ if not profile.homepage_title:
+ changed = True
+ profile.homepage_title = title
+ if changed:
+ profile.save()
+
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0250_profile_homepage'),
+ ]
+
+ operations = [
+ migrations.RunPython(default_welcome)
+ ]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index f45ebe069..f7512b606 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -36,7 +36,6 @@ import os
import re
import string
import tempfile
-import time
from io import BytesIO
# nosec: only script inside the script directory can be executed
# script directory is not web available
@@ -1174,8 +1173,7 @@ class IshtarSiteProfile(models.Model, Cached):
default="",
help_text=_(
"Homepage of Ishtar - if not defined a default homepage "
- "will appear. Use the markdown syntax. {random_image} "
- "can be used to display a random image."
+ "will appear. Use HTML or markdown syntax."
),
)
homepage_title = models.CharField(_("Homepage - Title"), max_length=100, default="", blank=True)
diff --git a/ishtar_common/templates/index.html b/ishtar_common/templates/index.html
index d1000396a..69bc52617 100644
--- a/ishtar_common/templates/index.html
+++ b/ishtar_common/templates/index.html
@@ -1,7 +1,7 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}<div id="welcome" class="container">
- <h2>{% if welcome_title %}{{welcome_title}}{% else %}{% trans "Welcome in Ishtar, open source software for management and inventory of archaeological data" %}{% endif %}</h2>
+ <h2>{{welcome_title}}</h2>
<div class="row">
{% if display_random_image %}
{{random_image}}
@@ -9,7 +9,7 @@
<div class="col col-lg-9">
<div class="card">
<div class="card-body">
- {% if homepage %}{{homepage|safe}}{% else %}{% include "welcome.html" %}{% endif %}
+ {{homepage|safe}}
</div>
</div>
</div>
diff --git a/ishtar_common/templates/welcome.html b/ishtar_common/templates/welcome.html
deleted file mode 100644
index c5d21cecc..000000000
--- a/ishtar_common/templates/welcome.html
+++ /dev/null
@@ -1,10 +0,0 @@
-{% load i18n %}
-
-<p>{% trans "Some useful links:" %}</p>
-<ul>
- <li><a href='https://ishtar-archeo.net' target="_blank">{% trans "Presentation site and blog" %}</a>{% trans ":"%} {% trans "stay tuned with Ishtar news!" %}</li>
- <li><a href="https://ishtar.readthedocs.io/fr/{{ISHTAR_DOCUMENT_VERSION}}/" target="_blank">{% trans "Documentation" %}</a>{% trans ":"%} {% trans "inline documentation." %}</li>
- <li><a href="{% url 'admin:index' %}" target="_blank">{% trans "Admin interface" %}</a>{% trans ":"%} {% trans "for admin only." %}</li>
- <li><a href="https://discourse.ishtar-archeo.net/" target="_blank">{% trans "Forum" %}</a>{% trans ":"%} {% trans "need help? find a new bug? a fantastic feature to propose? Here is the place to go." %}</li>
- <li><a href="https://gitlab.com/iggdrasil/ishtar" target="_blank">{% trans "Source code" %}</a> &ndash; <a href="https://tickets.iggdrasil.net/projects/ishtar" target="_blank">{% trans "tickets" %}</a>{% trans ":"%} {% trans "where the magic happens." %}</li>
-</ul>
diff --git a/ishtar_common/utils_migrations.py b/ishtar_common/utils_migrations.py
index 72697f48b..3400e1738 100644
--- a/ishtar_common/utils_migrations.py
+++ b/ishtar_common/utils_migrations.py
@@ -8,6 +8,32 @@ import uuid
from django.core.files import File
from django.core.management import call_command
from django.db import connection
+from django.utils.translation import ugettext_lazy
+
+HOMEPAGE_TITLE = ugettext_lazy("Welcome in Ishtar, open source software for management and inventory of archaeological data")
+
+HOMEPAGE_DEFAULT = """{% load i18n %}
+<p>{% trans "Some useful links:" %}</p>
+<ul>
+ <li><a href="https://ishtar.readthedocs.io/fr/ISHTAR_DOCUMENT_VERSION/" target="_blank">
+ {% trans "Documentation" %}</a>{% trans ":"%}
+ {% trans "inline documentation." %}
+ </li>
+ <li><a href="https://discourse.ishtar-archeo.net/" target="_blank">
+ {% trans "Forum" %}</a>{% trans ":"%}
+ {% trans "need help? find a new bug? a fantastic feature to propose? Here is the place to go." %}
+ </li>
+ <li><a href='https://ishtar-archeo.net' target="_blank">
+ {% trans "Presentation site and blog" %}</a>{% trans ":"%}
+ {% trans "stay tuned with Ishtar news!" %}
+ </li>
+ <li><a href="https://gitlab.com/iggdrasil/ishtar" target="_blank">
+ {% trans "Source code" %}</a> &ndash;
+ <a href="https://tickets.iggdrasil.net/projects/ishtar" target="_blank">{% trans "tickets" %}</a>{% trans ":"%}
+ {% trans "where the magic happens." %}
+ </li>
+</ul>
+"""
def migrations_load_data(module_name, migration_filename):
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 2772bd44f..5b675eb52 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -53,7 +53,9 @@ from django.http import (
JsonResponse,
)
from django.shortcuts import redirect, render, get_object_or_404
+from django.template import Context, Template
from django.urls import reverse, NoReverseMatch
+from django.utils import translation
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext, ugettext_lazy as _
from django.views.generic import ListView, TemplateView, View
@@ -73,6 +75,7 @@ from ishtar_common.data_importer import ImporterError
from ishtar_common.forms import FinalForm, FinalDeleteForm, reverse_lazy
from ishtar_common.models import get_current_profile
from ishtar_common.templatetags.link_to_window import simple_link_to_window
+from ishtar_common.utils_migrations import HOMEPAGE_DEFAULT, HOMEPAGE_TITLE
from ishtar_common.utils import (
clean_session_cache,
CSV_OPTIONS,
@@ -182,8 +185,9 @@ def index(request):
Main page
"""
profile = get_current_profile()
+ welcome_title = profile.homepage_title or str(HOMEPAGE_TITLE)
dct = {"warnings": [], "extra_form_modals": wizards.EXTRA_FORM_MODALS,
- "welcome_title": profile.homepage_title}
+ "welcome_title": welcome_title}
if settings.PROJECT_SLUG == "default":
dct["warnings"].append(
_(
@@ -204,11 +208,18 @@ def index(request):
dct["display_random_image"] = True
dct["random_image"] = get_random_item_image_link(request)
- if hasattr(profile, "homepage") and profile.homepage:
+ if 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}", "")
+ else:
+ old_language = translation.get_language()
+ translation.activate(settings.LANGUAGE_CODE)
+ dct["homepage"] = Template(HOMEPAGE_DEFAULT).render(Context({}, use_l10n=True))
+ translation.activate(old_language)
+
+ dct["homepage"] = dct["homepage"].replace("ISHTAR_DOCUMENT_VERSION", settings.ISHTAR_DOCUMENT_VERSION)
display_statistics = profile.homepage_statistics_available and (
authenticated or profile.homepage_statistics_available_offline