# HG changeset patch # User Paul Boddie # Date 1442617697 -7200 # Node ID d40e26697850eceb4324d53407b3a6e2999dc029 # Parent 02fb76c41c87cca07597eea0b49b16d586d33044 Added initial support for showing counter-proposals. diff -r 02fb76c41c87 -r d40e26697850 imiptools/client.py --- a/imiptools/client.py Sat Sep 19 01:07:40 2015 +0200 +++ b/imiptools/client.py Sat Sep 19 01:08:17 2015 +0200 @@ -281,14 +281,18 @@ # Store operations. - def get_stored_object(self, uid, recurrenceid): + def get_stored_object(self, uid, recurrenceid, section=None): """ Return the stored object for the current user, with the given 'uid' and - 'recurrenceid'. + 'recurrenceid' from the given 'section' (if specified), or from the + standard object collection otherwise. """ - fragment = self.store.get_event(self.user, uid, recurrenceid) + if section == "counters": + fragment = self.store.get_counter(self.user, uid, recurrenceid) + else: + fragment = self.store.get_event(self.user, uid, recurrenceid) return fragment and Object(fragment) # Free/busy operations. diff -r 02fb76c41c87 -r d40e26697850 imipweb/calendar.py --- a/imipweb/calendar.py Sat Sep 19 01:07:40 2015 +0200 +++ b/imipweb/calendar.py Sat Sep 19 01:08:17 2015 +0200 @@ -702,11 +702,22 @@ else: page.td(class_=css, rowspan=span) - # Only link to events if they are not being - # updated by requests. + # Only link to events if they are not being updated + # by requests. + + if not p.summary or \ + group_type != "request" and self._have_request(p.uid, p.recurrenceid, None, True): + + page.span(p.summary or "(Participant is busy)") - if not p.summary or self._have_request(p.uid, p.recurrenceid) and group_type != "request": - page.span(p.summary or "(Participant is busy)") + # Link to counter-proposals. + + elif group_type == "request" and self._have_request(p.uid, p.recurrenceid, "COUNTER", True): + page.a(p.summary, href=self.link_to(p.uid, p.recurrenceid, "counter")) + + # Link to requests and events (including ones for + # which counter-proposals exist). + else: page.a(p.summary, href=self.link_to(p.uid, p.recurrenceid)) diff -r 02fb76c41c87 -r d40e26697850 imipweb/event.py --- a/imipweb/event.py Sat Sep 19 01:07:40 2015 +0200 +++ b/imipweb/event.py Sat Sep 19 01:08:17 2015 +0200 @@ -1082,8 +1082,8 @@ "Show an object request using the given 'path_info' for the current user." - uid, recurrenceid = self._get_identifiers(path_info) - obj = self.get_stored_object(uid, recurrenceid) + uid, recurrenceid, section = self.get_identifiers(path_info) + obj = self.get_stored_object(uid, recurrenceid, section) if not obj: return False diff -r 02fb76c41c87 -r d40e26697850 imipweb/resource.py --- a/imipweb/resource.py Sat Sep 19 01:07:40 2015 +0200 +++ b/imipweb/resource.py Sat Sep 19 01:08:17 2015 +0200 @@ -83,11 +83,19 @@ self.new_page(title="Redirect") self.page.p("Redirecting to: %s" % url) - def link_to(self, uid, recurrenceid=None): + def link_to(self, uid, recurrenceid=None, section=None): + + """ + Return a link to an object with the given 'uid', 'recurrenceid' and + 'section'. See get_identifiers for the decoding of such links. + """ + + path = [uid] if recurrenceid: - return self.env.new_url("/".join([uid, recurrenceid])) - else: - return self.env.new_url(uid) + path.append(recurrenceid) + if section: + path.append(section) + return self.env.new_url("/".join(path)) # Control naming helpers. @@ -102,18 +110,38 @@ # Access to objects. - def _get_identifiers(self, path_info): + def get_identifiers(self, path_info): + + """ + Return identifiers provided by 'path_info', potentially encoded by + 'link_to'. + """ + parts = path_info.lstrip("/").split("/") + + # UID only. + if len(parts) == 1: - return parts[0], None + return parts[0], None, None + + # UID and RECURRENCE-ID or UID and section. + + elif len(parts) == 2: + if parts[1] == "counter": + return parts[0], None, "counters" + else: + return parts[0], parts[1], parts[2] == "counter" and "counters" or None + + # UID, RECURRENCE-ID and section. + else: - return parts[:2] + return parts[:3] - def _get_object(self, uid, recurrenceid=None): - if self.objects.has_key((uid, recurrenceid)): - return self.objects[(uid, recurrenceid)] + def _get_object(self, uid, recurrenceid=None, section=None): + if self.objects.has_key((uid, recurrenceid, section)): + return self.objects[(uid, recurrenceid, section)] - obj = self.objects[(uid, recurrenceid)] = self.get_stored_object(uid, recurrenceid) + obj = self.objects[(uid, recurrenceid, section)] = self.get_stored_object(uid, recurrenceid, section) return obj def _get_recurrences(self, uid): @@ -127,9 +155,8 @@ self.requests = self.store.get_requests(self.user) return self.requests - def _have_request(self, uid, recurrenceid=None): - requests = self._get_requests() - return self.store.have_request(requests, uid, recurrenceid) + def _have_request(self, uid, recurrenceid=None, type=None, strict=False): + return self.store.have_request(self._get_requests(), uid, recurrenceid, type, strict) def _get_request_summary(self):