1 #!/usr/bin/env python 2 3 """ 4 A Web interface to the user profile. 5 6 Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 from imiptools import config 23 from imipweb.resource import ResourceClient 24 25 class ProfilePage(ResourceClient): 26 27 "A request handler for the user profile page." 28 29 # See: imiptools.profile 30 31 pref_labels = { 32 "CN" : "Common name", 33 "LANG" : "Language", 34 "TZID" : "Time zone/regime", 35 "add_method_response" : "Respond to messages adding events with...", 36 "event_refreshing" : "Handle event refresh requests automatically", 37 "freebusy_bundling" : "Bundle free/busy details with messages", 38 "freebusy_messages" : "Notify about received free/busy messages", 39 "freebusy_offers" : "Reserve time periods when making counter-proposals", 40 "freebusy_publishing" : "Publish free/busy details via the Web", 41 "freebusy_sharing" : "Share free/busy information at all", 42 "incoming" : "Incoming calendar messages presented using...", 43 "organiser_replacement" : "Recognise which kinds of participants as replacement organisers...", 44 "participating" : "Participate in the calendar system at all?", 45 "permitted_times" : None, 46 } 47 48 def handle_request(self): 49 args = self.env.get_args() 50 save = args.has_key("save") 51 cancel = args.has_key("cancel") 52 action = save or cancel 53 54 if not action: 55 return ["action"] 56 57 return None 58 59 # Output fragment methods. 60 61 def show_preferences(self, errors=None): 62 page = self.page 63 64 # Show the range of preferences, getting all possible entries and using 65 # configuration defaults. 66 67 prefs = self.get_preferences() 68 items = prefs.items(True, None, True) 69 items.sort() 70 71 page.table(class_="profile", cellspacing=5, cellpadding=5) 72 page.thead() 73 page.tr() 74 page.th("Preferences", class_="mainheading", colspan=2) 75 page.tr.close() 76 page.thead.close() 77 page.tbody() 78 79 for name, value in items: 80 label = self.pref_labels.get(name) 81 if not label: 82 continue 83 84 page.tr() 85 page.th(class_="profileheading %s%s" % (name, errors and name in errors and " error" or "")) 86 page.label(label) 87 page.th.close() 88 page.td() 89 page.input(name=name, value=(value or ""), type="text", class_="preference") 90 page.td.close() 91 page.tr.close() 92 93 page.tbody.close() 94 page.table.close() 95 96 # Full page output methods. 97 98 def show(self): 99 100 "Show the preferences of a user." 101 102 errors = self.handle_request() 103 104 if not errors: 105 return True 106 107 self.new_page(title="Profile") 108 self.show_preferences(errors) 109 110 return True 111 112 # vim: tabstop=4 expandtab shiftwidth=4