OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered by a BSD-style |
| 3 # license that can be found in the LICENSE file or at |
| 4 # https://developers.google.com/open-source/licenses/bsd |
| 5 |
| 6 """Classes for the user settings (preferences) page.""" |
| 7 |
| 8 import time |
| 9 import urllib |
| 10 |
| 11 from third_party import ezt |
| 12 |
| 13 from framework import framework_helpers |
| 14 from framework import permissions |
| 15 from framework import servlet |
| 16 from framework import template_helpers |
| 17 from framework import urls |
| 18 |
| 19 |
| 20 class UserSettings(servlet.Servlet): |
| 21 """Shows a page with a simple form to edit user preferences.""" |
| 22 |
| 23 _PAGE_TEMPLATE = 'sitewide/user-settings-page.ezt' |
| 24 |
| 25 def AssertBasePermission(self, mr): |
| 26 """Assert that the user has the permissions needed to view this page.""" |
| 27 super(UserSettings, self).AssertBasePermission(mr) |
| 28 |
| 29 if not mr.auth.user_id: |
| 30 raise permissions.PermissionException( |
| 31 'Anonymous users are not allowed to edit user settings') |
| 32 |
| 33 def GatherPageData(self, mr): |
| 34 """Build up a dictionary of data values to use when rendering the page.""" |
| 35 page_data = { |
| 36 'user_tab_mode': 'st3', |
| 37 'logged_in_user_pb': template_helpers.PBProxy(mr.auth.user_pb), |
| 38 # When on /hosting/settings, the logged-in user is the viewed user. |
| 39 'viewed_user': mr.auth.user_view, |
| 40 'offer_saved_queries_subtab': ezt.boolean(True), |
| 41 'viewing_self': ezt.boolean(True), |
| 42 } |
| 43 page_data.update( |
| 44 framework_helpers.UserSettings.GatherUnifiedSettingsPageData( |
| 45 mr.auth.user_id, mr.auth.user_view, mr.auth.user_pb)) |
| 46 return page_data |
| 47 |
| 48 def ProcessFormData(self, mr, post_data): |
| 49 """Process the posted form.""" |
| 50 framework_helpers.UserSettings.ProcessSettingsForm( |
| 51 mr.cnxn, self.services.user, post_data, |
| 52 mr.auth.user_id, mr.auth.user_pb) |
| 53 |
| 54 url = framework_helpers.FormatAbsoluteURL( |
| 55 mr, urls.USER_SETTINGS, include_project=False, |
| 56 saved=1, ts=int(time.time())) |
| 57 |
| 58 return url |
OLD | NEW |