Repository: akvo/akvo-rsr

Issue:
Unnecessary unsaved project messages on EUTF projects



Discussion:

Resolving patch:
diff --git a/akvo/rsr/admin.py b/akvo/rsr/admin.py
--- a/akvo/rsr/admin.py
+++ b/akvo/rsr/admin.py
@@ -21,6 +21,7 @@
 from django.contrib.auth.models import Group
 from django.db import models, transaction
 from django.apps import apps
+from django.contrib.postgres.fields import JSONField
 from django.forms.utils import ErrorList
 from django.forms import TextInput
 from django.utils.decorators import method_decorator
@@ -28,6 +29,7 @@
 from django.views.decorators.csrf import csrf_protect
 from django.utils.encoding import force_text
 
+from prettyjson import PrettyJSONWidget
 from sorl.thumbnail.fields import ImageField
 from embed_video.admin import AdminVideoMixin
 import os.path
@@ -1579,3 +1581,12 @@ class UserProjectsAdmin(admin.ModelAdmin):
     model = UserProjects
 
 admin.site.register(UserProjects, UserProjectsAdmin)
+
+
+class OrganisationCodeList(admin.ModelAdmin):
+    list_display = (u'slug',)
+    formfield_overrides = {
+        JSONField: {'widget': PrettyJSONWidget}
+    }
+
+admin.site.register(apps.get_model('rsr', 'organisationcodelist'), OrganisationCodeList)
diff --git a/akvo/rsr/models/project.py b/akvo/rsr/models/project.py
--- a/akvo/rsr/models/project.py
+++ b/akvo/rsr/models/project.py
@@ -1387,14 +1387,9 @@ def copy_period(self, indicator, source_period, set_parent=True):
         )
         qs = IndicatorPeriod.objects.select_related('indicator', 'indicator__result')
         if set_parent:
-            period, _ = qs.update_or_create(
-                indicator=indicator, parent_period=source_period, defaults=data
-            )
+            qs.update_or_create(indicator=indicator, parent_period=source_period, defaults=data)
         else:
-            period = qs.create(indicator=indicator, **data)
-
-        fields = ['target_value', 'target_comment', 'actual_comment']
-        self._update_fields_if_not_child_updated(source_period, period, fields)
+            qs.create(indicator=indicator, **data)
 
     def update_period(self, indicator, parent_period):
         """Update a period based on the parent period attributes."""
@@ -1416,9 +1411,6 @@ def update_period(self, indicator, parent_period):
         child_period.period_end = parent_period.period_end
         child_period.save()
 
-        fields = ['target_value', 'target_comment', 'actual_comment']
-        self._update_fields_if_not_child_updated(parent_period, child_period, fields)
-
     def copy_dimension(self, indicator, source_dimension, set_parent=True):
         IndicatorDimension = apps.get_model('rsr', 'IndicatorDimension')
         data = dict(


Test patch:
diff --git a/akvo/rsr/tests/results_framework/test_results_framework.py b/akvo/rsr/tests/results_framework/test_results_framework.py
--- a/akvo/rsr/tests/results_framework/test_results_framework.py
+++ b/akvo/rsr/tests/results_framework/test_results_framework.py
@@ -213,7 +213,7 @@ def test_child_period_state_updates_after_change(self):
         # Given
         self.period.period_start = datetime.datetime.today() + datetime.timedelta(days=30)
         self.period.period_end = datetime.datetime.today() + datetime.timedelta(days=300)
-        # # these properties were not set already, and hence should be updated too
+        # # these properties shouldn't get imported
         self.period.target_comment = "Target comment"
         self.period.actual_comment = "Actual comment"
 
@@ -225,8 +225,8 @@ def test_child_period_state_updates_after_change(self):
         child_period = self.period.child_periods.first()
         self.assertEqual(child_period.period_start, parent_period.period_start)
         self.assertEqual(child_period.period_end, parent_period.period_end)
-        self.assertEqual(child_period.target_comment, parent_period.target_comment)
-        self.assertEqual(child_period.actual_comment, parent_period.actual_comment)
+        self.assertEqual(child_period.target_comment, '')
+        self.assertEqual(child_period.actual_comment, '')
 
     def test_child_period_state_not_overwritten_after_change(self):
         """Test that changes made to child period are not overwritten."""