diff --git a/photo21/static/lang-select.js b/photo21/static/lang-select.js index 0038534..662142c 100644 --- a/photo21/static/lang-select.js +++ b/photo21/static/lang-select.js @@ -3,6 +3,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later // On language selection, submit form -document.getElementsByName("language")[0].addEventListener("change", (e) => { - e.target.form.submit(); -}); +const langSelect = document.getElementsByName("language")[0]; +if (langSelect) { + langSelect.addEventListener("change", (e) => { + e.target.form.submit(); + }); +} diff --git a/photologue/forms.py b/photologue/forms.py index 1569961..7ac6841 100644 --- a/photologue/forms.py +++ b/photologue/forms.py @@ -113,6 +113,7 @@ class UploadForm(forms.Form): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() + self.helper.include_media = False self.helper.use_custom_control = False self.helper.layout = Layout( "file_field", diff --git a/photologue/migrations/0007_allow_duplicate_photo_titles.py b/photologue/migrations/0007_allow_duplicate_photo_titles.py new file mode 100644 index 0000000..b715249 --- /dev/null +++ b/photologue/migrations/0007_allow_duplicate_photo_titles.py @@ -0,0 +1,44 @@ +from pathlib import Path + +from django.db import migrations, models +from django.template.defaultfilters import slugify + + +def rename_photos(apps, schema_editor): + Photo = apps.get_model("photologue", "Photo") + taken_slugs = set(Photo.objects.values_list("slug", flat=True)) + + for photo in Photo.objects.order_by("pk"): + new_title = Path(photo.image.name).stem + base_slug = slugify(new_title) + + taken_slugs.discard(photo.slug) + + if base_slug in taken_slugs: + counter = 2 + while f"{base_slug}-{counter}" in taken_slugs: + counter += 1 + new_slug = f"{base_slug}-{counter}" + else: + new_slug = base_slug + + taken_slugs.add(new_slug) + photo.title = new_title + photo.slug = new_slug + photo.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('photologue', '0006_allow_duplicate_gallery_titles'), + ] + + operations = [ + migrations.AlterField( + model_name='photo', + name='title', + field=models.CharField(max_length=250, verbose_name='title'), + ), + migrations.RunPython(rename_photos, migrations.RunPython.noop), + ] diff --git a/photologue/templates/photologue/upload.html b/photologue/templates/photologue/upload.html index f44962e..7d4e0d0 100644 --- a/photologue/templates/photologue/upload.html +++ b/photologue/templates/photologue/upload.html @@ -8,10 +8,9 @@ SPDX-License-Identifier: GPL-3.0-or-later {% block title %}{% trans "Upload" %}{% endblock %} {% block extrajs %} - - {# jQuery first #} -{{ form.media }} {# Select2 JS/CSS comes after jQuery #} - {# your custom JS last #} + +{{ form.media }} + {% endblock %} {% block content %}