This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
glasnost/shared/web/PreferencesWeb.py

176 lines
6.1 KiB
Python

# -*- coding: iso-8859-15 -*-
# Glasnost
# By: Odile Bénassy <obenassy@entrouvert.com>
# Romain Chantereau <rchantereau@entrouvert.com>
# Nicolas Clapiès <nclapies@easter-eggs.org>
# Pierre-Antoine Dejace <padejace@entrouvert.be>
# Thierry Dulieu <tdulieu@easter-eggs.com>
# Florent Monnier <monnier@codelutin.com>
# Cédric Musso <cmusso@easter-eggs.org>
# Frédéric Péters <fpeters@entrouvert.be>
# Benjamin Poussin <poussin@codelutin.com>
# Emmanuel Raviart <eraviart@entrouvert.com>
# Sébastien Régnier <regnier@codelutin.com>
# Emmanuel Saracco <esaracco@easter-eggs.com>
#
# Copyright (C) 2000, 2001 Easter-eggs & Emmanuel Raviart
# Copyright (C) 2002 Odile Bénassy, Code Lutin, Thierry Dulieu, Easter-eggs,
# Entr'ouvert, Frédéric Péters, Benjamin Poussin, Emmanuel Raviart,
# Emmanuel Saracco & Théridion
# Copyright (C) 2003 Odile Bénassy, Romain Chantereau, Nicolas Clapiès,
# Code Lutin, Pierre-Antoine Dejace, Thierry Dulieu, Easter-eggs,
# Entr'ouvert, Florent Monnier, Cédric Musso, Ouvaton, Frédéric Péters,
# Benjamin Poussin, Rodolphe Quiédeville, Emmanuel Raviart, Sébastien
# Régnier, Emmanuel Saracco, Théridion & Vecam
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
__doc__ = """Glasnost Preferences Web"""
__version__ = '$Revision$'[11:-2]
import glasnost.common.context as context
import glasnost.common.faults as faults
from glasnost.common.ObjectsCommon import *
import glasnost.common.slots as slots
import glasnost.common.translation as translation
import glasnost.common.tools_new as commonTools
from glasnost.proxy.PreferencesProxy import *
try:
import accounting
except ImportError:
class FakeAccountingModule:
currencyLabels = { 'eur': 'Euro' }
accounting = FakeAccountingModule()
from ObjectsWeb import register, ObjectWebMixin, WebMixin
from tools import *
class Preference(ObjectWebMixin, Preference):
cryptEmails_kind_defaultValue = 1
cryptEmails_kind_widget_fieldLabel = N_('Crypt Emails')
cryptEmails_kind_widget_labels = {
'0': N_('Never'),
'1': N_('When Possible'),
}
cryptEmails_kind_widgetName = 'InputCheckBox'
currency_kind_defaultValue = 'eur'
currency_kind_widget_fieldLabel = N_('Currency')
currency_kind_widget_labels = accounting.currencyLabels
currency_kind_widgetName = 'Select'
spellcheckEntries_kind_defaultValue = 1
spellcheckEntries_kind_widget_fieldLabel = N_('Spellcheck Entries')
spellcheckEntries_kind_widget_labels = {
'0': N_('No'),
'1': N_('Yes'),
}
spellcheckEntries_kind_widgetName = 'InputCheckBox'
def newWidget(self, parentSlot = None):
return commonTools.newThing('widget', 'Thing')
register(Preference)
class PreferencesWeb(WebMixin, PreferencesProxy):
def edit(self):
userToken = context.getVar('userToken', default = '')
if not userToken:
return accessForbidden()
preference = self.getPreference()
return self.editObject(preference)
edit.isPublicForWeb = 1
def editObject(self, preference):
headerTitle = _('Editing Preferences')
context.push(_level = 'edit', layoutMode = 'edit')
try:
layout = X.array()
if context.getVar('error'):
layout += preference.getErrorLayout()
form = X.form(action = X.actionUrl('submit'),
enctype= 'multipart/form-data', method = 'post')
layout += form
slot = slots.Root(preference)
widget = slot.getWidget()
form += widget.getModelPageBodyLayout(slot, None)
buttonsBar = X.div(_class = 'buttons-bar')
form += buttonsBar
actionButtonsBar = X.span(_class = 'action-buttons-bar')
buttonsBar += actionButtonsBar
actionButtonsBar += X.buttonInForm('modify', 'modifyButton')
return writePageLayout(layout, headerTitle)
finally:
context.pull(_level = 'edit')
def submit(self, **keywords):
if keywords is None:
keywords = {}
if isButtonSelected('applyButton', keywords):
context.setVar('again', 1)
context.setVar('hideErrors', 1)
preference = Preference()
preference.submitFields(keywords)
if context.getVar('again'):
return self.editObject(preference)
try:
self.setPreference(preference)
except faults.WrongVersion:
context.setVar('again', 1)
context.setVar('error', 1)
preference.setError('version', 1)
return self.editObject(preference)
except:
if context.getVar('debug'):
raise
return accessForbidden()
return redirect(X.actionUrl())
submit.isPublicForWeb = 1
def viewAll(self):
userToken = context.getVar('userToken', default = '')
if not userToken:
return accessForbidden()
preference = self.getPreference()
layout = X.array()
slot = slots.Root(preference)
widget = slot.getWidget()
layout += widget.getModelPageBodyLayout(slot, None)
buttonsBar = X.div(_class = 'buttons-bar')
layout += buttonsBar
actionButtonsBar = X.span(_class = 'action-buttons-bar')
buttonsBar += actionButtonsBar
actionButtonsBar += X.buttonStandalone('edit', X.actionUrl('edit'))
return writePageLayout(layout, _('Preferences'))
viewAll.isPublicForWeb = 1