2.1 --- a/imip_manager.py Sun Feb 08 22:33:11 2015 +0100
2.2 +++ b/imip_manager.py Sun Feb 08 22:52:37 2015 +0100
2.3 @@ -469,12 +469,27 @@
2.4
2.5 def handle_request(self, uid, obj):
2.6
2.7 - "Handle actions involving the given 'uid' and 'obj' object."
2.8 + """
2.9 + Handle actions involving the given 'uid' and 'obj' object, returning an
2.10 + error if one occurred, or None if the request was successfully handled.
2.11 + """
2.12
2.13 # Handle a submitted form.
2.14
2.15 args = self.env.get_args()
2.16 - handled = True
2.17 +
2.18 + # Get the possible actions.
2.19 +
2.20 + reply = args.has_key("reply")
2.21 + discard = args.has_key("discard")
2.22 + invite = args.has_key("invite")
2.23 + cancel = args.has_key("cancel")
2.24 + save = args.has_key("save")
2.25 +
2.26 + have_action = reply or discard or invite or cancel or save
2.27 +
2.28 + if not have_action:
2.29 + return ["action"]
2.30
2.31 # Update the object.
2.32
2.33 @@ -502,7 +517,7 @@
2.34 dtstart, attr = t
2.35 update = self.set_datetime_in_object(dtstart, attr["TZID"], "DTSTART", obj) or update
2.36 else:
2.37 - return False
2.38 + return ["dtstart"]
2.39
2.40 # Handle specified end datetimes.
2.41
2.42 @@ -517,27 +532,23 @@
2.43 dtend += timedelta(1)
2.44 update = self.set_datetime_in_object(dtend, attr["TZID"], "DTEND", obj) or update
2.45 else:
2.46 - return False
2.47 + return ["dtend"]
2.48
2.49 - # Otherwise, treat the end date as the start date. Datetimes cannot
2.50 - # be duplicated in such a way.
2.51 + # Otherwise, treat the end date as the start date. Datetimes are
2.52 + # handled by making the event occupy the rest of the day.
2.53
2.54 else:
2.55 + dtend = dtstart + timedelta(1)
2.56 if isinstance(dtstart, datetime):
2.57 - return False
2.58 - dtend = dtstart + timedelta(1)
2.59 + dtend = get_start_of_day(dtend, attr["TZID"])
2.60 update = self.set_datetime_in_object(dtend, attr["TZID"], "DTEND", obj) or update
2.61
2.62 if dtstart >= dtend:
2.63 - return False
2.64 + return ["dtstart", "dtend"]
2.65
2.66 # Process any action.
2.67
2.68 - reply = args.has_key("reply")
2.69 - discard = args.has_key("discard")
2.70 - invite = args.has_key("invite")
2.71 - cancel = args.has_key("cancel")
2.72 - save = args.has_key("save")
2.73 + handled = True
2.74
2.75 if reply or invite or cancel:
2.76
2.77 @@ -572,7 +583,7 @@
2.78 if handled:
2.79 self.redirect(self.env.get_path())
2.80
2.81 - return handled
2.82 + return None
2.83
2.84 def handle_date_controls(self, name):
2.85
2.86 @@ -679,11 +690,11 @@
2.87 ("DELEGATED", "Delegated"),
2.88 ]
2.89
2.90 - def show_object_on_page(self, uid, obj):
2.91 + def show_object_on_page(self, uid, obj, error=None):
2.92
2.93 """
2.94 Show the calendar object with the given 'uid' and representation 'obj'
2.95 - on the current page.
2.96 + on the current page. If 'error' is given, show a suitable message.
2.97 """
2.98
2.99 page = self.page
2.100 @@ -752,8 +763,9 @@
2.101 # Handle datetimes specially.
2.102
2.103 if name in ["DTSTART", "DTEND"]:
2.104 + field = name.lower()
2.105
2.106 - page.th(label, class_="objectheading %s" % name.lower())
2.107 + page.th(label, class_="objectheading %s%s" % (field, error and field in error and " error" or ""))
2.108
2.109 # Obtain the datetime.
2.110
2.111 @@ -771,14 +783,14 @@
2.112 value = format_datetime(dt)
2.113
2.114 if is_organiser:
2.115 - page.td(class_="objectvalue %s" % name.lower())
2.116 + page.td(class_="objectvalue %s" % field)
2.117 if name == "DTEND":
2.118 page.div(class_="disabled")
2.119 page.label("Specify end date", for_="dtend-enable", class_="enable")
2.120 page.div.close()
2.121
2.122 page.div(class_="enabled")
2.123 - self._show_date_controls(name.lower(), value, attr, tzid)
2.124 + self._show_date_controls(field, value, attr, tzid)
2.125 if name == "DTEND":
2.126 page.label("End on same day", for_="dtend-disable", class_="disable")
2.127 page.div.close()
2.128 @@ -960,13 +972,13 @@
2.129 if not obj:
2.130 return False
2.131
2.132 - handled = self.handle_request(uid, obj)
2.133 + error = self.handle_request(uid, obj)
2.134
2.135 - if handled:
2.136 + if not error:
2.137 return True
2.138
2.139 self.new_page(title="Event")
2.140 - self.show_object_on_page(uid, obj)
2.141 + self.show_object_on_page(uid, obj, error)
2.142
2.143 return True
2.144