admin: remove leftover schema configuration auto pages (#53995)
This commit is contained in:
parent
fd09a2f6de
commit
1565f3abe2
|
@ -298,6 +298,23 @@ def test_settings_export_import(pub):
|
|||
assert 'Unknown referenced role (qux)' in resp
|
||||
|
||||
|
||||
def test_settings_session(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/settings/session')
|
||||
assert resp.form['ip_linked'].checked is False
|
||||
resp.form['ip_linked'].checked = True
|
||||
resp = resp.form.submit('submit')
|
||||
pub.reload_cfg()
|
||||
assert pub.cfg['session']['ip_linked'] is True
|
||||
|
||||
resp = app.get('/backoffice/settings/session')
|
||||
assert resp.form['ip_linked'].checked is True
|
||||
resp.form['ip_linked'].checked = False
|
||||
resp = resp.form.submit('cancel')
|
||||
assert pub.cfg['session']['ip_linked'] is True
|
||||
|
||||
|
||||
def test_settings_themes(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
|
|
|
@ -20,7 +20,7 @@ from quixote.html import TemplateIO, htmltext
|
|||
|
||||
from wcs.qommon import get_cfg
|
||||
|
||||
from .. import N_, _
|
||||
from .. import _
|
||||
from ..admin.cfg import cfg_submit
|
||||
from ..backoffice.menu import html_top
|
||||
from ..form import CheckboxWidget, Form, SingleSelectWidget, StringWidget
|
||||
|
@ -30,49 +30,31 @@ class SettingsDirectory(AccessControlled, Directory):
|
|||
def _q_access(self):
|
||||
get_response().breadcrumb.append(('settings/', _('Settings')))
|
||||
|
||||
def schema_to_form(self, schema):
|
||||
def session(self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
cfg = get_cfg(schema['name'], {})
|
||||
for option_name in schema['options']:
|
||||
option = schema['options'][option_name]
|
||||
if option['type'] == 'boolean':
|
||||
form.add(
|
||||
CheckboxWidget,
|
||||
option_name,
|
||||
title=_(option.get('title')),
|
||||
value=cfg.get(option_name, option.get('default', False)),
|
||||
)
|
||||
session_cfg = get_cfg('session', {})
|
||||
form.add(
|
||||
CheckboxWidget,
|
||||
'ip_linked',
|
||||
title=_('Fix sessions to an IP address'),
|
||||
value=session_cfg.get('ip_linked'),
|
||||
)
|
||||
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
return form
|
||||
|
||||
def config_page_from_schema(self, schema):
|
||||
title = _(schema['title'])
|
||||
name = schema['name']
|
||||
form = self.schema_to_form(schema)
|
||||
if form.get_widget('cancel').parse():
|
||||
return redirect('.')
|
||||
|
||||
if not form.is_submitted() or form.has_errors():
|
||||
html_top('settings', title=title)
|
||||
get_response().breadcrumb.append(('session', _('Session')))
|
||||
html_top('settings', title=_('Session'))
|
||||
r = TemplateIO(html=True)
|
||||
r += htmltext('<h2>%s</h2>') % title
|
||||
r += htmltext('<h2>%s</h2>') % _('Session')
|
||||
r += form.render()
|
||||
return r.getvalue()
|
||||
else:
|
||||
cfg_submit(form, name, schema['options'].keys())
|
||||
return redirect('')
|
||||
|
||||
session_cfg_schema = {
|
||||
'name': 'session',
|
||||
'title': N_('Session'),
|
||||
'options': {
|
||||
'ip_linked': {'type': 'boolean', 'default': False, 'title': N_('Fix sessions to an IP address')},
|
||||
},
|
||||
}
|
||||
|
||||
def session(self):
|
||||
get_response().breadcrumb.append(('session', _('Session')))
|
||||
return self.config_page_from_schema(self.session_cfg_schema)
|
||||
cfg_submit(form, 'session', ['ip_linked'])
|
||||
return redirect('.')
|
||||
|
||||
def language(self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
|
|
Loading…
Reference in New Issue