From 77fa91ed9598486cea76bc37165f93a635834f4d Mon Sep 17 00:00:00 2001 From: Jean-Etienne Castagnede Date: Wed, 2 Oct 2024 10:35:32 +0200 Subject: [PATCH 1/3] Use new crispy form 2.0 (#264) * use new crispy forms * fix typo * use defined form action class * Update CHANGES.md * fix login page * delete version in docker compose --- CHANGES.md | 9 ++ docker-compose.yml | 1 - docs/getting_started.rst | 1 + mapentity/context_processors.py | 4 +- mapentity/forms.py | 6 +- mapentity/settings.py | 2 +- mapentity/templates/mapentity/base.html | 2 +- .../bootstrap4/layout/formactions.html | 2 +- mapentity/templates/registration/login.html | 103 +++++++++++++----- setup.py | 3 +- test_app/forms.py | 10 +- test_app/views.py | 14 ++- test_project/settings.py | 1 + 13 files changed, 121 insertions(+), 37 deletions(-) rename mapentity/templates/mapentity/{crispy_forms => crispy_bootstrap4}/bootstrap4/layout/formactions.html (64%) diff --git a/CHANGES.md b/CHANGES.md index e0f9034b7..5ceff47b1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,15 @@ CHANGELOG 8.9.2+dev (XXXX-XX-XX) ----------------------- +**Breaking changes** + +* Compatibility with new django-crispy-forms (2.0.0+) + * New explicit dependency to ``crispy-bootstrap4``. + * You should adapt configuration by adding `crispy_bootstrap4` in your INSTALLED_APPS and check your templates inheritance. + +**Improvements** + +- Due to new crispy forms, there is new login form 8.9.2 (2024-07-15) diff --git a/docker-compose.yml b/docker-compose.yml index e5a2388c6..e8a7fa73d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: "3" services: convertit: image: makinacorpus/convertit:latest diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 38e9f56a4..4443d67c9 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -35,6 +35,7 @@ Add these entries to your ``INSTALLED_APPS``:: 'compressor', 'easy_thumbnails', 'crispy_forms', + 'crispy_bootstrap4', 'rest_framework', 'embed_video', 'modeltranslation' diff --git a/mapentity/context_processors.py b/mapentity/context_processors.py index 6710922b1..32a99878e 100644 --- a/mapentity/context_processors.py +++ b/mapentity/context_processors.py @@ -1,5 +1,5 @@ from django.conf import settings as settings_ # import the settings file - +from mapentity import __version__ from .registry import registry from .settings import app_settings @@ -12,7 +12,7 @@ def settings(request): return dict( TITLE=app_settings['TITLE'], DEBUG=settings_.DEBUG, - VERSION=getattr(settings_, 'VERSION', 'unknown'), + VERSION=getattr(settings_, 'VERSION', __version__), JS_SETTINGS_VIEW=app_settings['JS_SETTINGS_VIEW'], TRANSLATED_LANGUAGES=app_settings['TRANSLATED_LANGUAGES'], MODELTRANSLATION_LANGUAGES=settings_.MODELTRANSLATION_LANGUAGES, diff --git a/mapentity/forms.py b/mapentity/forms.py index d5ded3718..4f2c096e6 100644 --- a/mapentity/forms.py +++ b/mapentity/forms.py @@ -95,11 +95,13 @@ def __init__(self, div_id, label): class MapEntityForm(TranslatedModelForm): fieldslayout = None - geomfields = [] + geomfields = None leftpanel_scrollable = True hidden_fields = [] def __init__(self, *args, **kwargs): + if self.geomfields is None: + self.geomfields = ['geom'] self.user = kwargs.pop('user', None) self.can_delete = kwargs.pop('can_delete', True) @@ -221,7 +223,7 @@ def _init_layout(self): formactions = FormActions( *actions, css_class="form-actions", - template='mapentity/crispy_forms/bootstrap4/layout/formactions.html' + template='mapentity/crispy_bootstrap4/bootstrap4/layout/formactions.html' ) # Main form layout diff --git a/mapentity/settings.py b/mapentity/settings.py index 964b87c75..b816a2e1e 100644 --- a/mapentity/settings.py +++ b/mapentity/settings.py @@ -15,7 +15,7 @@ } app_settings = dict({ - 'TITLE': "", + 'TITLE': "Mapentity", 'HISTORY_ITEMS_MAX': 5, 'CONVERSION_SERVER': 'http://convertit/', 'CAPTURE_SERVER': 'http://screamshotter/', diff --git a/mapentity/templates/mapentity/base.html b/mapentity/templates/mapentity/base.html index 9a9dfcc2d..8087174eb 100644 --- a/mapentity/templates/mapentity/base.html +++ b/mapentity/templates/mapentity/base.html @@ -72,7 +72,7 @@ data-app-verbosename="{{ app_verbose_name }}" data-modelname="{{ modelname }}" data-objectsname="{{ objectsname }}" - data-pk="{{ object.pk }}"> + data-pk="{{ object.pk }}" class="{% block body_classes %}{% endblock %}"> {% block content %} {% block navbar %} diff --git a/mapentity/templates/mapentity/crispy_forms/bootstrap4/layout/formactions.html b/mapentity/templates/mapentity/crispy_bootstrap4/bootstrap4/layout/formactions.html similarity index 64% rename from mapentity/templates/mapentity/crispy_forms/bootstrap4/layout/formactions.html rename to mapentity/templates/mapentity/crispy_bootstrap4/bootstrap4/layout/formactions.html index a40468515..a57de2544 100644 --- a/mapentity/templates/mapentity/crispy_forms/bootstrap4/layout/formactions.html +++ b/mapentity/templates/mapentity/crispy_bootstrap4/bootstrap4/layout/formactions.html @@ -1,3 +1,3 @@ - + {{ fields_output|safe }} diff --git a/mapentity/templates/registration/login.html b/mapentity/templates/registration/login.html index c8f48d8ea..0d9b97ee4 100644 --- a/mapentity/templates/registration/login.html +++ b/mapentity/templates/registration/login.html @@ -1,34 +1,87 @@ {% extends "mapentity/base_site.html" %} -{% load i18n crispy_forms_tags mapentity_tags %} + +{% load crispy_forms_filters %} +{% load i18n mapentity_tags %} + +{% block extrahead %} + +{% endblock %} + +{% block body_classes %}bg-light{% endblock %} {% block content %} -
- {% if messages %} - {% for message in messages %} - - {% endfor %} - {% endif %} -
-
- - {% endblock content %} {% block extrabody %} diff --git a/setup.py b/setup.py index 137b984bc..e6fef4f07 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,8 @@ 'tzdata', 'django-appypod', 'django-compressor', - 'django-crispy-forms<2.0', + 'django-crispy-forms>=2.0', + 'crispy-bootstrap4', 'django-embed-video', 'django-filter', 'django-leaflet>=0.19,<0.20', # leaflet 0.7.x diff --git a/test_app/forms.py b/test_app/forms.py index fa7b97d56..3d2290200 100644 --- a/test_app/forms.py +++ b/test_app/forms.py @@ -1,5 +1,5 @@ from mapentity.forms import MapEntityForm -from test_app.models import Road, DummyModel +from test_app.models import Road, DummyModel, MushroomSpot class DummyModelForm(MapEntityForm): @@ -12,3 +12,11 @@ class RoadForm(MapEntityForm): class Meta: model = Road fields = ("name", "geom") + + +class MushroomSpotForm(MapEntityForm): + geomfields = [] + + class Meta: + model = MushroomSpot + fields = "__all__" diff --git a/test_app/views.py b/test_app/views.py index 791b4b8b4..8a7d5c563 100644 --- a/test_app/views.py +++ b/test_app/views.py @@ -3,8 +3,8 @@ from mapentity import views as mapentity_views from .filters import DummyModelFilter -from .forms import DummyModelForm, RoadForm -from .models import DummyModel, Road +from .forms import DummyModelForm, RoadForm, MushroomSpotForm +from .models import DummyModel, Road, MushroomSpot from .serializers import DummySerializer, RoadSerializer, DummyGeojsonSerializer @@ -72,3 +72,13 @@ class RoadViewSet(mapentity_views.MapEntityViewSet): queryset = Road.objects.all() serializer_class = RoadSerializer permission_classes = [DjangoModelPermissionsOrAnonReadOnly] + + +class MushroomSpotCreate(mapentity_views.MapEntityCreate): + model = MushroomSpot + form_class = MushroomSpotForm + + +class MushroomSpotUpdate(mapentity_views.MapEntityUpdate): + model = MushroomSpot + form_class = MushroomSpotForm diff --git a/test_project/settings.py b/test_project/settings.py index 7ac6504b1..0c3a626af 100644 --- a/test_project/settings.py +++ b/test_project/settings.py @@ -46,6 +46,7 @@ 'easy_thumbnails', 'django_filters', 'crispy_forms', + 'crispy_bootstrap4', 'rest_framework', 'embed_video', 'tinymce', From 9b32702593d5975d691af5010f3fbb1e33243b9b Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 2 Oct 2024 10:43:53 +0200 Subject: [PATCH 2/3] prepare release --- CHANGES.md | 2 +- mapentity/VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5ceff47b1..e6f106da2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ CHANGELOG ========= -8.9.2+dev (XXXX-XX-XX) +8.10.0 (2024-10-02) ----------------------- **Breaking changes** diff --git a/mapentity/VERSION b/mapentity/VERSION index bc218887b..7f6758ef9 100644 --- a/mapentity/VERSION +++ b/mapentity/VERSION @@ -1 +1 @@ -8.9.2+dev +8.10.0 From 99bb35edbcb089a12128dfcda17d66922cb0186a Mon Sep 17 00:00:00 2001 From: Jean-Etienne Castagnede Date: Wed, 2 Oct 2024 10:45:47 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f749f7be1..a23b2f002 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,9 +4,9 @@ CHANGELOG 8.9.2+dev (XXXX-XX-XX) ----------------------- -**Bug fixes** +**Improvements** -- Use HTML tag for create/update button +- Use HTML `button` tag for create/update forms 8.9.2 (2024-07-15)