Repository: liqd/a4-meinberlin

Issue:
bplan template dates saved but not shown in Dashboard
URL: https://mein.berlin.de/dashboard/projects/erweiterung-mauerpark-bebauungsplan-3-64-im-bezirk/bplan/
user: initiator
expected behaviour: date and time that I have entered are still shown after saving form
behaviour: dates are no longer shown after saving, no error message, I can still publish the project and date is shown correctly on project tile
device & browser: Desktop, mac, chrome Version 76.0.3809.132 (Offizieller Build) (64-Bit)
Importance: relevant bug, fix before next release


Discussion:
after release date is still not shown, e.g. here: https://mein.berlin.de/dashboard/projects/bebauungsplan-11-100-alt-friedrichsfelde-1-bis-3/bplan/

even though I successfully tested it on dev: https://meinberlin-dev.liqd.net/dashboard/projects/caros-b-plan/bplan/

Resolving patch:
diff --git a/meinberlin/apps/bplan/serializers.py b/meinberlin/apps/bplan/serializers.py
--- a/meinberlin/apps/bplan/serializers.py
+++ b/meinberlin/apps/bplan/serializers.py
@@ -66,8 +66,8 @@ def create(self, validated_data):
         orga = orga_model.objects.get(pk=orga_pk)
         validated_data['organisation'] = orga
 
-        start_date = validated_data.pop('start_date')
-        end_date = validated_data.pop('end_date')
+        start_date = validated_data['start_date']
+        end_date = validated_data['end_date']
 
         image_url = validated_data.pop('image_url', None)
         if image_url:
@@ -97,8 +97,8 @@ def _create_module_and_phase(self, bplan, start_date, end_date):
         )
 
     def update(self, instance, validated_data):
-        start_date = validated_data.pop('start_date', None)
-        end_date = validated_data.pop('end_date', None)
+        start_date = validated_data.get('start_date', None)
+        end_date = validated_data.get('end_date', None)
         if start_date or end_date:
             self._update_phase(instance, start_date, end_date)
             if end_date and end_date > timezone.localtime(timezone.now()):


Test patch:
diff --git a/tests/bplan/test_bplan_api.py b/tests/bplan/test_bplan_api.py
--- a/tests/bplan/test_bplan_api.py
+++ b/tests/bplan/test_bplan_api.py
@@ -52,6 +52,8 @@ def test_initiator_add_bplan(apiclient, organisation):
     assert bplan.is_draft is False
     assert bplan.information == ''
     assert bplan.result == ''
+    assert bplan.start_date == parse("2013-01-01 17:00:00 UTC")
+    assert bplan.end_date == parse("2021-01-01 17:00:00 UTC")
     module = module_models.Module.objects.get(project=bplan)
     assert module is not None
     phase = phase_models.Phase.objects.get(module=module)
@@ -88,6 +90,14 @@ def test_initiator_update_bplan(apiclient, bplan, phase):
     bplan = bplan_models.Bplan.objects.first()
     assert bplan.is_draft is True
     assert bplan.tile_image_copyright == data.get('image_copyright')
+    assert bplan.start_date == parse("2013-01-01 17:00:00 UTC")
+    assert bplan.end_date == parse("2021-01-01 17:00:00 UTC")
+    module = module_models.Module.objects.get(project=bplan)
+    assert module is not None
+    phase = phase_models.Phase.objects.get(module=module)
+    assert phase is not None
+    assert phase.start_date == parse("2013-01-01 17:00:00 UTC")
+    assert phase.end_date == parse("2021-01-01 17:00:00 UTC")
 
 
 @pytest.mark.django_db
@@ -167,6 +177,9 @@ def test_initiator_update_bplan_phase(apiclient, bplan_factory, phase):
     apiclient.force_authenticate(user=user)
     response = apiclient.patch(url, data, format='json')
     assert response.status_code == status.HTTP_200_OK
+    bplan = bplan_models.Bplan.objects.first()
+    assert bplan.start_date == parse("2013-01-01 17:00:00 UTC")
+    assert bplan.end_date == parse("2021-01-01 17:00:00 UTC")
     phase = phase_models.Phase.objects.get(module=phase.module)
     assert phase.start_date == parse("2013-01-01 17:00:00 UTC")
     assert phase.end_date == parse("2021-01-01 17:00:00 UTC")