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