2.1 --- a/imip_manager.py Mon Feb 02 19:59:57 2015 +0100
2.2 +++ b/imip_manager.py Mon Feb 02 23:12:37 2015 +0100
2.3 @@ -360,13 +360,30 @@
2.4
2.5 # Create a new event using the available information.
2.6
2.7 - slot = args.get("slot", [None])[0]
2.8 + slots = args.get("slot", [])
2.9 participants = args.get("participants", [])
2.10
2.11 - if not slot:
2.12 + if not slots:
2.13 return
2.14
2.15 - start, end = slot.split("-")
2.16 + # Coalesce the selected slots.
2.17 +
2.18 + slots.sort()
2.19 + coalesced = []
2.20 + last = None
2.21 +
2.22 + for slot in slots:
2.23 + start, end = slot.split("-")
2.24 + if last:
2.25 + if start == last[1]:
2.26 + last = last[0], end
2.27 + continue
2.28 + else:
2.29 + coalesced.append(last)
2.30 + last = start, end
2.31 +
2.32 + if last:
2.33 + coalesced.append(last)
2.34
2.35 # Obtain the user's timezone.
2.36
2.37 @@ -378,36 +395,42 @@
2.38 utcnow = get_timestamp()
2.39 uid = "imip-agent-%s-%s" % (utcnow, get_address(self.user))
2.40
2.41 - # Create a calendar object and store it as a request.
2.42 -
2.43 - record = []
2.44 - rwrite = record.append
2.45 + # Define a single occurrence if only one coalesced slot exists.
2.46 + # Otherwise, many occurrences are defined.
2.47
2.48 - rwrite(("UID", {}, uid))
2.49 - rwrite(("SUMMARY", {}, "New event at %s" % utcnow))
2.50 - rwrite(("DTSTAMP", {}, utcnow))
2.51 - rwrite(("DTSTART", {"VALUE" : "DATE-TIME", "TZID" : tzid}, start))
2.52 - rwrite(("DTEND", {"VALUE" : "DATE-TIME", "TZID" : tzid}, end or
2.53 - format_datetime(get_end_of_day(get_datetime(start, {"TZID" : tzid})))
2.54 - ))
2.55 - rwrite(("ORGANIZER", {}, self.user))
2.56 + for i, (start, end) in enumerate(coalesced):
2.57 + this_uid = "%s-%s" % (uid, i)
2.58 +
2.59 + # Create a calendar object and store it as a request.
2.60 +
2.61 + record = []
2.62 + rwrite = record.append
2.63
2.64 - for participant in participants:
2.65 - if not participant:
2.66 - continue
2.67 - participant = get_uri(participant)
2.68 - if participant != self.user:
2.69 - rwrite(("ATTENDEE", {}, participant))
2.70 + rwrite(("UID", {}, this_uid))
2.71 + rwrite(("SUMMARY", {}, "New event at %s" % utcnow))
2.72 + rwrite(("DTSTAMP", {}, utcnow))
2.73 + rwrite(("DTSTART", {"VALUE" : "DATE-TIME", "TZID" : tzid}, start))
2.74 + rwrite(("DTEND", {"VALUE" : "DATE-TIME", "TZID" : tzid}, end or
2.75 + format_datetime(get_end_of_day(get_datetime(start, {"TZID" : tzid})))
2.76 + ))
2.77 + rwrite(("ORGANIZER", {}, self.user))
2.78
2.79 - obj = ("VEVENT", {}, record)
2.80 -
2.81 - self.store.set_event(self.user, uid, obj)
2.82 - self.store.queue_request(self.user, uid)
2.83 + for participant in participants:
2.84 + if not participant:
2.85 + continue
2.86 + participant = get_uri(participant)
2.87 + if participant != self.user:
2.88 + rwrite(("ATTENDEE", {}, participant))
2.89
2.90 - # Redirect to the object, where instead of attendee controls,
2.91 - # there will be organiser controls.
2.92 + obj = ("VEVENT", {}, record)
2.93 +
2.94 + self.store.set_event(self.user, this_uid, obj)
2.95 + self.store.queue_request(self.user, this_uid)
2.96
2.97 - self.redirect(self.env.new_url(uid))
2.98 + # Redirect to the object (or the first of the objects), where instead of
2.99 + # attendee controls, there will be organiser controls.
2.100 +
2.101 + self.redirect(self.env.new_url("%s-0" % uid))
2.102
2.103 def handle_request(self, uid, obj, queued):
2.104
2.105 @@ -1074,15 +1097,15 @@
2.106 value, identifier = self._slot_value_and_identifier(point, endpoint)
2.107 slot = self.env.get_args().get("slot", [None])[0]
2.108 if slot == value:
2.109 - page.input(name="slot", type="radio", value=value, id=identifier, class_="newevent", checked="checked")
2.110 + page.input(name="slot", type="checkbox", value=value, id=identifier, class_="newevent", checked="checked")
2.111 else:
2.112 - page.input(name="slot", type="radio", value=value, id=identifier, class_="newevent")
2.113 + page.input(name="slot", type="checkbox", value=value, id=identifier, class_="newevent")
2.114 page.label(self.format_time(point, "long"), class_="timepoint", for_=identifier)
2.115
2.116 def _empty_slot(self, point, endpoint):
2.117 page = self.page
2.118 value, identifier = self._slot_value_and_identifier(point, endpoint)
2.119 - page.label("Make a new event in this period", class_="newevent popup", for_=identifier)
2.120 + page.label("Select/deselect period", class_="newevent popup", for_=identifier)
2.121
2.122 def _slot_value_and_identifier(self, point, endpoint):
2.123 value = "%s-%s" % (format_datetime(point), endpoint and format_datetime(endpoint) or "")