1.1 --- a/imip_manager.py Sun Oct 26 00:45:58 2014 +0200
1.2 +++ b/imip_manager.py Sun Oct 26 17:51:04 2014 +0100
1.3 @@ -4,6 +4,7 @@
1.4
1.5 sys.path.append("/var/lib/imip-agent")
1.6
1.7 +from imiptools.content import get_values, parse_object
1.8 import markup
1.9 import imip_store
1.10
1.11 @@ -80,6 +81,11 @@
1.12 self.new_page(title="Forbidden")
1.13 self.page.p("You are not logged in and thus cannot access scheduling requests.")
1.14
1.15 + def no_page(self):
1.16 + self.status(404, "Not Found")
1.17 + self.new_page(title="Not Found")
1.18 + self.page.p("No page is provided at the given address.")
1.19 +
1.20 def show_requests(self):
1.21
1.22 "Show requests for the current user."
1.23 @@ -91,6 +97,7 @@
1.24 self.page.ul()
1.25
1.26 requests = self.store.get_requests(self.user)
1.27 +
1.28 for request in requests:
1.29 self.page.li()
1.30 self.page.a(request, href="%s/%s" % (self.env.get_url(), request))
1.31 @@ -98,6 +105,33 @@
1.32
1.33 self.page.ul.close()
1.34
1.35 + def show_request(self, path_info):
1.36 +
1.37 + "Show a request using the given 'path_info' for the current user."
1.38 +
1.39 + uid = path_info.lstrip("/").split("/", 1)[0]
1.40 + f = uid and self.store.get_event(self.user, uid) or None
1.41 +
1.42 + if not f:
1.43 + return False
1.44 +
1.45 + request = parse_object(f, "utf-8")
1.46 +
1.47 + if not request:
1.48 + return False
1.49 +
1.50 + self.new_page(title="Request")
1.51 + self.page.p("The following request was received:")
1.52 + self.page.dl()
1.53 +
1.54 + for name in ["DTSTART", "DTEND", "ORGANIZER", "ATTENDEE"]:
1.55 + for value in get_values(request, name):
1.56 + self.page.dt(name)
1.57 + self.page.dd(value)
1.58 +
1.59 + self.page.dl.close()
1.60 + return True
1.61 +
1.62 def select_action(self):
1.63
1.64 "Select the desired action and show the result."
1.65 @@ -105,6 +139,10 @@
1.66 path_info = self.env.get_path_info().rstrip("/")
1.67 if not path_info:
1.68 self.show_requests()
1.69 + elif self.show_request(path_info):
1.70 + pass
1.71 + else:
1.72 + self.no_page()
1.73
1.74 def show(self):
1.75
1.76 @@ -115,6 +153,8 @@
1.77 else:
1.78 self.select_action()
1.79
1.80 + # Write the headers and actual content.
1.81 +
1.82 print >>self.out, "Content-Type: text/html; charset=%s" % self.encoding
1.83 print >>self.out
1.84 self.out.write(unicode(self.page).encode(self.encoding))