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.product}} + {{version.reference_product}} +
+