1.1 --- a/imip_manager.py Fri Jan 30 16:15:11 2015 +0100
1.2 +++ b/imip_manager.py Fri Jan 30 18:24:43 2015 +0100
1.3 @@ -24,6 +24,7 @@
1.4
1.5 LIBRARY_PATH = "/var/lib/imip-agent"
1.6
1.7 +from datetime import datetime
1.8 import babel.dates
1.9 import cgi, os, sys
1.10
1.11 @@ -33,7 +34,7 @@
1.12 get_item, get_uri, get_utc_datetime, get_value, \
1.13 get_value_map, get_values, parse_object, to_part
1.14 from imiptools.dates import format_datetime, get_datetime, get_start_of_day, \
1.15 - ends_on_same_day, to_timezone
1.16 + get_end_of_day, ends_on_same_day, to_timezone
1.17 from imiptools.mail import Messenger
1.18 from imiptools.period import add_day_start_points, add_slots, convert_periods, \
1.19 get_freebusy_details, \
1.20 @@ -290,6 +291,68 @@
1.21
1.22 # Request logic and page fragment methods.
1.23
1.24 + def handle_newevent(self):
1.25 +
1.26 + "Handle any new event operation."
1.27 +
1.28 + # Handle a submitted form.
1.29 +
1.30 + args = self.env.get_args()
1.31 +
1.32 + if not args.has_key("newevent"):
1.33 + return
1.34 +
1.35 + # Create a new event using the available information.
1.36 +
1.37 + slot = args.get("slot", [None])[0]
1.38 + participants = args.get("participants", [])
1.39 +
1.40 + if not slot:
1.41 + return
1.42 +
1.43 + start, end = slot.split("-")
1.44 +
1.45 + # Obtain the user's timezone.
1.46 +
1.47 + prefs = self.get_preferences()
1.48 + tzid = prefs.get("TZID", "UTC")
1.49 +
1.50 + # Invent a unique identifier.
1.51 +
1.52 + utcnow = format_datetime(to_timezone(datetime.utcnow(), "UTC"))
1.53 + uid = "imip-agent-%s-%s" % (utcnow, get_address(self.user))
1.54 +
1.55 + # Create a calendar object and store it as a request.
1.56 +
1.57 + record = []
1.58 + rwrite = record.append
1.59 +
1.60 + rwrite(("UID", {}, uid))
1.61 + rwrite(("SUMMARY", {}, "New event at %s" % utcnow))
1.62 + rwrite(("DTSTAMP", {}, utcnow))
1.63 + rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, start))
1.64 + rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, end or
1.65 + format_datetime(get_end_of_day(get_datetime(start, {"TZID" : tzid})))
1.66 + ))
1.67 + rwrite(("ORGANIZER", {}, self.user))
1.68 +
1.69 + for participant in participants:
1.70 + if not participant:
1.71 + continue
1.72 + participant = get_uri(participant)
1.73 + if participant != self.user:
1.74 + rwrite(("ATTENDEE", {}, participant))
1.75 +
1.76 + obj = ("VEVENT", {}, record)
1.77 +
1.78 + self.store.set_event(self.user, uid, obj)
1.79 + self.store.queue_request(self.user, uid)
1.80 +
1.81 + # Redirect to the object, where instead of attendee controls,
1.82 + # there will be organiser controls.
1.83 +
1.84 + self.redirect(self.env.new_url(uid))
1.85 +
1.86 def handle_request(self, uid, request, queued):
1.87
1.88 """
1.89 @@ -537,6 +600,8 @@
1.90
1.91 "Show the calendar for the current user."
1.92
1.93 + handled = self.handle_newevent()
1.94 +
1.95 self.new_page(title="Calendar")
1.96 page = self.page
1.97
1.98 @@ -848,7 +913,11 @@
1.99 def _time_point(self, point, endpoint):
1.100 page = self.page
1.101 value, identifier = self._slot_value_and_identifier(point, endpoint)
1.102 - page.input(name="start", type="radio", value=value, id=identifier, class_="newevent")
1.103 + slot = self.env.get_args().get("slot", [None])[0]
1.104 + if slot == value:
1.105 + page.input(name="slot", type="radio", value=value, id=identifier, class_="newevent", checked="checked")
1.106 + else:
1.107 + page.input(name="slot", type="radio", value=value, id=identifier, class_="newevent")
1.108 page.label(self.format_time(point, "long"), class_="timepoint", for_=identifier)
1.109
1.110 def _empty_slot(self, point, endpoint):
1.111 @@ -857,7 +926,7 @@
1.112 page.label("Make a new event in this period", class_="newevent popup", for_=identifier)
1.113
1.114 def _slot_value_and_identifier(self, point, endpoint):
1.115 - value = "%s-%s" % tuple(map(format_datetime, [point, endpoint]))
1.116 + value = "%s-%s" % (format_datetime(point), endpoint and format_datetime(endpoint) or "")
1.117 identifier = "slot-%s" % value
1.118 return value, identifier
1.119