1.1 --- a/imipweb/event.py Wed May 13 13:02:35 2015 +0200
1.2 +++ b/imipweb/event.py Wed May 13 14:18:07 2015 +0200
1.3 @@ -210,8 +210,9 @@
1.4
1.5 for period in periods:
1.6 p = event_period_from_period(period)
1.7 - tzid = p.start_attr and p.start_attr.get("TZID") or p.end_attr and p.end_attr.get("TZID")
1.8 - new_rdates.append(get_period_item(p.start, p.end, tzid))
1.9 + if p.origin != "RRULE":
1.10 + tzid = p.start_attr and p.start_attr.get("TZID") or p.end_attr and p.end_attr.get("TZID")
1.11 + new_rdates.append(get_period_item(p.start, p.end, tzid))
1.12
1.13 obj["RDATE"] = new_rdates
1.14
1.15 @@ -324,6 +325,12 @@
1.16 return FormPeriod(start, end, dtend_enabled, dttimes_enabled)
1.17
1.18 def get_current_recurrences(self, obj):
1.19 +
1.20 + """
1.21 + Return recurrences for 'obj' using the original object where no editing
1.22 + is in progress, using form data otherwise.
1.23 + """
1.24 +
1.25 args = self.env.get_args()
1.26 initial_load = not args.has_key("editing")
1.27
1.28 @@ -333,6 +340,9 @@
1.29 return self.get_recurrences()
1.30
1.31 def get_existing_recurrences(self, obj):
1.32 +
1.33 + "Return recurrences computed using the given 'obj'."
1.34 +
1.35 recurrences = []
1.36 for period in obj.get_periods(self.get_tzid(), self.get_window_end()):
1.37 if period.origin != "DTSTART":
1.38 @@ -349,15 +359,16 @@
1.39 all_dttimes_enabled = args.get("dttimes-control-recur", [])
1.40 all_starts = self.get_date_control_values("dtstart-recur", multiple=True)
1.41 all_ends = self.get_date_control_values("dtend-recur", multiple=True, tzid_name="dtstart-recur")
1.42 + all_origins = args.get("recur-origin", [])
1.43
1.44 periods = []
1.45
1.46 - for index, (start, end, dtend_enabled, dttimes_enabled) in \
1.47 - enumerate(map(None, all_starts, all_ends, all_dtend_enabled, all_dttimes_enabled)):
1.48 + for index, (start, end, dtend_enabled, dttimes_enabled, origin) in \
1.49 + enumerate(map(None, all_starts, all_ends, all_dtend_enabled, all_dttimes_enabled, all_origins)):
1.50
1.51 dtend_enabled = str(index) in all_dtend_enabled
1.52 dttimes_enabled = str(index) in all_dttimes_enabled
1.53 - period = FormPeriod(start, end, dtend_enabled, dttimes_enabled)
1.54 + period = FormPeriod(start, end, dtend_enabled, dttimes_enabled, origin)
1.55 periods.append(period)
1.56
1.57 return periods
1.58 @@ -726,7 +737,7 @@
1.59 self.show_object_datetime_controls(p, index)
1.60
1.61 page.table(cellspacing=5, cellpadding=5, class_="recurrence")
1.62 - page.caption("Occurrence")
1.63 + page.caption(p.origin == "RRULE" and "Occurrence from rule" or "Occurrence")
1.64 page.tbody()
1.65
1.66 page.tr()
1.67 @@ -972,22 +983,31 @@
1.68 if self.is_organiser(obj) and not replaced:
1.69 page.td(class_="objectvalue dt%s" % (show_start and "start" or "end"))
1.70
1.71 + read_only = period.origin == "RRULE"
1.72 +
1.73 if show_start:
1.74 page.div(class_="dt enabled")
1.75 - self._show_date_controls(ssn("dtstart", "recur", index), p.get_form_start(), index=index)
1.76 - page.br()
1.77 - page.label("Specify times", for_=sn("dttimes-enable", index), class_="time disabled enable")
1.78 - page.label("Specify dates only", for_=sn("dttimes-enable", index), class_="time enabled disable")
1.79 + self._show_date_controls(ssn("dtstart", "recur", index), p.get_form_start(), index=index, read_only=read_only)
1.80 + if not read_only:
1.81 + page.br()
1.82 + page.label("Specify times", for_=sn("dttimes-enable", index), class_="time disabled enable")
1.83 + page.label("Specify dates only", for_=sn("dttimes-enable", index), class_="time enabled disable")
1.84 page.div.close()
1.85
1.86 + # Put the origin somewhere.
1.87 +
1.88 + page.input(name="recur-origin", type="hidden", value=p.origin or "")
1.89 +
1.90 else:
1.91 page.div(class_="dt disabled")
1.92 - page.label("Specify end date", for_=sn("dtend-enable", index), class_="enable")
1.93 + if not read_only:
1.94 + page.label("Specify end date", for_=sn("dtend-enable", index), class_="enable")
1.95 page.div.close()
1.96 page.div(class_="dt enabled")
1.97 - self._show_date_controls(ssn("dtend", "recur", index), p.get_form_end(), index=index, show_tzid=False)
1.98 - page.br()
1.99 - page.label("End on same day", for_=sn("dtend-enable", index), class_="disable")
1.100 + self._show_date_controls(ssn("dtend", "recur", index), p.get_form_end(), index=index, show_tzid=False, read_only=read_only)
1.101 + if not read_only:
1.102 + page.br()
1.103 + page.label("End on same day", for_=sn("dtend-enable", index), class_="disable")
1.104 page.div.close()
1.105
1.106 page.td.close()
1.107 @@ -1089,7 +1109,7 @@
1.108 page.option(label, value=v)
1.109 page.select.close()
1.110
1.111 - def _show_date_controls(self, name, default, index=None, show_tzid=True):
1.112 + def _show_date_controls(self, name, default, index=None, show_tzid=True, read_only=False):
1.113
1.114 """
1.115 Show date controls for a field with the given 'name' and 'default' form
1.116 @@ -1102,6 +1122,9 @@
1.117
1.118 If 'show_tzid' is set to a false value, the time zone menu will not be
1.119 provided.
1.120 +
1.121 + If 'read_only' is set to a true value, the controls will be hidden and
1.122 + labels will be employed instead.
1.123 """
1.124
1.125 page = self.page
1.126 @@ -1115,26 +1138,51 @@
1.127 dt = date.today()
1.128
1.129 base = to_date(dt)
1.130 - items = []
1.131 - for i in range(-7, 8):
1.132 - d = base + timedelta(i)
1.133 - items.append((format_datetime(d), self.format_date(d, "full")))
1.134 +
1.135 + # Show a date label with a hidden field if read-only.
1.136 +
1.137 + if read_only:
1.138 + page.input(name="%s-date" % name, type="hidden", value=format_datetime(base))
1.139 + page.span(self.format_date(base, "long"))
1.140
1.141 - self._show_menu("%s-date" % name, format_datetime(base), items, index=index)
1.142 + # Show dates for up to one week around the current date.
1.143 +
1.144 + else:
1.145 + items = []
1.146 + for i in range(-7, 8):
1.147 + d = base + timedelta(i)
1.148 + items.append((format_datetime(d), self.format_date(d, "full")))
1.149 + self._show_menu("%s-date" % name, format_datetime(base), items, index=index)
1.150
1.151 # Show time details.
1.152
1.153 page.span(class_="time enabled")
1.154 - page.input(name="%s-hour" % name, type="text", value=default.get_hour(), maxlength=2, size=2)
1.155 - page.add(":")
1.156 - page.input(name="%s-minute" % name, type="text", value=default.get_minute(), maxlength=2, size=2)
1.157 - page.add(":")
1.158 - page.input(name="%s-second" % name, type="text", value=default.get_second(), maxlength=2, size=2)
1.159 +
1.160 + if read_only:
1.161 + page.span("%s:%s:%s" % (default.get_hour(), default.get_minute(), default.get_second()))
1.162 + page.input(name="%s-hour" % name, type="hidden", value=default.get_hour())
1.163 + page.input(name="%s-minute" % name, type="hidden", value=default.get_minute())
1.164 + page.input(name="%s-second" % name, type="hidden", value=default.get_second())
1.165 + else:
1.166 + page.input(name="%s-hour" % name, type="text", value=default.get_hour(), maxlength=2, size=2)
1.167 + page.add(":")
1.168 + page.input(name="%s-minute" % name, type="text", value=default.get_minute(), maxlength=2, size=2)
1.169 + page.add(":")
1.170 + page.input(name="%s-second" % name, type="text", value=default.get_second(), maxlength=2, size=2)
1.171 +
1.172 + # Show time zone details.
1.173
1.174 if show_tzid:
1.175 page.add(" ")
1.176 tzid = default.get_tzid() or self.get_tzid()
1.177 - self._show_timezone_menu("%s-tzid" % name, tzid, index)
1.178 +
1.179 + # Show a label if read-only or a menu otherwise.
1.180 +
1.181 + if read_only:
1.182 + page.input(name="%s-tzid" % name, type="hidden", value=tzid)
1.183 + page.span(tzid)
1.184 + else:
1.185 + self._show_timezone_menu("%s-tzid" % name, tzid, index)
1.186
1.187 page.span.close()
1.188