StichtingOpenGeo / openebs2

Tool to post real time changes and announcements for public transport lines with Dutch KV15 and KV17 protocols
2 stars 1 forks source link

ShowCancelledTrip #228

Open skinkie opened 1 month ago

skinkie commented 1 month ago
diff --git a/openebs/form_kv17.py b/openebs/form_kv17.py
index e43cadb..faa299b 100644
--- a/openebs/form_kv17.py
+++ b/openebs/form_kv17.py
@@ -369,7 +369,7 @@ class Kv17ChangeForm(forms.ModelForm):
             self.instance.endtime = endtime
             self.instance.is_cancel = True
             self.instance.monitoring_error = None
-            self.instance.showcancelledtrip = True if self.data['showcancelledtrip'] == 'on' else False
+            self.instance.showcancelledtrip = True if self.data.get('showcancelledtrip', '') == 'on' else False

             # Unfortunately, we can't place this any earlier, because we don't have the dataownercode there
             if self.instance.line.dataownercode == self.instance.dataownercode:
@@ -428,7 +428,7 @@ class Kv17ChangeForm(forms.ModelForm):
                 # Shouldn't be necessary, but just in case:
                 self.instance.begintime = None
                 self.instance.endtime = None
-                self.instance.showcancelledtrip = True if self.data['showcancelledtrip'] == 'on' else False
+                self.instance.showcancelledtrip = True if self.data.get('showcancelledtrip', '') == 'on' else False

                 # Unfortunately, we can't place this any earlier, because we don't have the dataownercode there
                 if self.instance.journey.dataownercode == self.instance.dataownercode:
@@ -466,7 +466,7 @@ class Kv17ChangeForm(forms.ModelForm):
         self.instance.endtime = endtime
         self.instance.is_cancel = True
         self.instance.monitoring_error = None
-        self.instance.showcancelledtrip = True if self.data['showcancelledtrip'] == 'on' else False
+        self.instance.showcancelledtrip = True if self.data.get('showcancelledtrip', '') == 'on' else False

         # Unfortunately, we can't place this any earlier, because we don't have the dataownercode there
         if self.instance.dataownercode == self.user.userprofile.company:
@@ -928,7 +928,7 @@ class Kv17ShortenForm(forms.ModelForm):
             self.instance.begintime = None
             self.instance.endtime = None
             self.instance.is_cancel = False
-            self.instance.showcancelledtrip = True if self.data['showcancelledtrip'] == 'on' else False
+            self.instance.showcancelledtrip = True if self.data.get('showcancelledtrip', '') == 'on' else False
             self.instance.monitoring_error = None
             if len(self.instance.recovered_changes) > 0:
                 self.instance.monitoring_error = self.instance.recovered_changes[0].monitoring_error