diff --git a/src/sdg/producten/models/product.py b/src/sdg/producten/models/product.py index 3cfe40b4c..39d4f78d7 100644 --- a/src/sdg/producten/models/product.py +++ b/src/sdg/producten/models/product.py @@ -323,7 +323,7 @@ def get_latest_versions( ): """:returns: The latest N versions for this product.""" step_slice = 1 if reverse_order else 1 - queryset = self.versies.all().order_by("-versie") + queryset = self.versies.all().order_by("-gewijzigd_op") if active: queryset = queryset.filter(publicatie_datum__lte=datetime.date.today()) @@ -334,7 +334,9 @@ def get_latest_versions( def get_all_versions(self, active=False, exclude_concept=False): """:returns: The versions for this product.""" - queryset = self.versies.all().order_by("-versie").select_related("gemaakt_door") + queryset = ( + self.versies.all().order_by("-gewijzigd_op").select_related("gemaakt_door") + ) if active: queryset = queryset.filter(publicatie_datum__lte=datetime.date.today()) @@ -451,7 +453,7 @@ class ProductVersie(ProductFieldMixin, models.Model): class Meta: verbose_name = _("product versie") verbose_name_plural = _("product versies") - ordering = ("-versie",) + ordering = ("-gewijzigd_op",) unique_together = (("versie", "product"),) def __str__(self): diff --git a/src/sdg/producten/tests/test_product.py b/src/sdg/producten/tests/test_product.py index e57032514..9b539db2c 100644 --- a/src/sdg/producten/tests/test_product.py +++ b/src/sdg/producten/tests/test_product.py @@ -1181,8 +1181,10 @@ def test_history_displays_reference_version(self): self.assertEqual(response.status_code, 200) revisions = response.pyquery(".revision-list") + latest_active_version = self.product_version.gemaakt_door + self.assertEqual(len(revisions), 2) - self.assertIn(str(self.product), revisions[0].text_content()) + self.assertIn(str(latest_active_version), revisions[1].text_content()) self.assertIn(str(self.reference_product), revisions[1].text_content()) @freeze_time(NOW_DATE) diff --git a/src/sdg/producten/views/product.py b/src/sdg/producten/views/product.py index d735fd689..fed02459f 100644 --- a/src/sdg/producten/views/product.py +++ b/src/sdg/producten/views/product.py @@ -266,11 +266,16 @@ def _save_version_form( new_version.product = self.product new_version.gemaakt_door = self.request.user new_version.versie = self.object.versie + 1 if created else self.object.versie + changes_specific_fields = [ + field + for field in product_form.changed_data + if field in settings.SDG_LOCALIZED_FORM_FIELDS + ] new_version.bewerkte_velden = list( chain.from_iterable( [ localized_formset.changed_data_localized, - parse_changed_data(product_form.changed_data, form=product_form), + parse_changed_data(changes_specific_fields, form=product_form), ] ) ) diff --git a/src/sdg/templates/producten/_include/productversie.html b/src/sdg/templates/producten/_include/productversie.html index 3fbae0673..49584f097 100644 --- a/src/sdg/templates/producten/_include/productversie.html +++ b/src/sdg/templates/producten/_include/productversie.html @@ -2,32 +2,46 @@ - {{ version.gemaakt_door|default:"Systeem" }} + + + {{ version.gemaakt_door|default:"Systeem" }} + -
  • - {% with last_modified=version.gewijzigd_op %} + + +

    + {{version.product}} + {{version.reference_product}} +

    +
  • - {{ last_modified }}. {{ version }} gewijzigd.   + {{ version.gewijzigd_op }} + + {% trans "versie" %} {{version.versie}} {% if not version.publicatie_datum %}(concept){% endif %} + {% trans "gewijzigd" %} + {% if version.publicatie_datum %} + + Gepubliceerd op + {% blocktrans with publication_date=version.publicatie_datum %} + {{ publication_date }}. + {% endblocktrans %} + {% endif %} - {% endwith %} - - {% if version.publicatie_datum %} - {% blocktrans with publication_date=version.publicatie_datum %} - Gepubliceerd op   {{ publication_date }}. - {% endblocktrans %} - {% endif %} -
  • - {% if version.interne_opmerkingen %} + + + + + {% if version.interne_opmerkingen %}
  • {{ version.interne_opmerkingen }}
  • - {% endif %} - {% if version.bewerkte_velden %} + {% endif %} + {% if version.bewerkte_velden %}
  • {% include 'producten/_include/productversie_bewerkte_velden.html' %}
  • - {% endif %} + {% endif %}