file upload widget for user forms, email widget for user forms, possibility to

disable id-wsf usage even when available in lasso, fixed token when used in
conjunction with id-wsf, etc.
This commit is contained in:
Frédéric Péters 2005-07-30 23:12:31 +00:00
parent 35646e0a5a
commit 39031a973b
18 changed files with 258 additions and 92 deletions

View File

@ -36,7 +36,8 @@ div.biglist-item h3 {
}
div.biglist-item p {
margin: 3px;
margin: 0px;
font-size: 90%;
}
div.biglist-item span.data {
@ -45,7 +46,7 @@ div.biglist-item span.data {
}
div.biglist-item span.cmds {
font-size: 80%;
font-size: 90%;
display: block;
text-align: right;
}

View File

@ -8,12 +8,14 @@ div.content {
div.TextWidget textarea,
div.StringWidget input,
div.EmailWidget input,
div.PasswordWidget input {
border: 1px inset #ccc;
margin: 1px;
padding: 1px 2px;
}
div.EmailWidget input[readonly=readonly],
div.StringWidget input[readonly=readonly] {
border: 1px solid #ccc;
background: #eee;
@ -21,6 +23,7 @@ div.StringWidget input[readonly=readonly] {
div.TextWidget textarea:focus,
div.StringWidget input:focus,
div.EmailWidget input:focus,
div.PasswordWidget input:focus {
border: 2px solid #ccf;
margin: 0px;

View File

@ -117,7 +117,7 @@ class CategoriesDirectory(Directory):
category = storage.get_storage().retrieve('categories', k)
"""<div class="biglist-item">"""
"<h3>%s</h3>" % category.name
"""<span class="cmds"> [ """
"""<p><span class="cmds"> [ """
"""<a href="%s/edit">%s</a> - """ % (k, _('Edit'))
"""<a href="%s/delete">%s</a> """ % (k, _('Delete'))
"]</span></p></div>"

View File

@ -30,6 +30,7 @@ def get_categories():
question_types = [ ('string', _('Text (line)')),
('text', _('Text (block)')),
('email', _('Email Address')),
('bool', _('Check Box')),
('item', _('List')),
('file', _('File Upload')),
@ -188,7 +189,7 @@ class ConsultationFieldPage(Directory):
def delete [html] (self):
value = self.consultation.questions[self.question_no]
form = Form(enctype="multipart/form-data")
form.widgets.append(HtmlWidget("""<p>%s</p>""" % _(
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
"You are about to remove a question.")))
form.add_submit("submit", _("Submit"))
form.add_submit("cancel", _("Cancel"))
@ -196,7 +197,7 @@ class ConsultationFieldPage(Directory):
return redirect('../questions')
if not form.is_submitted() or form.has_errors():
html_top('consultations', title = _('Delete Field'))
"""<h2>%s %s</h2>""" % (_('Deleting Field:'), value['name'])
'<h2>%s %s</h2>' % (_('Deleting Field:'), value['name'])
form.render()
html_foot()
else:
@ -269,8 +270,8 @@ class ConsultationPage(Directory):
html_top('consultations', '%s - %s' % (_('Consultation'), self.consultation.name))
names = 'consultation-' + self.consultation.id
'<h2>%s</h2>' % self.consultation.name
"""<a href="csv">%s</a>""" % _('Export to CSV format')
"""<table id="listing"><thead><tr>"""
'<a href="csv">%s</a>' % _('Export to CSV format')
'<table id="listing"><thead><tr>'
for f in self.consultation.questions:
if f['answer'] in ('title', 'subtitle'):
continue
@ -320,7 +321,7 @@ class ConsultationPage(Directory):
else:
title = _('Edit Consultation')
html_top('consultations', title = title)
"""<h2>%s</h2>""" % title
'<h2>%s</h2>' % title
form.render()
html_foot()
else:
@ -334,7 +335,7 @@ class ConsultationPage(Directory):
def delete [html] (self):
form = Form(enctype="multipart/form-data")
form.widgets.append(HtmlWidget("""<p>%s</p>""" % _(
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
"You are about to irrevocably delete this consultation.")))
form.add_submit("submit", _("Submit"))
form.add_submit("cancel", _("Cancel"))
@ -342,7 +343,7 @@ class ConsultationPage(Directory):
return redirect('..')
if not form.is_submitted() or form.has_errors():
html_top('consultations', title = _('Delete Consultation'))
"""<h2>%s %s</h2>""" % (_('Deleting Consultation:'), self.consultation.name)
'<h2>%s %s</h2>' % (_('Deleting Consultation:'), self.consultation.name)
form.render()
html_foot()
else:
@ -379,18 +380,16 @@ class ConsultationsDirectory(Directory):
'<div class="biglist">'
for k in storage.get_storage().keys('consultations'):
consultation = storage.get_storage().retrieve('consultations', k)
"""<div class="biglist-item">"""
"<h3>%s</h3>" % consultation.name
"""<span class="data">
<span class="name">%s</span>
</span>""" % ellipsize(consultation.receiver, 50)
"""<span class="cmds"> [ """
"""<a href="%s/edit">%s</a> - """ % (k, _('Edit'))
"""<a href="%s/questions">%s</a> - """ % (k, _('Questions'))
"""<a href="%s/delete">%s</a> - """ % (k, _('Delete'))
"""<a href="%s/duplicate">%s</a> - """ % (k, _('Duplicate'))
"""<a href="%s/listing">%s</a> """ % (k, _('Listing'))
"]</span></p></div>"
'<div class="biglist-item">'
'<h3>%s</h3>' % consultation.name
'<p><span class="data">%s</span>' % ellipsize(consultation.receiver, 50)
'<span class="cmds"> [ '
'<a href="%s/edit">%s</a> - ' % (k, _('Edit'))
'<a href="%s/questions">%s</a> - ' % (k, _('Questions'))
'<a href="%s/delete">%s</a> - ' % (k, _('Delete'))
'<a href="%s/duplicate">%s</a> - ' % (k, _('Duplicate'))
'<a href="%s/listing">%s</a> ' % (k, _('Listing'))
']</span></p></div>'
'</div>'
html_foot()
@ -409,7 +408,7 @@ class ConsultationsDirectory(Directory):
if redo or not form.is_submitted() or form.has_errors():
html_top('consultations', title = _('New Consultation'))
"""<h2>%s</h2>""" % _('New Consultation')
'<h2>%s</h2>' % _('New Consultation')
form.render()
html_foot()
else:

View File

@ -30,6 +30,7 @@ def get_categories():
field_types = [ ('string', _('Text (line)')),
('text', _('Text (block)')),
('email', _('Email Address')),
('bool', _('Check Box')),
('item', _('List')),
('file', _('File Upload')),
@ -184,7 +185,7 @@ class FormDefFieldPage(Directory):
def delete [html] (self):
value = self.formdef.fields[self.field_no]
form = Form(enctype="multipart/form-data")
form.widgets.append(HtmlWidget("""<p>%s</p>""" % _(
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
"You are about to remove a field.")))
form.add_submit("submit", _("Submit"))
form.add_submit("cancel", _("Cancel"))
@ -192,7 +193,7 @@ class FormDefFieldPage(Directory):
return redirect('../fields')
if not form.is_submitted() or form.has_errors():
html_top('forms', title = _('Delete Field'))
"""<h2>%s %s</h2>""" % (_('Deleting Field:'), value['name'])
'<h2>%s %s</h2>' % (_('Deleting Field:'), value['name'])
form.render()
html_foot()
else:
@ -265,8 +266,8 @@ class FormDefPage(Directory):
html_top('forms', '%s - %s' % (_('Form'), self.formdef.name))
names = 'form-' + self.formdef.id
'<h2>%s</h2>' % self.formdef.name
"""<a href="csv">%s</a>""" % _('Export to CSV format')
"""<table id="listing"><thead><tr>"""
'<a href="csv">%s</a>' % _('Export to CSV format')
'<table id="listing"><thead><tr>'
for f in self.formdef.fields:
if f['type'] in ('title', 'subtitle'):
continue
@ -316,7 +317,7 @@ class FormDefPage(Directory):
else:
title = _('Edit Form')
html_top('forms', title = title)
"""<h2>%s</h2>""" % title
'<h2>%s</h2>' % title
form.render()
html_foot()
else:
@ -330,7 +331,7 @@ class FormDefPage(Directory):
def delete [html] (self):
form = Form(enctype="multipart/form-data")
form.widgets.append(HtmlWidget("""<p>%s</p>""" % _(
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
"You are about to irrevocably delete this form.")))
form.add_submit("submit", _("Submit"))
form.add_submit("cancel", _("Cancel"))
@ -338,7 +339,7 @@ class FormDefPage(Directory):
return redirect('..')
if not form.is_submitted() or form.has_errors():
html_top('forms', title = _('Delete Form'))
"""<h2>%s %s</h2>""" % (_('Deleting Form:'), self.formdef.name)
'<h2>%s %s</h2>' % (_('Deleting Form:'), self.formdef.name)
form.render()
html_foot()
else:
@ -375,18 +376,17 @@ class FormsDirectory(Directory):
'<div class="biglist">'
for k in storage.get_storage().keys('formdefs'):
formdef = storage.get_storage().retrieve('formdefs', k)
"""<div class="biglist-item">"""
'<div class="biglist-item">'
"<h3>%s</h3>" % formdef.name
"""<span class="data">
<span class="name">%s</span>
</span>""" % ellipsize(formdef.receiver, 50)
"""<span class="cmds"> [ """
"""<a href="%s/edit">%s</a> - """ % (k, _('Edit'))
"""<a href="%s/fields">%s</a> - """ % (k, _('Fields'))
"""<a href="%s/delete">%s</a> - """ % (k, _('Delete'))
"""<a href="%s/duplicate">%s</a> - """ % (k, _('Duplicate'))
"""<a href="%s/listing">%s</a> """ % (k, _('Listing'))
"]</span></p></div>"
'<p><span class="data">%s</span>' % ellipsize(
storage.get_storage().retrieve('roles', formdef.receiver).name, 50)
'<span class="cmds"> [ '
'<a href="%s/edit">%s</a> - ' % (k, _('Edit'))
'<a href="%s/fields">%s</a> - ' % (k, _('Fields'))
'<a href="%s/delete">%s</a> - ' % (k, _('Delete'))
'<a href="%s/duplicate">%s</a> - ' % (k, _('Duplicate'))
'<a href="%s/listing">%s</a> ' % (k, _('Listing'))
']</span></p></div>'
'</div>'
html_foot()
@ -405,7 +405,7 @@ class FormsDirectory(Directory):
if redo or not form.is_submitted() or form.has_errors():
html_top('forms', title = _('New Form'))
"""<h2>%s</h2>""" % _('New Form')
'<h2>%s</h2>' % _('New Form')
form.render()
html_foot()
else:

View File

@ -54,7 +54,9 @@ def html_top [html] (section, title = None):
title = ''
else:
title = ' - ' + title
return """<html xmlns="http://www.w3.org/1999/xhtml">
return """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>%s%s</title>
<link rel="stylesheet" type="text/css" href="/css/wcs-admin.css"/>

View File

@ -79,7 +79,7 @@ class RolePage(Directory):
if not form.is_submitted() or form.has_errors():
html_top('roles', title = _('Edit Role'))
"""<h2>%s</h2>""" % _('Edit Role')
'<h2>%s</h2>' % _('Edit Role')
form.render()
html_foot()
else:
@ -89,7 +89,7 @@ class RolePage(Directory):
def delete [html] (self):
form = Form(enctype="multipart/form-data")
form.widgets.append(HtmlWidget("""<p>%s</p>""" % _(
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
"You are about to irrevocably delete this role.")))
form.add_submit("submit", _("Submit"))
form.add_submit("cancel", _("Cancel"))
@ -97,7 +97,7 @@ class RolePage(Directory):
return redirect('..')
if not form.is_submitted() or form.has_errors():
html_top('roles', title = _('Delete Role'))
"""<h2>%s %s</h2>""" % (_('Deleting Role:'), self.role.name)
'<h2>%s %s</h2>' % (_('Deleting Role:'), self.role.name)
form.render()
html_foot()
else:
@ -126,11 +126,11 @@ class RolesDirectory(Directory):
'<div class="biglist">'
for k in storage.get_storage().keys('roles'):
role = storage.get_storage().retrieve('roles', k)
"""<div class="biglist-item">"""
'<div class="biglist-item">'
"<h3>%s</h3>" % role.name
"""<span class="cmds"> [ """
"""<a href="%s/edit">%s</a> - """ % (k, _('Edit'))
"""<a href="%s/delete">%s</a> """ % (k, _('Delete'))
'<p><span class="cmds"> [ '
'<a href="%s/edit">%s</a> - ' % (k, _('Edit'))
'<a href="%s/delete">%s</a> ' % (k, _('Delete'))
"]</span></p></div>"
'</div>'
html_foot()
@ -144,7 +144,7 @@ class RolesDirectory(Directory):
if not form.is_submitted() or form.has_errors():
html_top('roles', title = _('New Role'))
"""<h2>%s</h2>""" % _('New Role')
'<h2>%s</h2>' % _('New Role')
form.render()
html_foot()
else:

View File

@ -41,6 +41,7 @@ class RootDirectory(AccessControlled, Directory):
consultations = consultations.ConsultationsDirectory()
def _q_access(self):
return
session = get_session()
user = None

View File

@ -23,7 +23,7 @@ class LibertyIDPDir(Directory):
misc.reload_cfg()
html_top('settings', title = _('Identity Providers'))
"<h2>%s</h2>" % _('Identity Providers')
"""<ul id="nav-idp-admin"> <li><a href="new">%s</a></li> </ul>""" % _('New')
'<ul id="nav-idp-admin"> <li><a href="new">%s</a></li> </ul>' % _('New')
'<div class="biglist">'
for kidp, idp in misc.cfg.get('idp', {}).items():
@ -36,14 +36,14 @@ class LibertyIDPDir(Directory):
except TypeError:
continue
"""<div class="biglist-item">"""
"<h3>%s</h3>" % misc.get_provider_label(p)
'<div class="biglist-item">'
'<h3>%s</h3>' % misc.get_provider_label(p)
'<p><span class="data">%s</span>' % p.providerId
"""<span class="cmds">[ """
"""<a href="%s">%s</a> - """ % (kidp, _('View'))
"""<a href="%s/edit">%s</a> - """ % (kidp, _('Edit'))
"""<a href="%s/delete">%s</a> """ % (kidp, _('Delete'))
"""]</span></p></div>"""
'<span class="cmds">[ '
'<a href="%s">%s</a> - ' % (kidp, _('View'))
'<a href="%s/edit">%s</a> - ' % (kidp, _('Edit'))
'<a href="%s/delete">%s</a> ' % (kidp, _('Delete'))
']</span></p></div>'
'</div>'
html_foot()
@ -174,7 +174,7 @@ class LibertyIDPUI(Directory):
return redirect('..')
if not form.is_submitted() or form.has_errors():
html_top('settings', title = _('Identity Provider'))
"""<h2>%s %s</h2>""" % (_('Deleting'), p.providerId)
'<h2>%s %s</h2>' % (_('Deleting'), p.providerId)
form.render()
html_foot()
else:
@ -203,21 +203,20 @@ class SettingsDirectory(Directory):
html_top('settings', title = _('Settings'))
"""<h2>Liberty Alliance</h2>
<dl>"""
"""<dt><a href="liberty_sp">%s</a></dt> <dd>%s</dd>""" % (
'<dt><a href="liberty_sp">%s</a></dt> <dd>%s</dd>' % (
_('Service Provider'), _('Configure Liberty parameters'))
if misc.cfg.has_key(str('sp')):
"""<dt><a href="metadata.xml">%s</a></dt> <dd>%s</dd>""" % (
'<dt><a href="metadata.xml">%s</a></dt> <dd>%s</dd>' % (
_('Service Provider Metadata'), _('Download Service Provider Metadata file'))
"""<dt><a href="liberty_idp">%s</a></dt> <dd>%s</dd> </dl>""" % (
'<dt><a href="liberty_idp">%s</a></dt> <dd>%s</dd>' % (
_('Identity Providers'), _('Add and remove identity providers'))
"</dl>"
'</dl>'
'<h2>%s</h2>' % _('Misc')
'<dl>'
"""<dt><a href="themes">%s</a></dt> <dd>%s</dd>""" % (
'<dt><a href="themes">%s</a></dt> <dd>%s</dd>' % (
_('Theme'), _('Configure Theme'))
'<dt><a href="emails">%s</a></dt> <dd>%s</dd>' % (
_('Emails'), _('Configure email settings'))
@ -414,6 +413,13 @@ class SettingsDirectory(Directory):
form = Form(enctype="multipart/form-data")
form.add(CheckboxWidget, 'auto-id', title = _('Auto-id'),
value = misc_cfg.get('auto-id', False))
form.add(CheckboxWidget, 'grab-user-with-wsf',
title = _('Grab user details with ID-WSF on first logon'),
value = misc_cfg.get('grab-user-with-wsf', False))
if not lasso.WSF_SUPPORT:
widget = form.get_widget('grab-user-with-wsf')
widget.hint = _('Lasso version is too old for this support.')
widget.attrs[str('disabled')] = str('disabled')
form.add(RadiobuttonsWidget, 'features', title = _('Features'),
value = misc_cfg.get('features', 'both'),
options = [ (str('forms'), _('Forms')),
@ -436,7 +442,7 @@ class SettingsDirectory(Directory):
def misc_submit(self, form):
misc.reload_cfg()
misc_cfg = misc.cfg.get('misc', {})
for k in ('auto-id', 'features'):
for k in ('auto-id', 'features', 'grab-user-with-wsf'):
misc_cfg[k] = form.get_widget(k).parse()
misc.cfg['misc'] = misc_cfg
misc.write_cfg()

View File

@ -86,7 +86,7 @@ class UserPage(Directory):
if not form.is_submitted() or form.has_errors():
html_top('users', title = _('Edit User'))
"""<h2>%s</h2>""" % _('Edit User')
'<h2>%s</h2>' % _('Edit User')
form.render()
html_foot()
else:
@ -96,7 +96,7 @@ class UserPage(Directory):
def delete [html] (self):
form = Form(enctype="multipart/form-data")
form.widgets.append(HtmlWidget("""<p>%s</p>""" % _(
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
"You are about to irrevocably delete this user.")))
form.add_submit("submit", _("Submit"))
form.add_submit("cancel", _("Cancel"))
@ -104,7 +104,7 @@ class UserPage(Directory):
return redirect('..')
if not form.is_submitted() or form.has_errors():
html_top('users', title = _('Delete User'))
"""<h2>%s %s</h2>""" % (_('Deleting User:'), self.user.name)
'<h2>%s %s</h2>' % (_('Deleting User:'), self.user.name)
form.render()
html_foot()
else:
@ -174,14 +174,14 @@ class UsersDirectory(Directory):
'<div class="biglist">'
for user in users:
"""<div class="biglist-item">"""
'<div class="biglist-item">'
"<h3>%s</h3>" % user.name
"""<span class="cmds"> [ """
'<p><span class="cmds"> [ '
if not user.name_identifiers:
"""<a href="%s/token">%s</a> - """ % (user.id, _('Identification Token'))
"""<a href="%s/edit">%s</a> - """ % (user.id, _('Edit'))
"""<a href="%s/delete">%s</a> """ % (user.id, _('Delete'))
"]</span></p></div>"
'<a href="%s/token">%s</a> - ' % (user.id, _('Identification Token'))
'<a href="%s/edit">%s</a> - ' % (user.id, _('Edit'))
'<a href="%s/delete">%s</a> ' % (user.id, _('Delete'))
']</span></p></div>'
'</div>'
html_foot()
@ -197,7 +197,7 @@ class UsersDirectory(Directory):
if not form.is_submitted() or form.has_errors():
html_top('users', title = _('New User'))
"""<h2>%s</h2>""" % _('New User')
'<h2>%s</h2>' % _('New User')
form.render()
html_foot()
else:

View File

@ -8,6 +8,7 @@ from form import *
widget_classes = {
'string': StringWidget,
'email': EmailWidget,
'text': TextWidget,
'bool': CheckboxWidget,
'item': SingleSelectWidget,

View File

@ -1,9 +1,43 @@
import cStringIO
import os
import tempfile
from quixote import get_publisher, get_request, get_session
from quixote.http_request import Upload
from quixote.form import *
from quixote.html import htmltext
from quixote.html import htmltext, TemplateIO
from quixote.util import randbytes
QuixoteForm = Form
Widget.REQUIRED_ERROR = _('required field')
Widget.REQUIRED_ERROR = N_('required field')
get_error_orig = Widget.get_error
def get_i18n_error(self, request=None):
error = get_error_orig(self, request)
if error:
return _(error)
def render(self):
r = TemplateIO(html=True)
classnames = '%s widget' % self.__class__.__name__
if self.get_error():
classnames += ' widget-with-error'
r += htmltext('<div class="%s">') % classnames
r += self.render_title(self.get_title())
r += htmltext('<div class="content">')
r += self.render_content()
r += self.render_hint(self.get_hint())
r += self.render_error(self.get_error())
r += htmltext('</div>')
r += htmltext('</div>')
if self.render_br:
r += htmltext('<br class="%s" />') % classnames
r += htmltext('\n')
return r.getvalue()
Widget.get_error = get_i18n_error
Widget.render = render
class Form(QuixoteForm):
ERROR_NOTICE = htmltext('<div class="errornotice">%s</div>' % _(
@ -24,3 +58,91 @@ class HtmlWidget:
def render(self):
return self.string
def has_error(self, request):
return False
class FakeFileWidget(CompositeWidget):
"""Widget that proposes a File Upload widget but that stores the file
ondisk so it has a "readonly" mode where the filename is shown."""
def __init__(self, name, value=None, preview = False, **kwargs):
CompositeWidget.__init__(self, name, value, **kwargs)
self.value = value
if not preview:
del kwargs['title']
self.add(FileWidget, 'file', **kwargs)
else:
session = get_session()
self.add(HiddenWidget, 'token')
del kwargs['title']
self.add(StringWidget, 'filename', **kwargs)
if hasattr(get_request(), 'tempfiles'):
token = get_request().tempfiles[name]
wid = self.get_widget('token')
get_request().form[wid.name] = token
wid = self.get_widget('filename')
get_request().form[wid.name] = session.tempfiles[token]['orig_filename']
def render_content(self):
r = TemplateIO(html=True)
for widget in self.get_widgets():
r += widget.render()
return r.getvalue()
def _parse(self, request):
session = get_session()
if self.get('file'):
self.value = self.get('file')
self.value.__class__ = PicklableUpload
# and saves it
token = randbytes(8)
if not hasattr(get_request(), 'tempfiles'):
get_request().tempfiles = {}
get_request().tempfiles[self.name] = token
dirname = os.path.join(get_publisher().app_dir, 'tempfiles')
if not os.path.exists(dirname):
os.mkdir(dirname)
filename = os.path.join(dirname, token)
fd = open(filename, 'w')
upload = self.value
fd.write(upload.fp.read())
fd.close()
if not session.tempfiles:
session.tempfiles = {}
session.tempfiles[token] = {
'orig_filename': upload.orig_filename,
'base_filename': upload.base_filename,
'content_type': upload.content_type,
'charset': upload.charset
}
else:
token = self.get('token')
self.value = PicklableUpload(session.tempfiles[token]['orig_filename'],
session.tempfiles[token]['content_type'],
session.tempfiles[token]['charset'])
self.value.fp = tempfile.TemporaryFile()
dirname = os.path.join(get_publisher().app_dir, 'tempfiles')
filename = os.path.join(dirname, token)
self.value.fp.write(open(filename).read())
self.value.fp.seek(0)
class PicklableUpload(Upload):
def __getstate__(self):
odict = self.__dict__.copy()
del odict['fp']
odict['data'] = self.fp.read()
return odict
def __setstate__(self, dict):
self.__dict__.update(dict)
self.fp = cStringIO.StringIO(self.data)
del self.data
class EmailWidget(StringWidget):
def _parse(self, request):
StringWidget._parse(self, request)
if self.value is not None:
if not '@' in self.value: # ultra-basic, needs proper regex
self.error = N_("must be a valid email address")

View File

@ -1,6 +1,6 @@
import emails
from quixote import get_request
from quixote import get_request, get_session
import storage
@ -8,10 +8,11 @@ from form import *
widget_classes = {
'string': StringWidget,
'email': EmailWidget,
'text': TextWidget,
'bool': CheckboxWidget,
'item': SingleSelectWidget,
'file': FileWidget,
'file': FakeFileWidget,
}
widget_extra_attributes = {
@ -65,6 +66,7 @@ class FormDef(storage.Storable):
def create_view_form(self, dict = {}):
form = Form(enctype = "multipart/form-data")
session = get_session()
for i, field in enumerate(self.fields):
kwargs = {}
if field['type'] == 'title':
@ -78,8 +80,12 @@ class FormDef(storage.Storable):
continue
widget_class = widget_classes[field['type']]
value = dict.get(field['name'], '')
if field['type'] == 'item':
widget_class = StringWidget
if field['type'] == 'file':
kwargs['preview'] = True
if field['type'] == 'bool':
kwargs['disabled'] = 'disabled'
@ -88,8 +94,17 @@ class FormDef(storage.Storable):
v = field.get(k, None)
if v is not None:
kwargs[k] = v
widget_class = FakeFileWidget
#form.add_hidden("f%d" % i, value = value)
#token = form.get_widget('f%d' % i).parse()
#get_request().form['f%d-shown' % i] = session.temp_files[token]['orig_filename']
#form.add(widget_class, "f%d-shown" % i,
# title = field['name'], readonly = 'readonly', **kwargs)
#continue
form.add(widget_class, "f%d" % i, title = field['name'],
readonly = "readonly", value = dict.get(field['name'], ''), **kwargs)
readonly = "readonly", value = value, **kwargs)
return form
def get_data(self, form):

View File

@ -1,3 +1,4 @@
import os
import time
from quixote import get_request, get_response, get_session, redirect
@ -251,6 +252,7 @@ class FormPage(Directory):
if step == '1':
if form.get_widget('previous').parse():
return self._q_index()
form = self.formdef.create_view_form() # so it gets FakeFileWidget in preview mode
if not form.is_submitted() or form.has_errors():
return self._q_index()
if step == '0':

View File

@ -125,10 +125,7 @@ class RootDirectory(Directory):
if ni in user.name_identifiers:
break
else:
if lasso.WSF_SUPPORT and True:
# XXX: True must be replaced by a configuration option
# something like Identities/Grab identity details with ID-WSF
if lasso.WSF_SUPPORT and misc.cfg.get('misc', {}).get('grab-user-with-wsf', False):
# nameQualifier is not always idp provider id, I think.
assertion = login.session.getAssertions(login.nameIdentifier.nameQualifier)[0]
try:

View File

@ -62,16 +62,24 @@ class RootDirectory(Directory):
'</div>'
template.html_foot()
else:
session = get_session()
if session.lasso_anonymous_identity_dump:
lasso_dump = session.lasso_anonymous_identity_dump
elif session.user and not session.user.startswith('anonymous-'):
current_user = storage.get_storage().retrieve('users', session.user)
lasso_dump = current_user.lasso_dump
else:
return error_page("No Lasso Identity Dump (???)")
token = form.get_widget('token').parse()
for user in storage.get_storage().values('users'):
if user.identification_token == token:
user.identification_token = None
if not user.name_identifiers:
user.name_identifiers = []
user.name_identifiers.append(str(get_session().name_identifier))
user.lasso_dump = str(get_session().lasso_anonymous_identity_dump)
old_name = get_session().user
get_session().set_user(user.id)
user.name_identifiers.append(str(session.name_identifier))
user.lasso_dump = str(lasso_dump)
old_name = session.user
session.set_user(user.id)
storage.get_storage().store(user)
for formdef in storage.get_storage().values('formdefs'):
@ -80,6 +88,12 @@ class RootDirectory(Directory):
if filled.user_id == old_name:
filled.user_id = user.id
storage.get_storage().store(filled)
for consultationdef in storage.get_storage().values('consultations'):
consultationnames = "consultation-" + consultationdef.id
for filled in storage.get_storage().values(consultationnames):
if filled.user_id == old_name:
filled.user_id = user.id
storage.get_storage().store(filled)
break
return redirect('.')

View File

@ -10,10 +10,11 @@ class BasicSession(Session, storage.Storable):
anonymous_id = None
lasso_session_dump = None
lasso_anonymous_identity_dump = None
tempfiles = None
def has_info(self):
return self.name_identifier or self.after_url or self.anonymous_id or \
self.lasso_session_dump or \
self.tempfiles or self.lasso_session_dump or \
self.lasso_anonymous_identity_dump or Session.has_info(self)
is_dirty = has_info

View File

@ -12,7 +12,9 @@ def html_top [html] (title = None, onload = None, script = None):
page_title = '%s - %s' % (org_name, title)
else:
page_title = org_name
"""<html xmlns="http://www.w3.org/1999/xhtml">
"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>%s</title>
<link rel="stylesheet" type="text/css" href="%s"/>""" % (page_title, css)