convert .ptl to .py files

This commit is contained in:
Frédéric Péters 2015-01-08 20:04:42 +01:00
parent 4747ab0f5f
commit fda091677f
7 changed files with 537 additions and 447 deletions

View File

@ -16,6 +16,7 @@
from quixote import get_publisher, get_request, get_response, get_session, redirect
from quixote.directory import Directory, AccessControlled
from quixote.html import TemplateIO, htmltext
from qommon import errors
from qommon.admin.texts import TextsDirectory
@ -32,7 +33,7 @@ from boconfig import ConfigDirectory
import quota
def generate_user_info [html] ():
def generate_user_info():
# same as backoffice.menu.generate_user_info, without the admin link, but
# with a configuration link
if not get_request().user:
@ -47,15 +48,18 @@ def generate_user_info [html] ():
logout_url = get_publisher().get_root_url() + 'logout'
config_url = get_publisher().get_root_url() + 'backoffice/config/'
'<ul class="user-info">'
'<li class="ui-name">%s</li>' % username
'<li class="ui-logout"><a href="%s">%s</a></li>' % (logout_url, _('logout'))
r = TemplateIO(html=True)
r += htmltext('<ul class="user-info">')
r += htmltext('<li class="ui-name">%s</li>') % username
r += htmltext('<li class="ui-logout"><a href="%s">%s</a></li>') % (logout_url, _('logout'))
if get_publisher().backoffice_help_url and \
get_request().language in get_publisher().backoffice_help_url:
help_url = get_publisher().backoffice_help_url[get_request().language]
'<li class="ui-help"><a href="%s">%s</a></li>' % (help_url, _('help'))
'</ul>'
r += htmltext('<li class="ui-help"><a href="%s">%s</a></li>') % (help_url, _('help'))
r += htmltext('</ul>')
return r.getvalue()
qommon.backoffice.menu.generate_user_info = generate_user_info
@ -120,64 +124,67 @@ class RootDirectory(AccessControlled, Directory):
self.create_asec_objects()
def _q_index [html] (self):
def _q_index(self):
get_response().breadcrumb = [ ('backoffice/', _('Back Office of your site')) ]
html_top('', _('Questionnaires'))
r = TemplateIO(html=True)
if quota.is_expired():
TextsDirectory.get_html_text('asec-expired-site-backoffice')
r += TextsDirectory.get_html_text('asec-expired-site-backoffice')
formdefs = FormDef.select(order_by='name', ignore_errors=True)
if formdefs:
'<h2>%s</h2>' % _('Existing Questionnaires')
r += htmltext('<h2>%s</h2>') % _('Existing Questionnaires')
'<ul class="biglist" id="all-forms">'
r += htmltext('<ul class="biglist" id="all-forms">')
for formdef in formdefs:
if formdef.disabled:
'<li class="disabled">'
r += htmltext('<li class="disabled">')
else:
'<li>'
'<strong class="label"><a href="forms/%s/">%s</a></strong>' % (formdef.id, formdef.name)
'</li>'
'</ul>'
r += htmltext('<li>')
r += htmltext('<strong class="label"><a href="forms/%s/">%s</a></strong>') % (formdef.id, formdef.name)
r += htmltext('</li>')
r += htmltext('</ul>')
if quota.may_add_a_new_form():
'<h2>%s</h2>' % _('New Questionnaire')
r += htmltext('<h2>%s</h2>') % _('New Questionnaire')
form = Form(enctype='multipart/form-data', action='new')
form.add(StringWidget, 'name', title=_('Title'), size=40, required=True)
form.add_submit('submit', _('Create New Questionnaire'))
form.render()
r += form.render()
get_response().filter['sidebar'] = self.get_sidebar()
return r.getvalue()
def get_sidebar [html] (self):
def get_sidebar(self):
# manually add those scripts, as the sidebar is not parsed when looking
# for popup links
get_response().add_javascript(['jquery.js', 'simplemodal/jquery.simplemodal.js', 'popup.js'])
'<div class="bo-block">'
'<h3>%s</h3>' % _('Your Profile')
r = TemplateIO(html=True)
r += htmltext('<div class="bo-block">')
r += htmltext('<h3>%s</h3>') % _('Your Profile')
# TODO: possiblity to create additional administrator accounts?
'<ul>'
' <li><a href="config/contact" rel="popup">%s</a></li>' % _('Contact Information')
' <li><a href="config/password" rel="popup">%s</a></li>' % _('Password Change')
'</ul>'
'</div>'
r += htmltext('<ul>')
r += htmltext(' <li><a href="config/contact" rel="popup">%s</a></li>') % _('Contact Information')
r += htmltext(' <li><a href="config/password" rel="popup">%s</a></li>') % _('Password Change')
r += htmltext('</ul>')
r += htmltext('</div>')
'<div class="bo-block">'
'<h3>%s</h3>' % _('Site Settings')
r += htmltext('<div class="bo-block">')
r += htmltext('<h3>%s</h3>') % _('Site Settings')
'<ul>'
' <li><a href="config/sitetitle" rel="popup">%s</a></li>' % _('Title')
' <li><a href="config/homepage">%s</a></li>' % _('Welcome Text')
' <li><a href="config/texts/asec-recorded-vote">%s</a></li>' % _('End Text')
r += htmltext('<ul>')
r += htmltext(' <li><a href="config/sitetitle" rel="popup">%s</a></li>') % _('Title')
r += htmltext(' <li><a href="config/homepage">%s</a></li>') % _('Welcome Text')
r += htmltext(' <li><a href="config/texts/asec-recorded-vote">%s</a></li>') % _('End Text')
if quota.can_logo() or quota.can_theme():
' <li><a href="config/appearance">%s</a></li>' % _('Appearance')
'</ul>'
'</div>'
r += htmltext(' <li><a href="config/appearance">%s</a></li>') % _('Appearance')
r += htmltext('</ul>')
r += htmltext('</div>')
return r.getvalue()
def new(self):
if not quota.may_add_a_new_form():

View File

@ -18,6 +18,7 @@ import imghdr
from quixote import get_request, get_response, get_session, redirect
from quixote.directory import Directory
from quixote.html import TemplateIO, htmltext
from qommon import misc, get_cfg, get_logger
from qommon.admin.cfg import cfg_submit
@ -57,11 +58,12 @@ class ConfigDirectory(Directory):
del self.texts.texts_dict[k]
return Directory._q_traverse(self, path)
def _q_index [html] (self):
def _q_index(self):
return redirect('..')
def contact [html] (self):
def contact(self):
get_response().breadcrumb.append( ('contact', _('Contact Information')) )
r = TemplateIO(html=True)
form = Form(enctype='multipart/form-data')
user = get_request().user
@ -82,8 +84,9 @@ class ConfigDirectory(Directory):
return redirect('.')
html_top('config', _('Contact Information'))
'<h2>%s</h2>' % _('Contact Information')
form.render()
r += htmltext('<h2>%s</h2>') % _('Contact Information')
r += form.render()
return r.getvalue()
def contact_submit(self, form):
user = get_request().user
@ -93,7 +96,7 @@ class ConfigDirectory(Directory):
setattr(user, f, widget.parse())
user.store()
def password [html] (self):
def password(self):
get_response().breadcrumb.append( ('password', _('Password Change')) )
ident_method = get_cfg('identification', {}).get('methods', ['idp'])[0]
if ident_method != 'password':
@ -134,10 +137,12 @@ class ConfigDirectory(Directory):
return redirect('.')
html_top('config', _('Password Change'))
'<h2>%s</h2>' % _('Password Change')
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Password Change')
r += form.render()
return r.getvalue()
def sitetitle [html] (self):
def sitetitle(self):
get_response().breadcrumb.append( ('sitetitle', _('Site Title')) )
misc_cfg = get_cfg('misc', {})
@ -152,13 +157,15 @@ class ConfigDirectory(Directory):
if not form.is_submitted() or form.has_errors():
html_top('config', title = _('Site Title'))
'<h2>%s</h2>' % _('Site Title')
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Site Title')
r += form.render()
return r.getvalue()
else:
cfg_submit(form, 'misc', ['sitename'])
redirect('.')
def homepage [html] (self):
def homepage(self):
get_response().breadcrumb.append( ('homepage', _('Home Page Text')) )
texts_cfg = get_cfg('texts', {})
@ -175,8 +182,10 @@ class ConfigDirectory(Directory):
if not form.is_submitted() or form.has_errors():
html_top('config', title = _('Home Page Text'))
'<h2>%s</h2>' % _('Home Page Text')
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Home Page Text')
r += form.render()
return r.getvalue()
else:
texts_cfg[str('text-welcome-unlogged')] = form.get_widget('welcome-unlogged').parse()
texts_cfg[str('text-welcome-logged')] = form.get_widget('welcome-logged').parse()
@ -184,18 +193,21 @@ class ConfigDirectory(Directory):
get_publisher().write_cfg()
redirect('.')
def appearance [html] (self):
def appearance(self):
get_response().breadcrumb.append(('appearance', _('Appearance')))
html_top('config', title = _('Appearance'))
r = TemplateIO(html=True)
if quota.can_theme():
"<h2>%s</h2>" % _('Appearance')
self.appearance_theme()
r += htmltext("<h2>%s</h2>") % _('Appearance')
r += self.appearance_theme()
if quota.can_logo():
self.appearance_logo()
r += self.appearance_logo()
def appearance_theme [html] (self):
return r.getvalue()
def appearance_theme(self):
request = get_request()
if request.form.has_key('theme'):
themes = qommon.template.get_themes()
@ -207,11 +219,12 @@ class ConfigDirectory(Directory):
current_theme = get_cfg('branding', {}).get('theme', 'default')
'<div class="themes">'
r = TemplateIO(html=True)
r += htmltext('<div class="themes">')
'<p>'
_('Click on a thumbnail to change the appearance of your site.')
'</p>'
r += htmltext('<p>')
r += _('Click on a thumbnail to change the appearance of your site.')
r += htmltext('</p>')
themes = qommon.template.get_themes()
for theme, (label, desc, author, icon) in sorted(themes.items()):
@ -222,34 +235,35 @@ class ConfigDirectory(Directory):
active = ' active'
else:
active = ''
'<div class="theme%s">' % active
'<a href="appearance?theme=%s">' % theme
'<img src="/themes/%s/icon.png" alt="" class="theme-icon" />' % theme
'</a>'
'</div>'
'<hr class="clear" />'
'</div>'
r += htmltext('<div class="theme%s">') % active
r += htmltext('<a href="appearance?theme=%s">') % theme
r += htmltext('<img src="/themes/%s/icon.png" alt="" class="theme-icon" />') % theme
r += htmltext('</a>')
r += htmltext('</div>')
r += htmltext('<hr class="clear" />')
r += htmltext('</div>')
return r.getvalue()
def appearance_logo [html] (self):
'<div id="logo-selection">'
'<h2>%s</h2>' % _('Logo')
get_session().display_message()
def appearance_logo(self):
r = TemplateIO(html=True)
r += htmltext('<div id="logo-selection">')
r += htmltext('<h2>%s</h2>') % _('Logo')
r += get_session().display_message()
logo_url = get_logo_url()
if logo_url:
'<img src="%s" />' % logo_url
r += htmltext('<img src="%s" />') % logo_url
'<form action="logo" enctype="multipart/form-data" method="post">'
'<input type="file" name="file" />'
r += htmltext('<form action="logo" enctype="multipart/form-data" method="post">')
r += htmltext('<input type="file" name="file" />')
if logo_url:
'<input type="submit" name="submit" value="%s" />' % _('Upload New Logo')
'<input type="submit" name="remove" value="%s" />' % _('Remove Current Logo')
r += htmltext('<input type="submit" name="submit" value="%s" />') % _('Upload New Logo')
r += htmltext('<input type="submit" name="remove" value="%s" />') % _('Remove Current Logo')
else:
'<input type="submit" name="submit" value="%s" />' % _('Upload Logo')
'</form>'
'</div>'
r += htmltext('<input type="submit" name="submit" value="%s" />') % _('Upload Logo')
r += htmltext('</form>')
r += htmltext('</div>')
return r.getvalue()
def logo(self):
if not quota.can_logo():

View File

@ -21,7 +21,7 @@ from sets import Set
from quixote import get_publisher, get_request, get_response, get_session, redirect
from quixote.directory import Directory
from quixote.html import htmltext
from quixote.html import TemplateIO, htmltext
from qommon.backoffice.menu import html_top
from qommon.admin.emails import EmailsDirectory
@ -208,7 +208,7 @@ class DiffusionDirectory(Directory):
self.objectdef.store()
return redirect('.')
def emailfrom [html] (self):
def emailfrom(self):
emails_cfg = get_cfg('emails', {})
form = Form(enctype='multipart/form-data')
form.add(EmailWidget, 'from', title=_('Sender Address'),
@ -222,13 +222,15 @@ class DiffusionDirectory(Directory):
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append( ('emailfrom', _('Sender Address')) )
html_top('config', title = _('Sender Address'))
'<h2>%s</h2>' % _('Sender Address')
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Sender Address')
r += form.render()
return r.getvalue()
else:
cfg_submit(form, 'emails', ['from'])
redirect('.')
def emailnotify [html] (self):
def emailnotify(self):
emails_cfg = get_cfg('emails', {})
form = Form(enctype='multipart/form-data')
@ -247,8 +249,10 @@ class DiffusionDirectory(Directory):
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append( ('emailfrom', _('Sender Address')) )
html_top('config', title = _('Sender Address'))
'<h2>%s</h2>' % _('Sender Address')
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Sender Address')
r += form.render()
return r.getvalue()
else:
v = form.get_widget('notify').parse()
if v:
@ -273,77 +277,80 @@ class DiffusionDirectory(Directory):
def html_top(self, section, *args, **kwargs):
html_top('forms/%s/diffusion' % self.objectdef.id, *args, **kwargs)
def _q_index [html] (self):
def _q_index (self):
# XXX: it would be nice to be manage groups, to select an existing group
self.html_top(_('Diffusion'))
r = TemplateIO(html=True)
'<ul id="main-actions">'
'<li><a href="add" rel="popup">%s</a></li>' % _('Add a participant')
'</ul>'
r += htmltext('<ul id="main-actions">')
r += htmltext('<li><a href="add" rel="popup">%s</a></li>') % _('Add a participant')
r += htmltext('</ul>')
'<h2>%s</h2>' % _('Diffusion')
r += htmltext('<h2>%s</h2>') % _('Diffusion')
'<ul>'
' <li>%s ' % _('Participants:')
r += htmltext('<ul>')
r += htmltext(' <li>%s ') % _('Participants:')
if self.objectdef.roles:
'<a href="disable">%s</a>' % _('Anybody')
' - '
'<strong>%s</strong>' % _('List of persons')
r += htmltext('<a href="disable">%s</a>') % _('Anybody')
r += htmltext(' - ')
r += htmltext('<strong>%s</strong>') % _('List of persons')
else:
'<strong>%s</strong>' % _('Anybody')
' - '
' <a href="enable">%s</a>' % _('List of persons')
'</li>'
r += htmltext('<strong>%s</strong>') % _('Anybody')
r += htmltext(' - ')
r += htmltext(' <a href="enable">%s</a>') % _('List of persons')
r += htmltext('</li>')
access_mode = get_form_access_mode(self.objectdef)
' <li>%s ' % _('Questionnaire Address:')
r += htmltext(' <li>%s ') % _('Questionnaire Address:')
if access_mode == 'public':
'<strong>%s</strong>' % _('Visible')
r += htmltext('<strong>%s</strong>') % _('Visible')
else:
' <a href="access-public">%s</a>' % _('Visible')
' - '
r += htmltext(' <a href="access-public">%s</a>') % _('Visible')
r += htmltext(' - ')
if access_mode == 'private':
'<strong>%s</strong>' % _('Hidden')
r += htmltext('<strong>%s</strong>') % _('Hidden')
else:
' <a href="access-private">%s</a>' % _('Hidden')
'<ul><li>'
r += htmltext(' <a href="access-private">%s</a>') % _('Hidden')
r += htmltext('<ul><li>')
url = get_form_url(self.objectdef)
'<a href="%s">%s</a>' % (url, url)
'</li></ul>'
'</li>'
r += htmltext('<a href="%s">%s</a>') % (url, url)
r += htmltext('</li></ul>')
r += htmltext('</li>')
emails_cfg = get_cfg('emails', {})
'<li>%s' % _('Sender Address: ')
r += htmltext('<li>%s') % _('Sender Address: ')
if emails_cfg.get('from', ''):
emails_cfg.get('from')
' (<a href="emailfrom" rel="popup">%s</a>)' % _('change address')
r += htmltext(' (<a href="emailfrom" rel="popup">%s</a>)') % _('change address')
else:
_('None set')
' (<a href="emailfrom" rel="popup">%s</a>)' % _('set address')
'</li>'
r += _('None set')
r += htmltext(' (<a href="emailfrom" rel="popup">%s</a>)') % _('set address')
r += htmltext('</li>')
'<li>%s' % _('Notification when a questionnaire is filled: ')
r += htmltext('<li>%s') % _('Notification when a questionnaire is filled: ')
if not self.objectdef.workflow_options:
self.objectdef.workflow_options = {}
if self.objectdef.workflow_options.get('done*mail-on-filled*to'):
self.objectdef.workflow_options.get('done*mail-on-filled*to')
' (<a href="emailnotify" rel="popup">%s</a>)' % _('change address')
r += htmltext(' (<a href="emailnotify" rel="popup">%s</a>)') % _('change address')
else:
_('None set')
' (<a href="emailnotify" rel="popup">%s</a>)' % _('set address')
'</li>'
r += _('None set')
r += htmltext(' (<a href="emailnotify" rel="popup">%s</a>)') % _('set address')
r += htmltext('</li>')
'</ul>'
r += htmltext('</ul>')
get_response().filter['sidebar'] = self.get_sidebar()
get_session().display_message()
if self.objectdef.roles:
self.display_participants()
r += self.display_participants()
def display_participants [html] (self):
return r.getvalue()
def display_participants(self):
users = []
many_users = False
search_result = False
@ -400,15 +407,17 @@ class DiffusionDirectory(Directory):
# XXX: and now, convert from user_ids to User objects?
r = TemplateIO(html=True)
if user_ids:
# XXX: paragraph of explanation, and option to get a list of access
# codes instead of sending them out
'<p>'
_('%s participants.') % len(user_ids)
r += htmltext('<p>')
r += _('%s participants.') % len(user_ids)
if search_result:
' <a href=".">%s</a>' % _('Back to full listing')
'</p>'
r += htmltext(' <a href=".">%s</a>') % _('Back to full listing')
r += htmltext('</p>')
if len(user_ids) < 500:
# reasonable number, load all of them, so it's possible to
@ -420,62 +429,65 @@ class DiffusionDirectory(Directory):
all_users = sorted(user_ids)
user_are_objects = False
'<div class="splitcontent-left">'
'<ul class="biglist">'
r += htmltext('<div class="splitcontent-left">')
r += htmltext('<ul class="biglist">')
rightcol = False
for i, user in enumerate(all_users):
if user_are_objects:
user_id = user.id
'<li><strong>%s</strong> ' % user.display_name
r += htmltext('<li><strong>%s</strong> ') % user.display_name
else:
user_id = user
'<li><strong>%s</strong> ' % user_id
'(<a href="remove?id=%s">%s</a>)' % (user_id, _('remove'))
'</li>'
r += htmltext('<li><strong>%s</strong> ') % user_id
r += htmltext('(<a href="remove?id=%s">%s</a>)') % (user_id, _('remove'))
r += htmltext('</li>')
if not rightcol and (i+1) >= len(user_ids)/2.0:
rightcol = True
'</ul>'
'</div>'
'<div class="splitcontent-right">'
'<ul class="biglist">'
'</ul>'
'</div>'
r += htmltext('</ul>')
r += htmltext('</div>')
r += htmltext('<div class="splitcontent-right">')
r += htmltext('<ul class="biglist">')
r += htmltext('</ul>')
r += htmltext('</div>')
# XXX: add pagination
elif user_ids is None: # unknown set
'<p>'
_('Unable to get a list of participants.')
' '
_('System overloaded?')
r += htmltext('<p>')
r += _('Unable to get a list of participants.')
r += ' '
r += _('System overloaded?')
# XXX: + use search form on the right.
'</p>'
r += htmltext('</p>')
else:
'<p>'
r += htmltext('<p>')
if search_result:
_('There is currently no participants matching your query.')
r += _('There is currently no participants matching your query.')
else:
_('There is currently no participants defined.')
'</p>'
r += _('There is currently no participants defined.')
r += htmltext('</p>')
return r.getvalue()
def get_sidebar [html] (self):
def get_sidebar(self):
if not self.objectdef.roles:
return ''
'<ul>'
'<li><a href="import" rel="popup">%s</a></li>' % _('Import list of participants')
'<li><a href="import-disabled" rel="popup">%s</a></li>' % _(
r = TemplateIO(html=True)
r += htmltext('<ul>')
r += htmltext('<li><a href="import" rel="popup">%s</a></li>') % _('Import list of participants')
r += htmltext('<li><a href="import-disabled" rel="popup">%s</a></li>') % _(
'Import list of participants to disable')
'<li><a href="mail-access-codes">%s</a></li>' % _('Mail access codes')
r += htmltext('<li><a href="mail-access-codes">%s</a></li>') % _('Mail access codes')
if quota.can_mail():
'<li><a href="mail-participants">%s</a></li>' % _('Mail participants')
'</ul>'
r += htmltext('<li><a href="mail-participants">%s</a></li>') % _('Mail participants')
r += htmltext('</ul>')
'<h4>%s</h4>' % _('Search a participant')
r += htmltext('<h4>%s</h4>') % _('Search a participant')
search_form = Form(enctype='multipart/form-data', use_tokens=False)
search_form.add(StringWidget, 'email', title=_('Email'))
search_form.add_submit('submit', _('Search'))
search_form.render()
r += search_form.render()
return r.getvalue()
def remove(self):
user_id = get_request().form.get('id')
@ -491,7 +503,7 @@ class DiffusionDirectory(Directory):
user.store()
return redirect('.')
def add [html] (self):
def add(self):
form = Form(enctype='multipart/form-data')
form.add(StringWidget, 'name', title=_('Name'), size=40, required=False)
form.add(EmailWidget, 'email', title=_('Email'), required=True)
@ -509,7 +521,9 @@ class DiffusionDirectory(Directory):
get_response().breadcrumb.append( ('add', _('Add')) )
self.html_top(_('Add a Participant'))
form.render()
r = TemplateIO(html=True)
r += form.render()
return r.getvalue()
def add_submit(self, form):
name = form.get_widget('name').parse()
@ -536,7 +550,7 @@ class DiffusionDirectory(Directory):
return redirect('.')
def p_import [html] (self):
def p_import(self):
if get_request().form.get('job'):
return self.participants_importing()
@ -556,17 +570,19 @@ class DiffusionDirectory(Directory):
get_response().breadcrumb.append( ('import', _('Import')) )
self.html_top(_('Import a List of Participants'))
'<h2>%s</h2>' % _('Importing a List of Participants')
'<p>'
_('The file should be in the CSV file format. Using your spreadsheet '\
'program (Calc, Excel...), click "Save as" and select the CSV format.')
'</p>'
'<p>'
_('The file should have email addresses in the first column, and, '\
'optionnaly, names in the second column.')
'</p>'
get_session().display_message()
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Importing a List of Participants')
r += htmltext('<p>')
r += _('The file should be in the CSV file format. Using your spreadsheet '\
'program (Calc, Excel...), click "Save as" and select the CSV format.')
r += htmltext('</p>')
r += htmltext('<p>')
r += _('The file should have email addresses in the first column, and, '\
'optionnaly, names in the second column.')
r += htmltext('</p>')
r += get_session().display_message()
r += form.render()
return r.getvalue()
def import_submit(self, form):
class ParticipantsImporter:
@ -648,30 +664,32 @@ class DiffusionDirectory(Directory):
return redirect('import?job=%s' % job.id)
def participants_importing [html] (self):
def participants_importing(self):
try:
job = AfterJob.get(get_request().form.get('job'))
except KeyError:
return redirect('.')
self.html_top( _('Importing Participants'))
r = TemplateIO(html=True)
get_response().add_javascript(['jquery.js', 'interface.js', 'afterjob.js'])
'<dl class="job-status">'
'<dt>'
_(job.label)
'</dt>'
'<dd>'
'<span class="afterjob" id="%s">' % job.id
_(job.status)
'</span>'
'</dd>'
'</dl>'
r += htmltext('<dl class="job-status">')
r += htmltext('<dt>')
r += _(job.label)
r += htmltext('</dt>')
r += htmltext('<dd>')
r += htmltext('<span class="afterjob" id="%s">') % job.id
r += _(job.status)
r += htmltext('</span>')
r += htmltext('</dd>')
r += htmltext('</dl>')
'<div class="done">'
'<a href="./">%s</a>' % _('Back')
'</div>'
r += htmltext('<div class="done">')
r += htmltext('<a href="./">%s</a>') % _('Back')
r += htmltext('</div>')
return r.getvalue()
def mail_access_codes [html] (self):
def mail_access_codes(self):
if get_request().form.get('job'):
return self.access_code_mailing()
@ -682,7 +700,7 @@ class DiffusionDirectory(Directory):
form = Form(enctype='multipart/form-data')
form.add(EmailWidget, 'mail_from', title=_('From'), size=40, required=False,
value=emails_cfg.get('from', ''), size=30)
value=emails_cfg.get('from', ''))
form.add(StringWidget, 'mail_subject', title=_('Subject'), size=40, required=True,
value=default_subject)
form.add(TextWidget, 'mail_body', title=_('Body'), cols=70, rows=20, required=True,
@ -718,33 +736,37 @@ class DiffusionDirectory(Directory):
return redirect('mail-access-codes?job=%s' % job.id)
self.html_top(_('Mailing access codes'))
'<h2>%s</h2>' % _('Mailing access codes')
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Mailing access codes')
r += form.render()
return r.getvalue()
def access_code_mailing [html] (self):
def access_code_mailing(self):
try:
job = AfterJob.get(get_request().form.get('job'))
except KeyError:
return redirect('.')
self.html_top(_('Mailing access codes'))
r = TemplateIO(html=True)
get_response().add_javascript(['jquery.js', 'interface.js', 'afterjob.js'])
'<dl class="job-status">'
'<dt>'
_(job.label)
'</dt>'
'<dd>'
'<span class="afterjob" id="%s">' % job.id
_(job.status)
'</span>'
'</dd>'
'</dl>'
r += htmltext('<dl class="job-status">')
r += htmltext('<dt>')
r += _(job.label)
r += htmltext('</dt>')
r += htmltext('<dd>')
r += htmltext('<span class="afterjob" id="%s">') % job.id
r += _(job.status)
r += htmltext('</span>')
r += htmltext('</dd>')
r += htmltext('</dl>')
'<div class="done">'
'<a href="./">%s</a>' % _('Back')
'</div>'
r += htmltext('<div class="done">')
r += htmltext('<a href="./">%s</a>') % _('Back')
r += htmltext('</div>')
return r.getvalue()
def import_disabled [html] (self):
def import_disabled(self):
if get_request().form.get('job'):
return self.participants_disabling()
@ -764,16 +786,18 @@ class DiffusionDirectory(Directory):
get_response().breadcrumb.append( ('import', _('Import')) )
self.html_top(_('Import a List of Participants to Disable'))
'<h2>%s</h2>' % _('Importing a List of Participants to Disable')
'<p>'
_('The file should be in the CSV file format. Using your spreadsheet '\
'program (Calc, Excel...), click "Save as" and select the CSV format.')
'</p>'
'<p>'
_('The file should consist of email addresses, one per line.')
'</p>'
get_session().display_message()
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Importing a List of Participants to Disable')
r += htmltext('<p>')
r += _('The file should be in the CSV file format. Using your spreadsheet '\
'program (Calc, Excel...), click "Save as" and select the CSV format.')
r += htmltext('</p>')
r += htmltext('<p>')
r += _('The file should consist of email addresses, one per line.')
r += htmltext('</p>')
r += get_session().display_message()
r += form.render()
return r.getvalue()
def import_disabled_submit(self, form):
class ParticipantsDisabler:
@ -853,30 +877,32 @@ class DiffusionDirectory(Directory):
return redirect('import-disabled?job=%s' % job.id)
def participants_disabling [html] (self):
def participants_disabling(self):
try:
job = AfterJob.get(get_request().form.get('job'))
except KeyError:
return redirect('.')
self.html_top(_('Disabling Participants'))
r = TemplateIO(html=True)
get_response().add_javascript(['jquery.js', 'interface.js', 'afterjob.js'])
'<dl class="job-status">'
'<dt>'
_(job.label)
'</dt>'
'<dd>'
'<span class="afterjob" id="%s">' % job.id
_(job.status)
'</span>'
'</dd>'
'</dl>'
r += htmltext('<dl class="job-status">')
r += htmltext('<dt>')
r += _(job.label)
r += htmltext('</dt>')
r += htmltext('<dd>')
r += htmltext('<span class="afterjob" id="%s">') % job.id
r += _(job.status)
r += htmltext('</span>')
r += htmltext('</dd>')
r += htmltext('</dl>')
'<div class="done">'
'<a href="./">%s</a>' % _('Back')
'</div>'
r += htmltext('<div class="done">')
r += htmltext('<a href="./">%s</a>') % _('Back')
r += htmltext('</div>')
return r.getvalue()
def mail_participants [html] (self):
def mail_participants(self):
if get_request().form.get('job'):
return self.participants_mailing()
@ -890,7 +916,7 @@ class DiffusionDirectory(Directory):
form = Form(enctype='multipart/form-data')
form.add(EmailWidget, 'mail_from', title=_('From'), size=40, required=False,
value=emails_cfg.get('from', ''), size=30)
value=emails_cfg.get('from', ''))
form.add(StringWidget, 'mail_subject', title=_('Subject'), size=40, required=True,
value=default_subject)
form.add(TextWidget, 'mail_body', title=_('Body'), cols=70, rows=20, required=True,
@ -925,10 +951,12 @@ class DiffusionDirectory(Directory):
return redirect('mail-participants?job=%s' % job.id)
self.html_top(_('Mailing participants'))
'<h2>%s</h2>' % _('Mailing participants')
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Mailing participants')
r += form.render()
return r.getvalue()
def participants_mailing [html] (self):
def participants_mailing(self):
try:
job = AfterJob.get(get_request().form.get('job'))
except KeyError:
@ -936,20 +964,22 @@ class DiffusionDirectory(Directory):
self.html_top(_('Mailing participants'))
get_response().add_javascript(['jquery.js', 'interface.js', 'afterjob.js'])
'<dl class="job-status">'
'<dt>'
_(job.label)
'</dt>'
'<dd>'
'<span class="afterjob" id="%s">' % job.id
_(job.status)
'</span>'
'</dd>'
'</dl>'
r = TemplateIO(html=True)
r += htmltext('<dl class="job-status">')
r += htmltext('<dt>')
r += _(job.label)
r += htmltext('</dt>')
r += htmltext('<dd>')
r += htmltext('<span class="afterjob" id="%s">') % job.id
r += _(job.status)
r += htmltext('</span>')
r += htmltext('</dd>')
r += htmltext('</dl>')
'<div class="done">'
'<a href="./">%s</a>' % _('Back')
'</div>'
r += htmltext('<div class="done">')
r += htmltext('<a href="./">%s</a>') % _('Back')
r += htmltext('</div>')
return r.getvalue()
EmailsDirectory.register('asec-voting-instructions',
N_('Instructions and access codes'),

View File

@ -21,7 +21,7 @@ from sets import Set
from quixote import get_publisher, get_request, get_response, get_session, redirect
from quixote.directory import Directory
from quixote.html import htmltext
from quixote.html import TemplateIO, htmltext
from qommon.backoffice.menu import html_top
from qommon.admin.menu import command_icon
@ -49,7 +49,7 @@ class CustomFieldDefPage(FieldDefPage):
section = 'forms/'
wsf_support = False
def html_top(self, section, *args, **kwargs):
def html_top(self, *args, **kwargs):
html_top('forms/%s' % self.objectdef.id, *args, **kwargs)
def duplicate(self):
@ -81,7 +81,7 @@ class FormDirectory(FieldsDirectory):
support_import = False
blacklisted_types = ['file']
def html_top(self, section, *args, **kwargs):
def html_top(self, *args, **kwargs):
html_top('forms/%s' % self.objectdef.id, *args, **kwargs)
def __init__(self, objectdef):
@ -91,7 +91,7 @@ class FormDirectory(FieldsDirectory):
if not hasattr(self.objectdef, 'asec_status'):
self.objectdef.asec_status = 'running'
def title [html] (self):
def title(self):
form = Form(enctype='multipart/form-data')
form.add(StringWidget, 'name', title=_('Title'), size=40,
required=True, value=self.objectdef.name)
@ -110,14 +110,14 @@ class FormDirectory(FieldsDirectory):
get_response().breadcrumb.append( ('forms/', None) )
get_response().breadcrumb.append( ('new', _('New Questionnaire')) )
html_top('forms', _('Change Title'))
form.render()
return form.render()
def title_submit(self, form):
self.objectdef.name = form.get_widget('name').parse()
self.objectdef.store()
return redirect('.')
def delete [html] (self):
def delete(self):
form = Form(enctype='multipart/form-data')
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
'You are about to irrevocably delete this questionnaire.')))
@ -129,8 +129,10 @@ class FormDirectory(FieldsDirectory):
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append(('delete', _('Delete')))
html_top('forms', title = _('Delete Questionnaire'))
'<h2>%s %s</h2>' % (_('Deleting Questionnaire:'), self.objectdef.name)
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s %s</h2>') % (_('Deleting Questionnaire:'), self.objectdef.name)
r += form.render()
return r.getvalue()
else:
# XXX: should also remove participants role, and participants to no
# other forms
@ -144,31 +146,35 @@ class FormDirectory(FieldsDirectory):
return t
return self._q_index_view()
def _q_index_view [html] (self):
def _q_index_view(self):
self.html_top(self.objectdef.name)
get_response().add_javascript(['jquery.js', 'interface.js', 'biglist.js'])
r = TemplateIO(html=True)
self.index_top()
r += self.index_top()
form = self.get_preview_form()
'<div class="form-preview bo-block">'
form.render()
'</div>'
r += htmltext('<div class="form-preview bo-block">')
r += form.render()
r += htmltext('</div>')
get_response().filter['sidebar'] = self.get_results_sidebar()
return r.getvalue()
def get_results_sidebar [html] (self):
def get_results_sidebar(self):
r = TemplateIO(html=True)
if self.objectdef.asec_status == 'running':
'<h3>%s</h3>' % _('Visualisation & export of preliminary results')
r += htmltext('<h3>%s</h3>') % _('Visualisation & export of preliminary results')
else:
'<h3>%s</h3>' % _('Visualisation & export of results')
r += htmltext('<h3>%s</h3>') % _('Visualisation & export of results')
'<ul>'
' <li><a href="results/">%s</a></li>' % _('Statistics')
' <li><a href="results/csv">%s</a></li>' % _('CSV Export')
r += htmltext('<ul>')
r += htmltext(' <li><a href="results/">%s</a></li>') % _('Statistics')
r += htmltext(' <li><a href="results/csv">%s</a></li>') % _('CSV Export')
if str(self.objectdef.workflow_id).endswith(str('+anonymous')):
' <li><a href="results/participation">%s</a>' % _('Participation')
'</ul>'
r += htmltext(' <li><a href="results/participation">%s</a>') % _('Participation')
r += htmltext('</ul>')
return r.getvalue()
def get_preview_form(self):
form = Form()
@ -206,87 +212,91 @@ class FormDirectory(FieldsDirectory):
else:
raise quota.QuotaExceeded()
def index_top [html] (self):
'<ul id="main-actions">'
def index_top(self):
r = TemplateIO(html=True)
r += htmltext('<ul id="main-actions">')
if self.objectdef.asec_status == 'soon-available':
'<li><a href="title" rel="popup">%s</a></li>' % _('Change Title')
'<li><a href="delete" rel="popup">%s</a></li>' % _('Delete')
'</ul>'
r += htmltext('<li><a href="title" rel="popup">%s</a></li>') % _('Change Title')
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
r += htmltext('</ul>')
'<h2>%s</h2>' % _('Design')
get_session().display_message()
r += htmltext('<h2>%s</h2>') % _('Design')
r += get_session().display_message()
'<ul>'
r += htmltext('<ul>')
if self.objectdef.roles:
'<li>%s ' % _('Anonymity:')
r += htmltext('<li>%s ') % _('Anonymity:')
if str(self.objectdef.workflow_id).endswith(str('+anonymous')):
'<strong>%s</strong>' % _('Enabled')
' - '
'<a href="anonymity-off">%s</a>' % _('Disabled')
r += htmltext('<strong>%s</strong>') % _('Enabled')
r += ' - '
r += htmltext('<a href="anonymity-off">%s</a>') % _('Disabled')
else:
'<a href="anonymity-on">%s</a>' % _('Enabled')
' - '
'<strong>%s</strong>' % _('Disabled')
'</li>'
r += htmltext('<a href="anonymity-on">%s</a>') % _('Enabled')
r += ' - '
r += htmltext('<strong>%s</strong>') % _('Disabled')
r += htmltext('</li>')
if not self.objectdef.disabled:
' <li>%s ' % _('Current Status:')
r += htmltext(' <li>%s ') % _('Current Status:')
if self.objectdef.asec_status == 'soon-available':
'<strong>%s</strong>' % _('Soon Available')
r += htmltext('<strong>%s</strong>') % _('Soon Available')
else:
'<a href="status-soonavailable">%s</a> ' % _('Soon Available')
' - '
r += htmltext('<a href="status-soonavailable">%s</a> ') % _('Soon Available')
r += ' - '
if self.objectdef.asec_status == 'running':
'<strong>%s</strong>' % _('Running')
r += htmltext('<strong>%s</strong>') % _('Running')
else:
if self.objectdef.fields:
'<a href="status-running">%s</a> ' % _('Running')
r += htmltext('<a href="status-running">%s</a> ') % _('Running')
else:
_('Running')
' - '
r += _('Running')
r += ' - '
if self.objectdef.asec_status == 'closed':
'<strong>%s</strong>' % _('Closed')
r += htmltext('<strong>%s</strong>') % _('Closed')
else:
if self.objectdef.fields:
'<a href="status-closed">%s</a> ' % _('Closed')
r += htmltext('<a href="status-closed">%s</a> ') % _('Closed')
else:
_('Closed')
'</li>'
r += _('Closed')
r += htmltext('</li>')
'</ul>'
r += htmltext('</ul>')
if not self.objectdef.fields:
'<p>'
_('There are not yet any fields for this questionnaire.')
'</p>'
'<p>'
_('You should use the controls at the right of the page to add fields.')
'</p>'
r += htmltext('<p>')
r += _('There are not yet any fields for this questionnaire.')
r += htmltext('</p>')
r += htmltext('<p>')
r += _('You should use the controls at the right of the page to add fields.')
r += htmltext('</p>')
'<h3>%s</h3>' % _('Contents of your questionnaire')
r += htmltext('<h3>%s</h3>') % _('Contents of your questionnaire')
return r.getvalue()
def get_new_field_form [html] (self, page_no):
def get_new_field_form(self, page_no):
r = TemplateIO(html=True)
if not self.objectdef.disabled:
if not hasattr(self.objectdef, str('asec_status')):
self.objectdef.asec_status = 'running'
if self.objectdef.asec_status == 'soon-available':
if self.objectdef.data_class().keys():
'<p>'
'<strong>%s</strong> ' % _('Warning:')
_('This form already contains submitted items.')
' '
'<a href="clean" rel="popup">%s</a>' % _('Remove Them')
'</p>'
r += htmltext('<p>')
r += htmltext('<strong>%s</strong> ') % _('Warning:')
r += _('This form already contains submitted items.')
r += ' '
r += htmltext('<a href="clean" rel="popup">%s</a>') % _('Remove Them')
r += htmltext('</p>')
if quota.may_add_a_new_field(self.objectdef):
super(FormDirectory, self).get_new_field_form(page_no)
r += super(FormDirectory, self).get_new_field_form(page_no)
else:
'<p>'
_('This questionnaire has reached its number of questions quota.')
'</p>'
r += htmltext('<p>')
r += _('This questionnaire has reached its number of questions quota.')
r += htmltext('</p>')
return r.getvalue()
def clean [html] (self):
def clean(self):
form = Form(enctype='multipart/form-data')
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
'You are about to irrevocably remove all submitted questionnaires.')))
@ -303,7 +313,7 @@ class FormDirectory(FieldsDirectory):
pass
html_top('forms', _('Remove submitted questionnaires'))
form.render()
return form.render()
def clean_submit(self):
get_logger().info('form %s - wiped submitted form' % self.objectdef.id)
@ -348,7 +358,7 @@ class FormDirectory(FieldsDirectory):
self.objectdef.id, self.objectdef.asec_status))
return redirect('.')
def options [html] (self):
def options(self):
form = Form(enctype='multipart/form-data')
if self.objectdef.roles: # list of participants -> access codes
form.add(CheckboxWidget, 'access_as_password',
@ -369,8 +379,10 @@ class FormDirectory(FieldsDirectory):
get_response().breadcrumb.append( ('forms/', None) )
get_response().breadcrumb.append( ('options', _('Options')) )
html_top('forms', _('Options'))
'<h2>%s</h2>' % _('Options')
form.render()
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Options')
r += form.render()
return r.getvalue()
def options_submit(self, form):
for widget in ('access_as_password',):
@ -393,7 +405,7 @@ class FormDirectory(FieldsDirectory):
class FormsDirectory(Directory):
_q_exports = ['']
def _q_index [html] (self):
def _q_index(self):
return redirect('..')
def _q_lookup(self, component):

View File

@ -16,6 +16,7 @@
from quixote import get_request, get_response, redirect
from quixote.directory import Directory
from quixote.html import TemplateIO, htmltext
from qommon.backoffice.menu import html_top
from qommon import errors, misc, get_logger
@ -56,33 +57,36 @@ class FormResultDirectory(FormPage):
def html_top(self, section, *args, **kwargs):
html_top('forms/%s/results' % self.formdef.id, *args, **kwargs)
def _q_index [html] (self):
def _q_index(self):
self.html_top(_('Analysis'))
'<h2>%s</h2>' % _('Analysis')
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Analysis')
if self.formdef.asec_status == 'running':
'<p>'
_('The questionnaire is still running, this is therefore preliminary data.')
'</p>'
r += htmltext('<p>')
r += _('The questionnaire is still running, this is therefore preliminary data.')
r += htmltext('</p>')
values = self.formdef.data_class().select()
no_forms = len(values)
'<p>%s %d</p>' % (_('Total number of records:'), no_forms)
r += htmltext('<p>%s %d</p>') % (_('Total number of records:'), no_forms)
# XXX: insert participation stats here
self.stats_fields(values)
r += self.stats_fields(values)
get_response().filter['sidebar'] = self.get_results_sidebar()
return r.getvalue()
def get_results_sidebar [html] (self, qs=''):
'<ul>'
' <li><a href="list%s">%s</a></li>' % (qs, _('List of results'))
' <li><a href="table%s">%s</a></li>' % (qs, _('Table of results'))
' <li><a href="csv%s">%s</a></li>' % (qs, _('CSV Export'))
def get_results_sidebar(self, qs=''):
r = TemplateIO(html=True)
r += htmltext('<ul>')
r += htmltext(' <li><a href="list%s">%s</a></li>') % (qs, _('List of results'))
r += htmltext(' <li><a href="table%s">%s</a></li>') % (qs, _('Table of results'))
r += htmltext(' <li><a href="csv%s">%s</a></li>') % (qs, _('CSV Export'))
if str(self.formdef.workflow_id).endswith(str('+anonymous')):
' <li><a href="participation">%s</a>' % _('Participation')
'</ul>'
r += htmltext(' <li><a href="participation">%s</a>') % _('Participation')
r += htmltext('</ul>')
return r.getvalue()
def csv_tuple_heading(self, fields):
if str(self.formdef.workflow_id).endswith(str('+anonymous')):
@ -116,13 +120,14 @@ class FormResultDirectory(FormPage):
return get_request().form['filter']
return 'all'
def participation [html] (self):
def participation(self):
if not str(self.formdef.workflow_id).endswith(str('+anonymous')):
raise errors.TraversalError()
get_logger().info('backoffice - form %s - participation' % self.formdef.name)
self.html_top('%s - %s' % (_('Participation'), self.formdef.name))
r = TemplateIO(html=True)
get_response().breadcrumb.append( ('participation', _('Participation')) )
'<h2>%s - %s</h2>' % (self.formdef.name, _('Participation'))
r += htmltext('<h2>%s - %s</h2>') % (self.formdef.name, _('Participation'))
nb_users = 0
if self.formdef.roles:
@ -134,26 +139,27 @@ class FormResultDirectory(FormPage):
continue
nb_users += 1
'<ul>'
' <li>%s</li>' % _('Registered Participants: %s') % nb_users
r += htmltext('<ul>')
r += htmltext(' <li>%s</li>') % _('Registered Participants: %s') % nb_users
voters = anonymity.get_voters(self.formdef)
' <li>%s</li>' % _('Registered Responses: %s') % len(voters)
r += htmltext(' <li>%s</li>') % _('Registered Responses: %s') % len(voters)
if nb_users:
' <li>%s</li>' % _('Abstention: %.2f%%') % (100*(1.0-(1.0*len(voters)/nb_users)))
r += htmltext(' <li>%s</li>') % _('Abstention: %.2f%%') % (100*(1.0-(1.0*len(voters)/nb_users)))
else:
' <li>%s</li>' % _('Abstention: n/a')
'</ul>'
r += htmltext(' <li>%s</li>') % _('Abstention: n/a')
r += htmltext('</ul>')
'<h3>%s</h3>' % _('List of participants')
r += htmltext('<h3>%s</h3>') % _('List of participants')
'<ul>'
r += htmltext('<ul>')
for v in sorted(voters):
try:
'<li>%s</li>' % User.get(v).display_name
r += htmltext('<li>%s</li>') % User.get(v).display_name
except KeyError:
'<li>%s</li>' % _('Deleted user')
'</ul>'
r += htmltext('<li>%s</li>') % _('Deleted user')
r += htmltext('</ul>')
return r.getvalue()
def get_fields_from_query(self):
field_ids = [x for x in get_request().form.keys()]
@ -171,8 +177,9 @@ class FormResultDirectory(FormPage):
return fields
def list [html] (self):
def list(self):
self.html_top('%s - %s' % (_('List of results'), self.formdef.name))
r = TemplateIO(html=True)
fields = self.get_fields_from_query()
qs = ''
if get_request().get_query():
@ -181,11 +188,11 @@ class FormResultDirectory(FormPage):
get_response().breadcrumb.append( ('list', _('List of results')) )
if len(fields) == 1:
'<h2>%s</h2>' % fields[0].label
r += htmltext('<h2>%s</h2>') % fields[0].label
else:
'<h2>%s</h2>' % _('List of results')
r += htmltext('<h2>%s</h2>') % _('List of results')
'<div class="fields-listing">'
r += htmltext('<div class="fields-listing">')
for result in self.formdef.data_class().select(order_by='id'):
had_data = False
for field in fields:
@ -219,19 +226,21 @@ class FormResultDirectory(FormPage):
continue
if not had_data:
'<div class="dataview">'
r += htmltext('<div class="dataview">')
had_data = True
if len(fields) > 1:
'<p><span class="label">%s</span> ' % field.label
'<span class="value">'
value
'</span></p>'
r += htmltext('<p><span class="label">%s</span> ') % field.label
r += htmltext('<span class="value">')
r += value
r += htmltext('</span></p>')
if had_data:
'</div>'
'</div>'
r += htmltext('</div>')
r += htmltext('</div>')
return r.getvalue()
def table [html] (self):
def table(self):
self.html_top('%s - %s' % (_('Table of results'), self.formdef.name))
r = TemplateIO(html=True)
fields = self.get_fields_from_query()
qs = ''
if get_request().get_query():
@ -239,14 +248,14 @@ class FormResultDirectory(FormPage):
get_response().filter['sidebar'] = self.get_results_sidebar(qs) + self.get_fields_sidebar(fields)
get_response().breadcrumb.append( ('table', _('Table of results')) )
'<h2>%s</h2>' % _('Table of results')
r += htmltext('<h2>%s</h2>') % _('Table of results')
'<table id="listing">'
'<thead>'
r += htmltext('<table id="listing">')
r += htmltext('<thead>')
for field in fields:
'<th>%s</th>' % field.label
'</thead>'
'<tbody>'
r += htmltext('<th>%s</th>') % field.label
r += htmltext('</thead>')
r += htmltext('<tbody>')
for result in self.formdef.data_class().select(order_by='id'):
had_data = False
for field in fields:
@ -274,32 +283,35 @@ class FormResultDirectory(FormPage):
value = value.replace(str('[download]'), str(''))
if not had_data:
'<tr>'
r += htmltext('<tr>')
had_data = True
'<td>'
value
'</td>'
r += htmltext('<td>')
r += value
r += htmltext('</td>')
if had_data:
'</tr>'
'</tbody>'
'</table>'
r += htmltext('</tr>')
r += htmltext('</tbody>')
r += htmltext('</table>')
return r.getvalue()
def get_fields_sidebar [html] (self, fields):
'<h3>%s</h3>' % _('Fields to display')
'<form>'
'<ul>'
def get_fields_sidebar(self, fields):
r = TemplateIO(html=True)
r += htmltext('<h3>%s</h3>') % _('Fields to display')
r += htmltext('<form>')
r += htmltext('<ul>')
for field in self.get_formdef_fields():
if not hasattr(field, str('get_view_value')):
continue
'<li><input type="checkbox" name="%s"' % field.id
r += htmltext('<li><input type="checkbox" name="%s"') % field.id
if field.id in [x.id for x in fields]:
' checked="checked"'
'/>'
'<label for="%s">%s</label>' % (field.id, field.label)
'</li>'
'</ul>'
'<input type="submit" value="%s"/>' % _('Reload')
'</form>'
r += htmltext(' checked="checked"')
r += htmltext('/>')
r += htmltext('<label for="%s">%s</label>') % (field.id, field.label)
r += htmltext('</li>')
r += htmltext('</ul>')
r += htmltext('<input type="submit" value="%s"/>') % _('Reload')
r += htmltext('</form>')
return r.getvalue()
def get_formdef_fields(self):
fields = []

View File

@ -16,6 +16,7 @@
from quixote import get_request, redirect
from quixote.directory import Directory
from quixote.html import TemplateIO, htmltext
from qommon.admin.texts import TextsDirectory
from qommon.admin.emails import EmailsDirectory
from qommon import errors
@ -43,7 +44,8 @@ class ResultsDirectory(Directory):
if self.formdef.asec_status != 'closed':
raise errors.AccessForbiddenError()
def stats_fields [html] (self, values):
def stats_fields(self, values):
r = TemplateIO(html=True)
had_page = False
last_page = None
last_title = None
@ -62,22 +64,24 @@ class ResultsDirectory(Directory):
continue
if last_page:
if had_page:
'</div>'
'<div class="page">'
'<h3>%s</h3>' % last_page
r += htmltext('</div>')
r += htmltext('<div class="page">')
r += htmltext('<h3>%s</h3>') % last_page
had_page = True
last_page = None
if last_title:
'<h3>%s</h3>' % last_title
r += htmltext('<h3>%s</h3>') % last_title
last_title = None
t
r += t
if had_page:
'</div>'
r += htmltext('</div>')
return r.getvalue()
def _q_index [html] (self):
def _q_index(self):
wcs.forms.root.html_top(self.formdef.name)
r = TemplateIO(html=True)
# XXX: need an option to decide if we want results to be displayed
#values = self.formdef.data_class().select()
@ -85,18 +89,19 @@ class ResultsDirectory(Directory):
if str(self.formdef.workflow_id).endswith(str('+anonymous')):
# Verification Code
'<div class="verification-code">'
'<h3>%s</h3>' % _('Anonymous Verification Code Check')
r += htmltext('<div class="verification-code">')
r += htmltext('<h3>%s</h3>') % _('Anonymous Verification Code Check')
form = Form(action='check')
form.add(StringWidget, 'code', title=('Verification Code'), required=True)
_('Enter your verification code to check it against the recorded ballot.')
r += _('Enter your verification code to check it against the recorded ballot.')
form.add_submit('submit', _('Submit'))
form.render()
_('Or search for it in the list of all the ballots:')
' <a href="listing">%s</a>' % _('complete listing')
'</div>'
r += form.render()
r += _('Or search for it in the list of all the ballots:')
r += htmltext(' <a href="listing">%s</a>') % _('complete listing')
r += htmltext('</div>')
return r.getvalue()
def check [html] (self):
def check(self):
if not str(self.formdef.workflow_id).endswith(str('+anonymous')):
raise errors.TraversalError()
wcs.forms.root.html_top(self.formdef.name)
@ -107,36 +112,39 @@ class ResultsDirectory(Directory):
return redirect('.')
code = get_request().form.get('code')
r = TemplateIO(html=True)
import anonymity
if code not in anonymity.get_verification_codes(self.formdef):
'<p>'
_('No ballot has been found with such a verification code.')
'</p>'
r += htmltext('<p>')
r += _('No ballot has been found with such a verification code.')
r += htmltext('</p>')
else:
for formdata in self.formdef.data_class().select():
if hasattr(formdata, str('verification_code')) and formdata.verification_code == code:
form_status = wcs.forms.root.PublicFormStatusPage(self.formdef, formdata)
'<p>'
_('The following ballot has been recorded:')
'</p>'
form_status.receipt(show_status=False, show_signature=False, form_url=None)
r += htmltext('<p>')
r += _('The following ballot has been recorded:')
r += htmltext('</p>')
r += form_status.receipt(show_status=False, show_signature=False, form_url=None)
break
else:
'<p>'
_('No ballot has been found with such a verification code.')
'</p>'
r += htmltext('<p>')
r += _('No ballot has been found with such a verification code.')
r += htmltext('</p>')
return r.getvalue()
def listing [html] (self):
def listing(self):
if not str(self.formdef.workflow_id).endswith(str('+anonymous')):
raise errors.TraversalError()
wcs.forms.root.html_top(self.formdef.name)
import anonymity
'<ul>'
r += htmltext('<ul>')
for code in anonymity.get_verification_codes(self.formdef):
'<li><a href="check?code=%s">%s</a></li>' % (code, code)
'</ul>'
r += htmltext('<li><a href="check?code=%s">%s</a></li>') % (code, code)
r += htmltext('</ul>')
return r.getvalue()
class FormPage(wcs.forms.root.FormPage):
@ -187,17 +195,19 @@ class FormPage(wcs.forms.root.FormPage):
except AlreadyVotedError:
return self.already_voted_error()
def expired [html] (self):
def expired(self):
wcs.forms.root.html_top(self.formdef.name)
TextsDirectory.get_html_text('asec-expired-site-questionnaire')
return TextsDirectory.get_html_text('asec-expired-site-questionnaire')
def soon_available [html] (self):
def soon_available(self):
wcs.forms.root.html_top(self.formdef.name)
'<div id="access-asec-identify">'
TextsDirectory.get_html_text('asec-soon-available')
'</div>'
r = TemplateIO(html=True)
r += htmltext('<div id="access-asec-identify">')
r += TextsDirectory.get_html_text('asec-soon-available')
r += htmltext('</div>')
return r.getvalue()
def participant_ask_token [html] (self):
def participant_ask_token(self):
form = Form(enctype='multipart/form-data')
form.add(EmailWidget, 'email', title=_('Email'), required=True)
if self.formdef.access_as_password:
@ -220,26 +230,28 @@ class FormPage(wcs.forms.root.FormPage):
form_reminder.clear_errors()
wcs.forms.root.html_top(self.formdef.name)
r = TemplateIO(html=True)
'<div id="access-asec">'
get_session().display_message()
r += htmltext('<div id="access-asec">')
r += get_session().display_message()
'<div id="access-asec-identify">'
r += htmltext('<div id="access-asec-identify">')
if self.formdef.asec_status == 'soon-available':
TextsDirectory.get_html_text('asec-soon-available')
r += TextsDirectory.get_html_text('asec-soon-available')
else:
TextsDirectory.get_html_text('asec-please-identify')
form.render()
'</div>'
r += TextsDirectory.get_html_text('asec-please-identify')
r += form.render()
r += htmltext('</div>')
'<div id="access-asec-reminder">'
'<h3>%s</h3>' % _('Lost or forgotten access code?')
'<p>'
_('Please enter your e-mail address to get a new access code sent to you.')
'</p>'
form_reminder.render()
'</div>'
'</div> <!-- #access-asec -->'
r += htmltext('<div id="access-asec-reminder">')
r += htmltext('<h3>%s</h3>') % _('Lost or forgotten access code?')
r += htmltext('<p>')
r += _('Please enter your e-mail address to get a new access code sent to you.')
r += htmltext('</p>')
r += form_reminder.render()
r += htmltext('</div>')
r += htmltext('</div> <!-- #access-asec -->')
return r.getvalue()
def participant_ask_token_submit(self, form):
email = form.get_widget('email').parse()
@ -300,9 +312,9 @@ class FormPage(wcs.forms.root.FormPage):
return redirect('.')
def already_voted_error [html] (self):
def already_voted_error(self):
wcs.forms.root.html_top(self.formdef.name)
TextsDirectory.get_html_text('asec-already-voted')
return TextsDirectory.get_html_text('asec-already-voted')
TextsDirectory.register('asec-already-voted',

View File

@ -19,6 +19,7 @@ import os
from quixote import get_publisher, get_request, get_response, redirect
from quixote.directory import Directory
from quixote.util import StaticDirectory
from quixote.html import TemplateIO, htmltext
from qommon.admin.texts import TextsDirectory
from qommon import template
@ -83,7 +84,7 @@ class RootDirectory(wcs.root.RootDirectory):
return TextsDirectory.get_html_text('asec-locked-site')
return Directory._q_traverse(self, path)
def _q_index [html] (self):
def _q_index(self):
template.html_top()
formdefs = FormDef.select(order_by='name', ignore_errors=True)
@ -91,26 +92,28 @@ class RootDirectory(wcs.root.RootDirectory):
if quota.is_expired():
return self.index_expired()
r = TemplateIO(html=True)
if len(formdefs) == 0:
TextsDirectory.get_html_text('asec-welcome-empty-site')
r += TextsDirectory.get_html_text('asec-welcome-empty-site')
else:
if get_request().user:
TextsDirectory.get_html_text('welcome-logged')
r += TextsDirectory.get_html_text('welcome-logged')
else:
TextsDirectory.get_html_text('welcome-unlogged')
r += TextsDirectory.get_html_text('welcome-unlogged')
'<ul>'
r += htmltext('<ul>')
for formdef in formdefs:
if formdef.disabled:
continue
if formdef.private:
continue
'<li><a href="%s/">%s</a></li>' % (formdef.url_name, formdef.name)
'</ul>'
r += htmltext('<li><a href="%s/">%s</a></li>') % (formdef.url_name, formdef.name)
r += htmltext('</ul>')
return r.getvalue()
def index_expired [html] (self):
def index_expired(self):
template.html_top()
TextsDirectory.get_html_text('asec-expired-site-homepage')
return TextsDirectory.get_html_text('asec-expired-site-homepage')
def _q_lookup(self, component):
if component in ('css','images'):