1.1 --- a/imip_manager.py Mon Feb 02 19:59:57 2015 +0100
1.2 +++ b/imip_manager.py Mon Feb 02 23:12:37 2015 +0100
1.3 @@ -360,13 +360,30 @@
1.4
1.5 # Create a new event using the available information.
1.6
1.7 - slot = args.get("slot", [None])[0]
1.8 + slots = args.get("slot", [])
1.9 participants = args.get("participants", [])
1.10
1.11 - if not slot:
1.12 + if not slots:
1.13 return
1.14
1.15 - start, end = slot.split("-")
1.16 + # Coalesce the selected slots.
1.17 +
1.18 + slots.sort()
1.19 + coalesced = []
1.20 + last = None
1.21 +
1.22 + for slot in slots:
1.23 + start, end = slot.split("-")
1.24 + if last:
1.25 + if start == last[1]:
1.26 + last = last[0], end
1.27 + continue
1.28 + else:
1.29 + coalesced.append(last)
1.30 + last = start, end
1.31 +
1.32 + if last:
1.33 + coalesced.append(last)
1.34
1.35 # Obtain the user's timezone.
1.36
1.37 @@ -378,36 +395,42 @@
1.38 utcnow = get_timestamp()
1.39 uid = "imip-agent-%s-%s" % (utcnow, get_address(self.user))
1.40
1.41 - # Create a calendar object and store it as a request.
1.42 -
1.43 - record = []
1.44 - rwrite = record.append
1.45 + # Define a single occurrence if only one coalesced slot exists.
1.46 + # Otherwise, many occurrences are defined.
1.47
1.48 - rwrite(("UID", {}, uid))
1.49 - rwrite(("SUMMARY", {}, "New event at %s" % utcnow))
1.50 - rwrite(("DTSTAMP", {}, utcnow))
1.51 - rwrite(("DTSTART", {"VALUE" : "DATE-TIME", "TZID" : tzid}, start))
1.52 - rwrite(("DTEND", {"VALUE" : "DATE-TIME", "TZID" : tzid}, end or
1.53 - format_datetime(get_end_of_day(get_datetime(start, {"TZID" : tzid})))
1.54 - ))
1.55 - rwrite(("ORGANIZER", {}, self.user))
1.56 + for i, (start, end) in enumerate(coalesced):
1.57 + this_uid = "%s-%s" % (uid, i)
1.58 +
1.59 + # Create a calendar object and store it as a request.
1.60 +
1.61 + record = []
1.62 + rwrite = record.append
1.63
1.64 - for participant in participants:
1.65 - if not participant:
1.66 - continue
1.67 - participant = get_uri(participant)
1.68 - if participant != self.user:
1.69 - rwrite(("ATTENDEE", {}, participant))
1.70 + rwrite(("UID", {}, this_uid))
1.71 + rwrite(("SUMMARY", {}, "New event at %s" % utcnow))
1.72 + rwrite(("DTSTAMP", {}, utcnow))
1.73 + rwrite(("DTSTART", {"VALUE" : "DATE-TIME", "TZID" : tzid}, start))
1.74 + rwrite(("DTEND", {"VALUE" : "DATE-TIME", "TZID" : tzid}, end or
1.75 + format_datetime(get_end_of_day(get_datetime(start, {"TZID" : tzid})))
1.76 + ))
1.77 + rwrite(("ORGANIZER", {}, self.user))
1.78
1.79 - obj = ("VEVENT", {}, record)
1.80 -
1.81 - self.store.set_event(self.user, uid, obj)
1.82 - self.store.queue_request(self.user, uid)
1.83 + for participant in participants:
1.84 + if not participant:
1.85 + continue
1.86 + participant = get_uri(participant)
1.87 + if participant != self.user:
1.88 + rwrite(("ATTENDEE", {}, participant))
1.89
1.90 - # Redirect to the object, where instead of attendee controls,
1.91 - # there will be organiser controls.
1.92 + obj = ("VEVENT", {}, record)
1.93 +
1.94 + self.store.set_event(self.user, this_uid, obj)
1.95 + self.store.queue_request(self.user, this_uid)
1.96
1.97 - self.redirect(self.env.new_url(uid))
1.98 + # Redirect to the object (or the first of the objects), where instead of
1.99 + # attendee controls, there will be organiser controls.
1.100 +
1.101 + self.redirect(self.env.new_url("%s-0" % uid))
1.102
1.103 def handle_request(self, uid, obj, queued):
1.104
1.105 @@ -1074,15 +1097,15 @@
1.106 value, identifier = self._slot_value_and_identifier(point, endpoint)
1.107 slot = self.env.get_args().get("slot", [None])[0]
1.108 if slot == value:
1.109 - page.input(name="slot", type="radio", value=value, id=identifier, class_="newevent", checked="checked")
1.110 + page.input(name="slot", type="checkbox", value=value, id=identifier, class_="newevent", checked="checked")
1.111 else:
1.112 - page.input(name="slot", type="radio", value=value, id=identifier, class_="newevent")
1.113 + page.input(name="slot", type="checkbox", value=value, id=identifier, class_="newevent")
1.114 page.label(self.format_time(point, "long"), class_="timepoint", for_=identifier)
1.115
1.116 def _empty_slot(self, point, endpoint):
1.117 page = self.page
1.118 value, identifier = self._slot_value_and_identifier(point, endpoint)
1.119 - page.label("Make a new event in this period", class_="newevent popup", for_=identifier)
1.120 + page.label("Select/deselect period", class_="newevent popup", for_=identifier)
1.121
1.122 def _slot_value_and_identifier(self, point, endpoint):
1.123 value = "%s-%s" % (format_datetime(point), endpoint and format_datetime(endpoint) or "")