1.1 --- a/imip_manager.py Tue Jan 13 23:37:56 2015 +0100
1.2 +++ b/imip_manager.py Wed Jan 14 00:49:25 2015 +0100
1.3 @@ -31,7 +31,7 @@
1.4
1.5 from imiptools.content import Handler, get_address, \
1.6 get_item, get_uri, get_utc_datetime, get_value, \
1.7 - get_values, parse_object, to_part
1.8 + get_value_map, get_values, parse_object, to_part
1.9 from imiptools.dates import format_datetime, get_datetime, get_start_of_day, \
1.10 to_timezone
1.11 from imiptools.mail import Messenger
1.12 @@ -126,12 +126,15 @@
1.13
1.14 # Action methods.
1.15
1.16 - def process_request(self, accept):
1.17 + def process_request(self, accept, update=False):
1.18
1.19 """
1.20 Process the current request for the given 'user', accepting any request
1.21 when 'accept' is true, declining requests otherwise. Return whether any
1.22 action was taken.
1.23 +
1.24 + If 'update' is given, the sequence number will be incremented in order
1.25 + to override any previous response.
1.26 """
1.27
1.28 # When accepting or declining, do so only on behalf of this user,
1.29 @@ -146,6 +149,10 @@
1.30 if self.messenger and self.messenger.sender != get_address(attendee):
1.31 attendee_attr["SENT-BY"] = get_uri(self.messenger.sender)
1.32 self.details["ATTENDEE"] = [(attendee, attendee_attr)]
1.33 + if update:
1.34 + sequence = self.get_value("SEQUENCE") or "0"
1.35 + self.details["SEQUENCE"] = [(str(int(sequence) + 1), {})]
1.36 +
1.37 self.send_message(get_address(attendee))
1.38
1.39 return True
1.40 @@ -260,9 +267,12 @@
1.41
1.42 # Request logic and page fragment methods.
1.43
1.44 - def handle_request(self, uid, request):
1.45 + def handle_request(self, uid, request, queued):
1.46
1.47 - "Handle actions involving the given 'uid' and 'request' object."
1.48 + """
1.49 + Handle actions involving the given 'uid' and 'request' object, where
1.50 + 'queued' indicates that the object has not yet been handled.
1.51 + """
1.52
1.53 # Handle a submitted form.
1.54
1.55 @@ -271,12 +281,13 @@
1.56
1.57 accept = args.has_key("accept")
1.58 decline = args.has_key("decline")
1.59 + update = not queued and args.has_key("update")
1.60
1.61 if accept or decline:
1.62
1.63 handler = ManagerHandler(request, self.user, self.messenger)
1.64
1.65 - if handler.process_request(accept):
1.66 + if handler.process_request(accept, update):
1.67
1.68 # Remove the request from the list.
1.69
1.70 @@ -296,11 +307,32 @@
1.71
1.72 return handled
1.73
1.74 - def show_request_form(self):
1.75 + def show_request_form(self, obj, needs_action):
1.76 +
1.77 + """
1.78 + Show a form for a request concerning 'obj', indicating whether action is
1.79 + needed if 'needs_action' is specified as a true value.
1.80 + """
1.81 +
1.82 + details = self._get_details(obj)
1.83 +
1.84 + attendees = get_value_map(details, "ATTENDEE")
1.85 + attendee_attr = attendees.get(self.user)
1.86
1.87 - "Show a form for a request."
1.88 + if attendee_attr:
1.89 + partstat = attendee_attr.get("PARTSTAT")
1.90 + if partstat == "ACCEPTED":
1.91 + self.page.p("This request has been accepted.")
1.92 + elif partstat == "DECLINED":
1.93 + self.page.p("This request has been declined.")
1.94 + else:
1.95 + self.page.p("This request has been ignored.")
1.96
1.97 - self.page.p("Action to take for this request:")
1.98 + if needs_action:
1.99 + self.page.p("An action is required for this request:")
1.100 + else:
1.101 + self.page.p("This request can be updated as follows:")
1.102 +
1.103 self.page.form(method="POST")
1.104 self.page.p()
1.105 self.page.input(name="accept", type="submit", value="Accept")
1.106 @@ -308,6 +340,8 @@
1.107 self.page.input(name="decline", type="submit", value="Decline")
1.108 self.page.add(" ")
1.109 self.page.input(name="ignore", type="submit", value="Ignore")
1.110 + if not needs_action:
1.111 + self.page.input(name="update", type="hidden", value="true")
1.112 self.page.p.close()
1.113 self.page.form.close()
1.114
1.115 @@ -413,7 +447,7 @@
1.116 return False
1.117
1.118 is_request = uid in self._get_requests()
1.119 - handled = is_request and self.handle_request(uid, obj)
1.120 + handled = self.handle_request(uid, obj, is_request)
1.121
1.122 if handled:
1.123 return True
1.124 @@ -422,8 +456,7 @@
1.125
1.126 self.show_object_on_page(uid, obj)
1.127
1.128 - if is_request and not handled:
1.129 - self.show_request_form()
1.130 + self.show_request_form(obj, is_request and not handled)
1.131
1.132 return True
1.133