imip-agent

Change of imip_manager.py

300:8d0c013ef527
imip_manager.py
     1.1 --- a/imip_manager.py	Sun Feb 08 22:52:37 2015 +0100
     1.2 +++ b/imip_manager.py	Mon Feb 09 14:37:21 2015 +0100
     1.3 @@ -512,17 +512,20 @@
     1.4          update = False
     1.5  
     1.6          if is_organiser:
     1.7 -            t = self.handle_date_controls("dtstart")
     1.8 +            dtend_enabled = args.get("dtend-control", [None])[0] == "enable"
     1.9 +            dttimes_enabled = args.get("dttimes-control", [None])[0] == "enable"
    1.10 +
    1.11 +            t = self.handle_date_controls("dtstart", dttimes_enabled)
    1.12              if t:
    1.13                  dtstart, attr = t
    1.14 -                update = self.set_datetime_in_object(dtstart, attr["TZID"], "DTSTART", obj) or update
    1.15 +                update = self.set_datetime_in_object(dtstart, attr.get("TZID"), "DTSTART", obj) or update
    1.16              else:
    1.17                  return ["dtstart"]
    1.18  
    1.19              # Handle specified end datetimes.
    1.20  
    1.21 -            if args.get("dtend-control", [None])[0] == "enable":
    1.22 -                t = self.handle_date_controls("dtend")
    1.23 +            if dtend_enabled:
    1.24 +                t = self.handle_date_controls("dtend", dttimes_enabled)
    1.25                  if t:
    1.26                      dtend, attr = t
    1.27  
    1.28 @@ -530,7 +533,7 @@
    1.29  
    1.30                      if not isinstance(dtend, datetime):
    1.31                          dtend += timedelta(1)
    1.32 -                    update = self.set_datetime_in_object(dtend, attr["TZID"], "DTEND", obj) or update
    1.33 +                    update = self.set_datetime_in_object(dtend, attr.get("TZID"), "DTEND", obj) or update
    1.34                  else:
    1.35                      return ["dtend"]
    1.36  
    1.37 @@ -541,7 +544,7 @@
    1.38                  dtend = dtstart + timedelta(1)
    1.39                  if isinstance(dtstart, datetime):
    1.40                      dtend = get_start_of_day(dtend, attr["TZID"])
    1.41 -                update = self.set_datetime_in_object(dtend, attr["TZID"], "DTEND", obj) or update
    1.42 +                update = self.set_datetime_in_object(dtend, attr.get("TZID"), "DTEND", obj) or update
    1.43  
    1.44              if dtstart >= dtend:
    1.45                  return ["dtstart", "dtend"]
    1.46 @@ -585,7 +588,7 @@
    1.47  
    1.48          return None
    1.49  
    1.50 -    def handle_date_controls(self, name):
    1.51 +    def handle_date_controls(self, name, with_time=True):
    1.52  
    1.53          """
    1.54          Handle date control information for fields starting with 'name',
    1.55 @@ -594,19 +597,24 @@
    1.56          """
    1.57  
    1.58          args = self.env.get_args()
    1.59 -        tzid = self.get_tzid()
    1.60  
    1.61          if args.has_key("%s-date" % name):
    1.62              date = args["%s-date" % name][0]
    1.63 -            hour = args.get("%s-hour" % name, [None])[0]
    1.64 -            minute = args.get("%s-minute" % name, [None])[0]
    1.65 -            second = args.get("%s-second" % name, [None])[0]
    1.66 -            tzid = args.get("%s-tzid" % name, [tzid])[0]
    1.67 +
    1.68 +            if with_time:
    1.69 +                hour = args.get("%s-hour" % name, [None])[0]
    1.70 +                minute = args.get("%s-minute" % name, [None])[0]
    1.71 +                second = args.get("%s-second" % name, [None])[0]
    1.72 +                tzid = args.get("%s-tzid" % name, [self.get_tzid()])[0]
    1.73  
    1.74 -            time = (hour or minute or second) and "T%s%s%s" % (hour, minute, second) or ""
    1.75 -            value = "%s%s" % (date, time)
    1.76 -            attr = {"TZID" : tzid}
    1.77 -            dt = get_datetime(value, attr)
    1.78 +                time = (hour or minute or second) and "T%s%s%s" % (hour, minute, second) or ""
    1.79 +                value = "%s%s" % (date, time)
    1.80 +                attr = {"TZID" : tzid, "VALUE" : "DATE-TIME"}
    1.81 +                dt = get_datetime(value, attr)
    1.82 +            else:
    1.83 +                attr = {"VALUE" : "DATE"}
    1.84 +                dt = get_datetime(date)
    1.85 +
    1.86              if dt:
    1.87                  return dt, attr
    1.88  
    1.89 @@ -707,17 +715,18 @@
    1.90          # Provide controls to change the displayed object.
    1.91  
    1.92          args = self.env.get_args()
    1.93 +        dtend_control = args.get("dtend-control", [None])[0]
    1.94 +        dttimes_control = args.get("dttimes-control", [None])[0]
    1.95 +        with_time = dttimes_control == "enable"
    1.96  
    1.97 -        t = self.handle_date_controls("dtstart")
    1.98 +        t = self.handle_date_controls("dtstart", with_time)
    1.99          if t:
   1.100              dtstart, dtstart_attr = t
   1.101          else:
   1.102              dtstart, dtstart_attr = obj.get_datetime_item("DTSTART")
   1.103  
   1.104 -        dtend_control = args.get("dtend-control", [None])[0]
   1.105 -
   1.106          if dtend_control == "enable":
   1.107 -            t = self.handle_date_controls("dtend")
   1.108 +            t = self.handle_date_controls("dtend", with_time)
   1.109              if t:
   1.110                  dtend, dtend_attr = t
   1.111              else:
   1.112 @@ -736,15 +745,23 @@
   1.113          # Show the end datetime controls if already active or if an object needs
   1.114          # them.
   1.115  
   1.116 -        dtend_control = dtend_control or (isinstance(dtend, datetime) or dtstart != dtend) and "enable" or None
   1.117 +        dtend_enabled = dtend_control == "enable" or isinstance(dtend, datetime) or dtstart != dtend
   1.118 +        dttimes_enabled = dttimes_control == "enable" or isinstance(dtstart, datetime) or isinstance(dtend, datetime)
   1.119  
   1.120 -        if dtend_control == "enable":
   1.121 +        if dtend_enabled:
   1.122              page.input(name="dtend-control", type="radio", value="enable", id="dtend-enable", checked="checked")
   1.123              page.input(name="dtend-control", type="radio", value="disable", id="dtend-disable")
   1.124          else:
   1.125              page.input(name="dtend-control", type="radio", value="enable", id="dtend-enable")
   1.126              page.input(name="dtend-control", type="radio", value="disable", id="dtend-disable", checked="checked")
   1.127  
   1.128 +        if dttimes_enabled:
   1.129 +            page.input(name="dttimes-control", type="radio", value="enable", id="dttimes-enable", checked="checked")
   1.130 +            page.input(name="dttimes-control", type="radio", value="disable", id="dttimes-disable")
   1.131 +        else:
   1.132 +            page.input(name="dttimes-control", type="radio", value="enable", id="dttimes-enable")
   1.133 +            page.input(name="dttimes-control", type="radio", value="disable", id="dttimes-disable", checked="checked")
   1.134 +
   1.135          # Provide a summary of the object.
   1.136  
   1.137          page.table(class_="object", cellspacing=5, cellpadding=5)
   1.138 @@ -779,25 +796,32 @@
   1.139                  else:
   1.140                      dt, attr, event_tzid = dtend or dtstart, dtend_attr or dtstart_attr, (dtend_attr or dtstart_attr).get("TZID", tzid)
   1.141  
   1.142 -                strvalue = self.format_datetime(dt, "full")
   1.143 -                value = format_datetime(dt)
   1.144 +                # Show controls for editing as organiser.
   1.145  
   1.146                  if is_organiser:
   1.147 +                    value = format_datetime(dt)
   1.148 +
   1.149                      page.td(class_="objectvalue %s" % field)
   1.150                      if name == "DTEND":
   1.151 -                        page.div(class_="disabled")
   1.152 +                        page.div(class_="dt disabled")
   1.153                          page.label("Specify end date", for_="dtend-enable", class_="enable")
   1.154                          page.div.close()
   1.155  
   1.156 -                    page.div(class_="enabled")
   1.157 +                    page.div(class_="dt enabled")
   1.158                      self._show_date_controls(field, value, attr, tzid)
   1.159 -                    if name == "DTEND":
   1.160 +                    if name == "DTSTART":
   1.161 +                        page.label("Specify times", for_="dttimes-enable", class_="time disabled enable")
   1.162 +                        page.label("Specify dates only", for_="dttimes-disable", class_="time enabled disable")
   1.163 +                    elif name == "DTEND":
   1.164                          page.label("End on same day", for_="dtend-disable", class_="disable")
   1.165                      page.div.close()
   1.166  
   1.167                      page.td.close()
   1.168 +
   1.169 +                # Show a label as attendee.
   1.170 +
   1.171                  else:
   1.172 -                    page.td(strvalue)
   1.173 +                    page.td(self.format_datetime(dt, "full"))
   1.174  
   1.175                  page.tr.close()
   1.176  
   1.177 @@ -1478,21 +1502,23 @@
   1.178  
   1.179          # Show time details.
   1.180  
   1.181 -        if isinstance(dt, datetime):
   1.182 -            hour = args.get("%s-hour" % name, "%02d" % dt.hour)
   1.183 -            minute = args.get("%s-minute" % name, "%02d" % dt.minute)
   1.184 -            second = args.get("%s-second" % name, "%02d" % dt.second)
   1.185 -            page.add(" ")
   1.186 -            page.input(name="%s-hour" % name, type="text", value=hour, maxlength=2, size=2)
   1.187 -            page.add(":")
   1.188 -            page.input(name="%s-minute" % name, type="text", value=minute, maxlength=2, size=2)
   1.189 -            page.add(":")
   1.190 -            page.input(name="%s-second" % name, type="text", value=second, maxlength=2, size=2)
   1.191 -            page.add(" ")
   1.192 -            self._show_menu("%s-tzid" % name, event_tzid,
   1.193 -                [(event_tzid, event_tzid)] + (
   1.194 -                event_tzid != tzid and [(tzid, tzid)] or []
   1.195 -                ))
   1.196 +        dt_time = isinstance(dt, datetime) and dt or None
   1.197 +        hour = args.get("%s-hour" % name, "%02d" % (dt_time and dt_time.hour or 0))
   1.198 +        minute = args.get("%s-minute" % name, "%02d" % (dt_time and dt_time.minute or 0))
   1.199 +        second = args.get("%s-second" % name, "%02d" % (dt_time and dt_time.second or 0))
   1.200 +
   1.201 +        page.span(class_="time enabled")
   1.202 +        page.input(name="%s-hour" % name, type="text", value=hour, maxlength=2, size=2)
   1.203 +        page.add(":")
   1.204 +        page.input(name="%s-minute" % name, type="text", value=minute, maxlength=2, size=2)
   1.205 +        page.add(":")
   1.206 +        page.input(name="%s-second" % name, type="text", value=second, maxlength=2, size=2)
   1.207 +        page.add(" ")
   1.208 +        self._show_menu("%s-tzid" % name, event_tzid,
   1.209 +            [(event_tzid, event_tzid)] + (
   1.210 +            event_tzid != tzid and [(tzid, tzid)] or []
   1.211 +            ))
   1.212 +        page.span.close()
   1.213  
   1.214      # Incoming HTTP request direction.
   1.215