From fda091677f8e61b1b09df14740a616b637f43d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 8 Jan 2015 20:04:42 +0100 Subject: [PATCH] convert .ptl to .py files --- .../modules/{backoffice.ptl => backoffice.py} | 77 ++-- extra/modules/{boconfig.ptl => boconfig.py} | 100 ++--- .../{bodiffusion.ptl => bodiffusion.py} | 364 ++++++++++-------- extra/modules/{boforms.ptl => boforms.py} | 160 ++++---- extra/modules/{boresults.ptl => boresults.py} | 142 +++---- extra/modules/{forms.ptl => forms.py} | 120 +++--- extra/modules/{root.ptl => root.py} | 21 +- 7 files changed, 537 insertions(+), 447 deletions(-) rename extra/modules/{backoffice.ptl => backoffice.py} (79%) rename extra/modules/{boconfig.ptl => boconfig.py} (80%) rename extra/modules/{bodiffusion.ptl => bodiffusion.py} (78%) rename extra/modules/{boforms.ptl => boforms.py} (74%) rename extra/modules/{boresults.ptl => boresults.py} (71%) rename extra/modules/{forms.ptl => forms.py} (77%) rename extra/modules/{root.ptl => root.py} (89%) diff --git a/extra/modules/backoffice.ptl b/extra/modules/backoffice.py similarity index 79% rename from extra/modules/backoffice.ptl rename to extra/modules/backoffice.py index f219479..9aaadb7 100644 --- a/extra/modules/backoffice.ptl +++ b/extra/modules/backoffice.py @@ -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/' - '') + 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: - '

%s

' % _('Existing Questionnaires') + r += htmltext('

%s

') % _('Existing Questionnaires') - '') if quota.may_add_a_new_form(): - '

%s

' % _('New Questionnaire') + r += htmltext('

%s

') % _('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']) - '
' - '

%s

' % _('Your Profile') + r = TemplateIO(html=True) + r += htmltext('
') + r += htmltext('

%s

') % _('Your Profile') # TODO: possiblity to create additional administrator accounts? - '
    ' - '
  • %s
  • ' % _('Contact Information') - '
  • %s
  • ' % _('Password Change') - '
' - '
' + r += htmltext('') + r += htmltext('
') - '
' - '

%s

' % _('Site Settings') + r += htmltext('
') + r += htmltext('

%s

') % _('Site Settings') - '
    ' - '
  • %s
  • ' % _('Title') - '
  • %s
  • ' % _('Welcome Text') - '
  • %s
  • ' % _('End Text') + r += htmltext('
      ') + r += htmltext('
    • %s
    • ') % _('Title') + r += htmltext('
    • %s
    • ') % _('Welcome Text') + r += htmltext('
    • %s
    • ') % _('End Text') if quota.can_logo() or quota.can_theme(): - '
    • %s
    • ' % _('Appearance') - '
    ' - '
' + r += htmltext('
  • %s
  • ') % _('Appearance') + r += htmltext('') + r += htmltext('
    ') + return r.getvalue() def new(self): if not quota.may_add_a_new_form(): diff --git a/extra/modules/boconfig.ptl b/extra/modules/boconfig.py similarity index 80% rename from extra/modules/boconfig.ptl rename to extra/modules/boconfig.py index efd29e3..1be9c13 100644 --- a/extra/modules/boconfig.ptl +++ b/extra/modules/boconfig.py @@ -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')) - '

    %s

    ' % _('Contact Information') - form.render() + r += htmltext('

    %s

    ') % _('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')) - '

    %s

    ' % _('Password Change') - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('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')) - '

    %s

    ' % _('Site Title') - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('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')) - '

    %s

    ' % _('Home Page Text') - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('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(): - "

    %s

    " % _('Appearance') - self.appearance_theme() + r += htmltext("

    %s

    ") % _('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') - '
    ' + r = TemplateIO(html=True) + r += htmltext('
    ') - '

    ' - _('Click on a thumbnail to change the appearance of your site.') - '

    ' + r += htmltext('

    ') + r += _('Click on a thumbnail to change the appearance of your site.') + r += htmltext('

    ') 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 = '' - '
    ' % active - '' % theme - '' % theme - '' - '
    ' - '
    ' - '
    ' + r += htmltext('
    ') % active + r += htmltext('') % theme + r += htmltext('') % theme + r += htmltext('') + r += htmltext('
    ') + r += htmltext('
    ') + r += htmltext('
    ') + return r.getvalue() - def appearance_logo [html] (self): - '
    ' - '

    %s

    ' % _('Logo') - - get_session().display_message() + def appearance_logo(self): + r = TemplateIO(html=True) + r += htmltext('
    ') + r += htmltext('

    %s

    ') % _('Logo') + r += get_session().display_message() logo_url = get_logo_url() if logo_url: - '' % logo_url + r += htmltext('') % logo_url - '
    ' - '' + r += htmltext('') + r += htmltext('') if logo_url: - '' % _('Upload New Logo') - '' % _('Remove Current Logo') + r += htmltext('') % _('Upload New Logo') + r += htmltext('') % _('Remove Current Logo') else: - '' % _('Upload Logo') - '
    ' - '
    ' - + r += htmltext('') % _('Upload Logo') + r += htmltext('') + r += htmltext('
    ') + return r.getvalue() def logo(self): if not quota.can_logo(): diff --git a/extra/modules/bodiffusion.ptl b/extra/modules/bodiffusion.py similarity index 78% rename from extra/modules/bodiffusion.ptl rename to extra/modules/bodiffusion.py index b98409e..6a4da24 100644 --- a/extra/modules/bodiffusion.ptl +++ b/extra/modules/bodiffusion.py @@ -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')) - '

    %s

    ' % _('Sender Address') - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('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')) - '

    %s

    ' % _('Sender Address') - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('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) - '' + r += htmltext('') - '

    %s

    ' % _('Diffusion') + r += htmltext('

    %s

    ') % _('Diffusion') - '') 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 - '

    ' - _('%s participants.') % len(user_ids) + r += htmltext('

    ') + r += _('%s participants.') % len(user_ids) if search_result: - ' %s' % _('Back to full listing') - '

    ' + r += htmltext(' %s') % _('Back to full listing') + r += htmltext('

    ') 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 - '
    ' - '') + r += htmltext('
    ') + r += htmltext('
    ') + r += htmltext('') + r += htmltext('
    ') # XXX: add pagination elif user_ids is None: # unknown set - '

    ' - _('Unable to get a list of participants.') - ' ' - _('System overloaded?') + r += htmltext('

    ') + r += _('Unable to get a list of participants.') + r += ' ' + r += _('System overloaded?') # XXX: + use search form on the right. - '

    ' + r += htmltext('

    ') else: - '

    ' + r += htmltext('

    ') 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.') - '

    ' + r += _('There is currently no participants defined.') + r += htmltext('

    ') + return r.getvalue() - def get_sidebar [html] (self): + def get_sidebar(self): if not self.objectdef.roles: return '' - '') - '

    %s

    ' % _('Search a participant') + r += htmltext('

    %s

    ') % _('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')) - '

    %s

    ' % _('Importing a List of Participants') - '

    ' - _('The file should be in the CSV file format. Using your spreadsheet '\ - 'program (Calc, Excel...), click "Save as" and select the CSV format.') - '

    ' - '

    ' - _('The file should have email addresses in the first column, and, '\ - 'optionnaly, names in the second column.') - '

    ' - get_session().display_message() - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('Importing a List of Participants') + r += htmltext('

    ') + 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('

    ') + r += htmltext('

    ') + r += _('The file should have email addresses in the first column, and, '\ + 'optionnaly, names in the second column.') + r += htmltext('

    ') + 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']) - '
    ' - '
    ' - _(job.label) - '
    ' - '
    ' - '' % job.id - _(job.status) - '' - '
    ' - '
    ' + r += htmltext('
    ') + r += htmltext('
    ') + r += _(job.label) + r += htmltext('
    ') + r += htmltext('
    ') + r += htmltext('') % job.id + r += _(job.status) + r += htmltext('') + r += htmltext('
    ') + r += htmltext('
    ') - '
    ' - '%s' % _('Back') - '
    ' + r += htmltext('
    ') + r += htmltext('%s') % _('Back') + r += htmltext('
    ') + 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')) - '

    %s

    ' % _('Mailing access codes') - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('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']) - '
    ' - '
    ' - _(job.label) - '
    ' - '
    ' - '' % job.id - _(job.status) - '' - '
    ' - '
    ' + r += htmltext('
    ') + r += htmltext('
    ') + r += _(job.label) + r += htmltext('
    ') + r += htmltext('
    ') + r += htmltext('') % job.id + r += _(job.status) + r += htmltext('') + r += htmltext('
    ') + r += htmltext('
    ') - '
    ' - '%s' % _('Back') - '
    ' + r += htmltext('
    ') + r += htmltext('%s') % _('Back') + r += htmltext('
    ') + 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')) - '

    %s

    ' % _('Importing a List of Participants to Disable') - '

    ' - _('The file should be in the CSV file format. Using your spreadsheet '\ - 'program (Calc, Excel...), click "Save as" and select the CSV format.') - '

    ' - '

    ' - _('The file should consist of email addresses, one per line.') - '

    ' - get_session().display_message() - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('Importing a List of Participants to Disable') + r += htmltext('

    ') + 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('

    ') + r += htmltext('

    ') + r += _('The file should consist of email addresses, one per line.') + r += htmltext('

    ') + 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']) - '
    ' - '
    ' - _(job.label) - '
    ' - '
    ' - '' % job.id - _(job.status) - '' - '
    ' - '
    ' + r += htmltext('
    ') + r += htmltext('
    ') + r += _(job.label) + r += htmltext('
    ') + r += htmltext('
    ') + r += htmltext('') % job.id + r += _(job.status) + r += htmltext('') + r += htmltext('
    ') + r += htmltext('
    ') - '
    ' - '%s' % _('Back') - '
    ' + r += htmltext('
    ') + r += htmltext('%s') % _('Back') + r += htmltext('
    ') + 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')) - '

    %s

    ' % _('Mailing participants') - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('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']) - '
    ' - '
    ' - _(job.label) - '
    ' - '
    ' - '' % job.id - _(job.status) - '' - '
    ' - '
    ' + r = TemplateIO(html=True) + r += htmltext('
    ') + r += htmltext('
    ') + r += _(job.label) + r += htmltext('
    ') + r += htmltext('
    ') + r += htmltext('') % job.id + r += _(job.status) + r += htmltext('') + r += htmltext('
    ') + r += htmltext('
    ') - '
    ' - '%s' % _('Back') - '
    ' + r += htmltext('
    ') + r += htmltext('%s') % _('Back') + r += htmltext('
    ') + return r.getvalue() EmailsDirectory.register('asec-voting-instructions', N_('Instructions and access codes'), diff --git a/extra/modules/boforms.ptl b/extra/modules/boforms.py similarity index 74% rename from extra/modules/boforms.ptl rename to extra/modules/boforms.py index 52758ad..0cc12e7 100644 --- a/extra/modules/boforms.ptl +++ b/extra/modules/boforms.py @@ -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('

    %s

    ' % _( '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')) - '

    %s %s

    ' % (_('Deleting Questionnaire:'), self.objectdef.name) - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s %s

    ') % (_('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() - '
    ' - form.render() - '
    ' + r += htmltext('
    ') + r += form.render() + r += htmltext('
    ') 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': - '

    %s

    ' % _('Visualisation & export of preliminary results') + r += htmltext('

    %s

    ') % _('Visualisation & export of preliminary results') else: - '

    %s

    ' % _('Visualisation & export of results') + r += htmltext('

    %s

    ') % _('Visualisation & export of results') - '') + 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): - '') - '

    %s

    ' % _('Design') - get_session().display_message() + r += htmltext('

    %s

    ') % _('Design') + r += get_session().display_message() - '') if not self.objectdef.fields: - '

    ' - _('There are not yet any fields for this questionnaire.') - '

    ' - '

    ' - _('You should use the controls at the right of the page to add fields.') - '

    ' + r += htmltext('

    ') + r += _('There are not yet any fields for this questionnaire.') + r += htmltext('

    ') + r += htmltext('

    ') + r += _('You should use the controls at the right of the page to add fields.') + r += htmltext('

    ') - '

    %s

    ' % _('Contents of your questionnaire') + r += htmltext('

    %s

    ') % _('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(): - '

    ' - '%s ' % _('Warning:') - _('This form already contains submitted items.') - ' ' - '%s' % _('Remove Them') - '

    ' + r += htmltext('

    ') + r += htmltext('%s ') % _('Warning:') + r += _('This form already contains submitted items.') + r += ' ' + r += htmltext('%s') % _('Remove Them') + r += htmltext('

    ') 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: - '

    ' - _('This questionnaire has reached its number of questions quota.') - '

    ' + r += htmltext('

    ') + r += _('This questionnaire has reached its number of questions quota.') + r += htmltext('

    ') + return r.getvalue() - def clean [html] (self): + def clean(self): form = Form(enctype='multipart/form-data') form.widgets.append(HtmlWidget('

    %s

    ' % _( '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')) - '

    %s

    ' % _('Options') - form.render() + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('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): diff --git a/extra/modules/boresults.ptl b/extra/modules/boresults.py similarity index 71% rename from extra/modules/boresults.ptl rename to extra/modules/boresults.py index 37abfcd..779099a 100644 --- a/extra/modules/boresults.ptl +++ b/extra/modules/boresults.py @@ -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')) - - '

    %s

    ' % _('Analysis') + r = TemplateIO(html=True) + r += htmltext('

    %s

    ') % _('Analysis') if self.formdef.asec_status == 'running': - '

    ' - _('The questionnaire is still running, this is therefore preliminary data.') - '

    ' + r += htmltext('

    ') + r += _('The questionnaire is still running, this is therefore preliminary data.') + r += htmltext('

    ') values = self.formdef.data_class().select() no_forms = len(values) - '

    %s %d

    ' % (_('Total number of records:'), no_forms) + r += htmltext('

    %s %d

    ') % (_('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=''): - '') + 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')) ) - '

    %s - %s

    ' % (self.formdef.name, _('Participation')) + r += htmltext('

    %s - %s

    ') % (self.formdef.name, _('Participation')) nb_users = 0 if self.formdef.roles: @@ -134,26 +139,27 @@ class FormResultDirectory(FormPage): continue nb_users += 1 - '') - '

    %s

    ' % _('List of participants') + r += htmltext('

    %s

    ') % _('List of participants') - '') + 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: - '

    %s

    ' % fields[0].label + r += htmltext('

    %s

    ') % fields[0].label else: - '

    %s

    ' % _('List of results') + r += htmltext('

    %s

    ') % _('List of results') - '
    ' + r += htmltext('
    ') 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: - '
    ' + r += htmltext('
    ') had_data = True if len(fields) > 1: - '

    %s ' % field.label - '' - value - '

    ' + r += htmltext('

    %s ') % field.label + r += htmltext('') + r += value + r += htmltext('

    ') if had_data: - '
    ' - '
    ' + r += htmltext('
    ') + r += htmltext('
    ') + 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')) ) - '

    %s

    ' % _('Table of results') + r += htmltext('

    %s

    ') % _('Table of results') - '' - '' + r += htmltext('
    ') + r += htmltext('') for field in fields: - '' % field.label - '' - '' + r += htmltext('') % field.label + r += htmltext('') + r += htmltext('') 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: - '' + r += htmltext('') had_data = True - '' + r += htmltext('') if had_data: - '' - '' - '
    %s
    %s
    ' - value - '') + r += value + r += htmltext('
    ' + r += htmltext('') + r += htmltext('') + r += htmltext('') + return r.getvalue() - def get_fields_sidebar [html] (self, fields): - '

    %s

    ' % _('Fields to display') - '
    ' - '
    ') + r += htmltext('') % _('Reload') + r += htmltext('') + return r.getvalue() def get_formdef_fields(self): fields = [] diff --git a/extra/modules/forms.ptl b/extra/modules/forms.py similarity index 77% rename from extra/modules/forms.ptl rename to extra/modules/forms.py index d01513b..c1929d4 100644 --- a/extra/modules/forms.ptl +++ b/extra/modules/forms.py @@ -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: - '' - '
    ' - '

    %s

    ' % last_page + r += htmltext('
    ') + r += htmltext('
    ') + r += htmltext('

    %s

    ') % last_page had_page = True last_page = None if last_title: - '

    %s

    ' % last_title + r += htmltext('

    %s

    ') % last_title last_title = None - t + r += t if had_page: - '
    ' + r += htmltext('') + 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 - '
    ' - '

    %s

    ' % _('Anonymous Verification Code Check') + r += htmltext('
    ') + r += htmltext('

    %s

    ') % _('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:') - ' %s' % _('complete listing') - '
    ' + r += form.render() + r += _('Or search for it in the list of all the ballots:') + r += htmltext(' %s') % _('complete listing') + r += htmltext('
    ') + 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): - '

    ' - _('No ballot has been found with such a verification code.') - '

    ' + r += htmltext('

    ') + r += _('No ballot has been found with such a verification code.') + r += htmltext('

    ') 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) - '

    ' - _('The following ballot has been recorded:') - '

    ' - form_status.receipt(show_status=False, show_signature=False, form_url=None) + r += htmltext('

    ') + r += _('The following ballot has been recorded:') + r += htmltext('

    ') + r += form_status.receipt(show_status=False, show_signature=False, form_url=None) break else: - '

    ' - _('No ballot has been found with such a verification code.') - '

    ' + r += htmltext('

    ') + r += _('No ballot has been found with such a verification code.') + r += htmltext('

    ') + 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 - '') + 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) - '
    ' - TextsDirectory.get_html_text('asec-soon-available') - '
    ' + r = TemplateIO(html=True) + r += htmltext('
    ') + r += TextsDirectory.get_html_text('asec-soon-available') + r += htmltext('
    ') + 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) - '
    ' - get_session().display_message() + r += htmltext('
    ') + r += get_session().display_message() - '
    ' + r += htmltext('
    ') 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() - '
    ' + r += TextsDirectory.get_html_text('asec-please-identify') + r += form.render() + r += htmltext('
    ') - '
    ' - '

    %s

    ' % _('Lost or forgotten access code?') - '

    ' - _('Please enter your e-mail address to get a new access code sent to you.') - '

    ' - form_reminder.render() - '
    ' - '
    ' + r += htmltext('
    ') + r += htmltext('

    %s

    ') % _('Lost or forgotten access code?') + r += htmltext('

    ') + r += _('Please enter your e-mail address to get a new access code sent to you.') + r += htmltext('

    ') + r += form_reminder.render() + r += htmltext('
    ') + r += htmltext('
    ') + 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', diff --git a/extra/modules/root.ptl b/extra/modules/root.py similarity index 89% rename from extra/modules/root.ptl rename to extra/modules/root.py index 9a3b3a3..96c9bbf 100644 --- a/extra/modules/root.ptl +++ b/extra/modules/root.py @@ -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') - '') + 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'):