imip-agent

Change of imip_manager.py

299:b96e527e13d4
imip_manager.py
     1.1 --- a/imip_manager.py	Sun Feb 08 22:33:11 2015 +0100
     1.2 +++ b/imip_manager.py	Sun Feb 08 22:52:37 2015 +0100
     1.3 @@ -469,12 +469,27 @@
     1.4  
     1.5      def handle_request(self, uid, obj):
     1.6  
     1.7 -        "Handle actions involving the given 'uid' and 'obj' object."
     1.8 +        """
     1.9 +        Handle actions involving the given 'uid' and 'obj' object, returning an
    1.10 +        error if one occurred, or None if the request was successfully handled.
    1.11 +        """
    1.12  
    1.13          # Handle a submitted form.
    1.14  
    1.15          args = self.env.get_args()
    1.16 -        handled = True
    1.17 +
    1.18 +        # Get the possible actions.
    1.19 +
    1.20 +        reply = args.has_key("reply")
    1.21 +        discard = args.has_key("discard")
    1.22 +        invite = args.has_key("invite")
    1.23 +        cancel = args.has_key("cancel")
    1.24 +        save = args.has_key("save")
    1.25 +
    1.26 +        have_action = reply or discard or invite or cancel or save
    1.27 +
    1.28 +        if not have_action:
    1.29 +            return ["action"]
    1.30  
    1.31          # Update the object.
    1.32  
    1.33 @@ -502,7 +517,7 @@
    1.34                  dtstart, attr = t
    1.35                  update = self.set_datetime_in_object(dtstart, attr["TZID"], "DTSTART", obj) or update
    1.36              else:
    1.37 -                return False
    1.38 +                return ["dtstart"]
    1.39  
    1.40              # Handle specified end datetimes.
    1.41  
    1.42 @@ -517,27 +532,23 @@
    1.43                          dtend += timedelta(1)
    1.44                      update = self.set_datetime_in_object(dtend, attr["TZID"], "DTEND", obj) or update
    1.45                  else:
    1.46 -                    return False
    1.47 +                    return ["dtend"]
    1.48  
    1.49 -            # Otherwise, treat the end date as the start date. Datetimes cannot
    1.50 -            # be duplicated in such a way.
    1.51 +            # Otherwise, treat the end date as the start date. Datetimes are
    1.52 +            # handled by making the event occupy the rest of the day.
    1.53  
    1.54              else:
    1.55 +                dtend = dtstart + timedelta(1)
    1.56                  if isinstance(dtstart, datetime):
    1.57 -                    return False
    1.58 -                dtend = dtstart + timedelta(1)
    1.59 +                    dtend = get_start_of_day(dtend, attr["TZID"])
    1.60                  update = self.set_datetime_in_object(dtend, attr["TZID"], "DTEND", obj) or update
    1.61  
    1.62              if dtstart >= dtend:
    1.63 -                return False
    1.64 +                return ["dtstart", "dtend"]
    1.65  
    1.66          # Process any action.
    1.67  
    1.68 -        reply = args.has_key("reply")
    1.69 -        discard = args.has_key("discard")
    1.70 -        invite = args.has_key("invite")
    1.71 -        cancel = args.has_key("cancel")
    1.72 -        save = args.has_key("save")
    1.73 +        handled = True
    1.74  
    1.75          if reply or invite or cancel:
    1.76  
    1.77 @@ -572,7 +583,7 @@
    1.78          if handled:
    1.79              self.redirect(self.env.get_path())
    1.80  
    1.81 -        return handled
    1.82 +        return None
    1.83  
    1.84      def handle_date_controls(self, name):
    1.85  
    1.86 @@ -679,11 +690,11 @@
    1.87          ("DELEGATED", "Delegated"),
    1.88          ]
    1.89  
    1.90 -    def show_object_on_page(self, uid, obj):
    1.91 +    def show_object_on_page(self, uid, obj, error=None):
    1.92  
    1.93          """
    1.94          Show the calendar object with the given 'uid' and representation 'obj'
    1.95 -        on the current page.
    1.96 +        on the current page. If 'error' is given, show a suitable message.
    1.97          """
    1.98  
    1.99          page = self.page
   1.100 @@ -752,8 +763,9 @@
   1.101              # Handle datetimes specially.
   1.102  
   1.103              if name in ["DTSTART", "DTEND"]:
   1.104 +                field = name.lower()
   1.105  
   1.106 -                page.th(label, class_="objectheading %s" % name.lower())
   1.107 +                page.th(label, class_="objectheading %s%s" % (field, error and field in error and " error" or ""))
   1.108  
   1.109                  # Obtain the datetime.
   1.110  
   1.111 @@ -771,14 +783,14 @@
   1.112                  value = format_datetime(dt)
   1.113  
   1.114                  if is_organiser:
   1.115 -                    page.td(class_="objectvalue %s" % name.lower())
   1.116 +                    page.td(class_="objectvalue %s" % field)
   1.117                      if name == "DTEND":
   1.118                          page.div(class_="disabled")
   1.119                          page.label("Specify end date", for_="dtend-enable", class_="enable")
   1.120                          page.div.close()
   1.121  
   1.122                      page.div(class_="enabled")
   1.123 -                    self._show_date_controls(name.lower(), value, attr, tzid)
   1.124 +                    self._show_date_controls(field, value, attr, tzid)
   1.125                      if name == "DTEND":
   1.126                          page.label("End on same day", for_="dtend-disable", class_="disable")
   1.127                      page.div.close()
   1.128 @@ -960,13 +972,13 @@
   1.129          if not obj:
   1.130              return False
   1.131  
   1.132 -        handled = self.handle_request(uid, obj)
   1.133 +        error = self.handle_request(uid, obj)
   1.134  
   1.135 -        if handled:
   1.136 +        if not error:
   1.137              return True
   1.138  
   1.139          self.new_page(title="Event")
   1.140 -        self.show_object_on_page(uid, obj)
   1.141 +        self.show_object_on_page(uid, obj, error)
   1.142  
   1.143          return True
   1.144