1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imipweb/profile.py Sun Oct 25 01:25:29 2015 +0200
1.3 @@ -0,0 +1,112 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +A Web interface to the user profile.
1.8 +
1.9 +Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +from imiptools import config
1.26 +from imipweb.resource import ResourceClient
1.27 +
1.28 +class ProfilePage(ResourceClient):
1.29 +
1.30 + "A request handler for the user profile page."
1.31 +
1.32 + # See: imiptools.profile
1.33 +
1.34 + pref_labels = {
1.35 + "CN" : "Common name",
1.36 + "LANG" : "Language",
1.37 + "TZID" : "Time zone/regime",
1.38 + "add_method_response" : "Respond to messages adding events with...",
1.39 + "event_refreshing" : "Handle event refresh requests automatically",
1.40 + "freebusy_bundling" : "Bundle free/busy details with messages",
1.41 + "freebusy_messages" : "Notify about received free/busy messages",
1.42 + "freebusy_offers" : "Reserve time periods when making counter-proposals",
1.43 + "freebusy_publishing" : "Publish free/busy details via the Web",
1.44 + "freebusy_sharing" : "Share free/busy information at all",
1.45 + "incoming" : "Incoming calendar messages presented using...",
1.46 + "organiser_replacement" : "Recognise which kinds of participants as replacement organisers...",
1.47 + "participating" : "Participate in the calendar system at all?",
1.48 + "permitted_times" : None,
1.49 + }
1.50 +
1.51 + def handle_request(self):
1.52 + args = self.env.get_args()
1.53 + save = args.has_key("save")
1.54 + cancel = args.has_key("cancel")
1.55 + action = save or cancel
1.56 +
1.57 + if not action:
1.58 + return ["action"]
1.59 +
1.60 + return None
1.61 +
1.62 + # Output fragment methods.
1.63 +
1.64 + def show_preferences(self, errors=None):
1.65 + page = self.page
1.66 +
1.67 + # Show the range of preferences, getting all possible entries and using
1.68 + # configuration defaults.
1.69 +
1.70 + prefs = self.get_preferences()
1.71 + items = prefs.items(True, None, True)
1.72 + items.sort()
1.73 +
1.74 + page.table(class_="profile", cellspacing=5, cellpadding=5)
1.75 + page.thead()
1.76 + page.tr()
1.77 + page.th("Preferences", class_="mainheading", colspan=2)
1.78 + page.tr.close()
1.79 + page.thead.close()
1.80 + page.tbody()
1.81 +
1.82 + for name, value in items:
1.83 + label = self.pref_labels.get(name)
1.84 + if not label:
1.85 + continue
1.86 +
1.87 + page.tr()
1.88 + page.th(class_="profileheading %s%s" % (name, errors and name in errors and " error" or ""))
1.89 + page.label(label)
1.90 + page.th.close()
1.91 + page.td()
1.92 + page.input(name=name, value=(value or ""), type="text", class_="preference")
1.93 + page.td.close()
1.94 + page.tr.close()
1.95 +
1.96 + page.tbody.close()
1.97 + page.table.close()
1.98 +
1.99 + # Full page output methods.
1.100 +
1.101 + def show(self):
1.102 +
1.103 + "Show the preferences of a user."
1.104 +
1.105 + errors = self.handle_request()
1.106 +
1.107 + if not errors:
1.108 + return True
1.109 +
1.110 + self.new_page(title="Profile")
1.111 + self.show_preferences(errors)
1.112 +
1.113 + return True
1.114 +
1.115 +# vim: tabstop=4 expandtab shiftwidth=4