From 1bb0330ab5e27eb1e63532cc4facd30d5408c8d6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 3 Aug 2019 16:57:13 -0500 Subject: [PATCH] Refactory Buefy templates to use WholePage and ThisPage components plus add `GridFilter.set_choices()` method --- tailbone/grids/core.py | 5 +- tailbone/grids/filters.py | 22 ++ tailbone/static/js/tailbone.buefy.grid.js | 6 - tailbone/templates/about.mako | 21 +- tailbone/templates/appsettings.mako | 260 +++++++++--------- tailbone/templates/batch/index.mako | 32 ++- tailbone/templates/batch/view.mako | 12 +- tailbone/templates/change_password.mako | 13 +- .../templates/datasync/changes/index.mako | 4 +- tailbone/templates/departments/view.mako | 25 +- tailbone/templates/email-bounces/view.mako | 40 ++- tailbone/templates/form.mako | 8 +- tailbone/templates/home.mako | 15 +- tailbone/templates/labels/profiles/view.mako | 35 ++- tailbone/templates/login.mako | 21 +- tailbone/templates/master/clone.mako | 4 +- tailbone/templates/master/delete.mako | 4 +- tailbone/templates/master/form.mako | 4 +- tailbone/templates/master/index.mako | 84 +++--- tailbone/templates/master/merge.mako | 129 ++++----- tailbone/templates/master/versions.mako | 11 +- tailbone/templates/master/view.mako | 8 +- tailbone/templates/master/view_version.mako | 7 +- tailbone/templates/messages/view.mako | 23 +- tailbone/templates/page.mako | 39 ++- tailbone/templates/people/view.mako | 47 +++- .../templates/principal/find_by_perm.mako | 259 ++++++++--------- tailbone/templates/reports/choose.mako | 26 +- tailbone/templates/roles/view.mako | 31 ++- tailbone/templates/settings/email/view.mako | 136 ++++----- tailbone/templates/tempmon/probes/create.mako | 4 +- tailbone/templates/tempmon/probes/graph.mako | 4 +- tailbone/templates/themes/falafel/base.mako | 66 +++++ tailbone/templates/upgrades/view.mako | 4 +- tailbone/views/bouncer.py | 6 +- tailbone/views/people.py | 4 +- 36 files changed, 806 insertions(+), 613 deletions(-) diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index 7c71ca0e..8f6e45df 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -1003,7 +1003,10 @@ class Grid(object): choices = [] choice_labels = {} - if self.enums and filtr.key in self.enums: + if filtr.choices: + choices = list(filtr.choices) + choices_labels = dict(filtr.choices) + elif self.enums and filtr.key in self.enums: choices = list(self.enums[filtr.key]) choice_labels = self.enums[filtr.key] diff --git a/tailbone/grids/filters.py b/tailbone/grids/filters.py index f6740623..0014c750 100644 --- a/tailbone/grids/filters.py +++ b/tailbone/grids/filters.py @@ -149,6 +149,7 @@ class GridFilter(object): value_renderer_factory = DefaultValueRenderer data_type = 'string' # default, but will be set from value renderer + choices = {} def __init__(self, key, label=None, verbs=None, value_enum=None, value_renderer=None, default_active=False, default_verb=None, default_value=None, @@ -187,6 +188,27 @@ class GridFilter(object): return verbs return ['equal', 'not_equal', 'is_null', 'is_not_null', 'is_any'] + def set_choices(self, choices): + """ + Set the value choices for the filter, post-construction. Note that + this also will set the value renderer to one which supports choices. + """ + # first must normalize choices + if isinstance(choices, OrderedDict): + normalized = choices + elif isinstance(choices, dict): + normalized = OrderedDict([ + (key, choices[value]) + for key in sorted(choices)]) + elif isinstance(choices, list): + normalized = OrderedDict([ + (key, key) + for key in choices]) + + # store normalized choices, and set renderer + self.choices = normalized + self.set_value_renderer(ChoiceValueRenderer(self.choices)) + def set_value_renderer(self, renderer): """ Set the value renderer for the filter, post-construction. diff --git a/tailbone/static/js/tailbone.buefy.grid.js b/tailbone/static/js/tailbone.buefy.grid.js index 36790feb..13fb8f00 100644 --- a/tailbone/static/js/tailbone.buefy.grid.js +++ b/tailbone/static/js/tailbone.buefy.grid.js @@ -174,9 +174,3 @@ let TailboneGrid = { } } } - - -let GridPage = { - template: '#grid-page-template', - methods: {} -} diff --git a/tailbone/templates/about.mako b/tailbone/templates/about.mako index 8c0bd67a..ef27c19c 100644 --- a/tailbone/templates/about.mako +++ b/tailbone/templates/about.mako @@ -1,14 +1,19 @@ -## -*- coding: utf-8 -*- -<%inherit file="/base.mako" /> +## -*- coding: utf-8; -*- +<%inherit file="/page.mako" /> <%namespace name="base_meta" file="/base_meta.mako" /> <%def name="title()">About ${base_meta.app_title()} -

${project_title} ${project_version}

+<%def name="page_content()"> +

${project_title} ${project_version}

-% for name, version in packages.items(): -

${name} ${version}

-% endfor + % for name, version in packages.items(): +

${name} ${version}

+ % endfor -
-

Please see rattailproject.org for more info.

+
+

Please see rattailproject.org for more info.

+ + + +${parent.body()} diff --git a/tailbone/templates/appsettings.mako b/tailbone/templates/appsettings.mako index 983f679b..36783c69 100644 --- a/tailbone/templates/appsettings.mako +++ b/tailbone/templates/appsettings.mako @@ -1,5 +1,5 @@ ## -*- coding: utf-8; -*- -<%inherit file="/base.mako" /> +<%inherit file="/page.mako" /> <%def name="title()">App Settings @@ -33,150 +33,164 @@ % endif +<%def name="context_menu_items()"> + % if request.has_perm('settings.list'): +
  • ${h.link_to("View Raw Settings", url('settings'))}
  • + % endif + -% if use_buefy: - - -
    - + ${h.end_form()}
    + + - + - +<%def name="make_this_page_component()"> + ${parent.make_this_page_component()} + + + + +% if use_buefy: + ${parent.body()} % else: ## legacy / not buefy diff --git a/tailbone/templates/batch/index.mako b/tailbone/templates/batch/index.mako index 1bae4f37..3de15c87 100644 --- a/tailbone/templates/batch/index.mako +++ b/tailbone/templates/batch/index.mako @@ -107,19 +107,15 @@ % endif -<%def name="modify_tailbone_grid()"> - ${parent.modify_tailbone_grid()} +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} % if master.results_executable and request.has_perm('{}.execute_multiple'.format(permission_prefix)): + % endif + + +<%def name="render_this_page_template()"> + ${parent.render_this_page_template()} + % if master.results_executable and request.has_perm('{}.execute_multiple'.format(permission_prefix)): + ${execute_form.render_deform(form_kwargs={'ref': 'actualForm'}, buttons=False)|n} + % endif + -% if use_buefy: - % if master.results_executable and request.has_perm('{}.execute_multiple'.format(permission_prefix)): - ${execute_form.render_deform(form_kwargs={'ref': 'actualForm'}, buttons=False)|n} - % endif -% endif ${parent.body()} diff --git a/tailbone/templates/batch/view.mako b/tailbone/templates/batch/view.mako index aa87f408..aacc756c 100644 --- a/tailbone/templates/batch/view.mako +++ b/tailbone/templates/batch/view.mako @@ -187,16 +187,16 @@ % endif -<%def name="render_this_page_buefy()"> +<%def name="render_this_page_template()"> + ${parent.render_this_page_template()} % if use_buefy and master.handler.executable(batch) and request.has_perm('{}.execute'.format(permission_prefix)): ## TODO: stop using |n filter ${execute_form.render_deform(buttons=capture(execute_submit_button), form_kwargs={'@submit': 'submitExecuteForm'})|n} % endif - ${parent.render_this_page_buefy()} -<%def name="modify_this_page()"> - ${parent.modify_this_page()} +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} % if not batch.executed and request.has_perm('{}.execute'.format(permission_prefix)): +<%def name="extra_styles()"> + ${parent.extra_styles()} + + + <%def name="context_menu_items()"> ${parent.context_menu_items()} % if not bounce.processed and request.has_perm('emailbounces.process'): @@ -43,8 +49,12 @@ % endif -${parent.body()} +<%def name="page_content()"> + ${parent.page_content()} +
    +  ${message}
    +  
    + -
    -${message}
    -
    + +${parent.body()} diff --git a/tailbone/templates/form.mako b/tailbone/templates/form.mako index 0a2dbd0f..6a89b048 100644 --- a/tailbone/templates/form.mako +++ b/tailbone/templates/form.mako @@ -45,15 +45,15 @@ -<%def name="render_this_page_buefy()"> +<%def name="render_this_page_template()"> % if form is not Underined: ${self.render_form()} % endif - ${parent.render_this_page_buefy()} + ${parent.render_this_page_template()} -<%def name="finalize_page_components()"> - ${parent.finalize_page_components()} +<%def name="finalize_this_page_vars()"> + ${parent.finalize_this_page_vars()} % if form is not Undefined: - - -<%def name="make_tailbone_grid_app()"> - ${self.modify_tailbone_grid()} - + - Vue.component('grid-page', GridPage) +<%def name="make_this_page_component()"> + ${parent.make_this_page_component()} + +<%def name="render_this_page()"> + ${self.page_content()} + + +<%def name="render_this_page_template()"> + ${parent.render_this_page_template()} + + ## TODO: stop using |n filter + ${grid.render_buefy(tools=capture(self.grid_tools).strip(), context_menu=capture(self.context_menu_items).strip())|n} + + % if use_buefy: - ## TODO: stop using |n filter - ${grid.render_buefy(tools=capture(self.grid_tools).strip(), context_menu=capture(self.context_menu_items).strip())|n} - - - -
    - -
    - - ${self.make_tailbone_grid_app()} + ${parent.body()} % else: ## no buefy, so do the traditional thing diff --git a/tailbone/templates/master/merge.mako b/tailbone/templates/master/merge.mako index 086b4d1a..8924fcd0 100644 --- a/tailbone/templates/master/merge.mako +++ b/tailbone/templates/master/merge.mako @@ -154,75 +154,80 @@ ${h.end_form()} % endif +<%def name="render_this_page_template()"> + ${parent.render_this_page_template()} -% if use_buefy: - + + - + - -% endif ${parent.body()} diff --git a/tailbone/templates/master/versions.mako b/tailbone/templates/master/versions.mako index b20b7a4e..ccd0c6b8 100644 --- a/tailbone/templates/master/versions.mako +++ b/tailbone/templates/master/versions.mako @@ -4,7 +4,9 @@ ## Default master 'versions' template, for showing an object's version history. ## ## ############################################################################## -<%inherit file="/base.mako" /> +<%inherit file="/page.mako" /> + +## TODO: this page still uses old-style grid but should use Buefy grid <%def name="title()">${model_title_plural} » ${instance_title} » history @@ -21,4 +23,9 @@ History for ${instance_title} -${grid.render_complete()|n} +<%def name="page_content()"> + ${grid.render_complete()|n} + + + +${parent.body()} diff --git a/tailbone/templates/master/view.mako b/tailbone/templates/master/view.mako index e6ed6c63..1f4b59ee 100644 --- a/tailbone/templates/master/view.mako +++ b/tailbone/templates/master/view.mako @@ -93,15 +93,15 @@ % endif -<%def name="render_this_page_buefy()"> +<%def name="render_this_page_template()"> % if master.has_rows: ## TODO: stop using |n filter ${rows_grid.render_buefy(allow_save_defaults=False, tools=capture(self.render_row_grid_tools))|n} % endif - ${parent.render_this_page_buefy()} + ${parent.render_this_page_template()} -<%def name="make_this_page_app()"> +<%def name="make_this_page_component()"> - ${parent.make_this_page_app()} + ${parent.make_this_page_component()} diff --git a/tailbone/templates/master/view_version.mako b/tailbone/templates/master/view_version.mako index 0980235d..68c76c6d 100644 --- a/tailbone/templates/master/view_version.mako +++ b/tailbone/templates/master/view_version.mako @@ -1,8 +1,9 @@ ## -*- coding: utf-8; -*- -<%inherit file="/base.mako" /> +<%inherit file="/page.mako" /> <%def name="title()">${instance_title_normal} @ ver ${transaction.id} +<%def name="page_content()"> ## TODO: this was basically copied from Revel diff template..need to abstract
    @@ -97,3 +98,7 @@ % endif % endfor + + + +${parent.body()} diff --git a/tailbone/templates/messages/view.mako b/tailbone/templates/messages/view.mako index 2d14d4d8..5bab5a4b 100644 --- a/tailbone/templates/messages/view.mako +++ b/tailbone/templates/messages/view.mako @@ -1,4 +1,4 @@ -## -*- coding: utf-8 -*- +## -*- coding: utf-8; -*- <%inherit file="/master/view.mako" /> <%def name="extra_javascript()"> @@ -87,12 +87,17 @@ ${instance.body} +<%def name="page_content()"> + ${parent.page_content()} + + ${self.message_tools()} + +
    + ${self.message_body()} +
    + + ${self.message_tools()} + + + ${parent.body()} - -${self.message_tools()} - -
    - ${self.message_body()} -
    - -${self.message_tools()} diff --git a/tailbone/templates/page.mako b/tailbone/templates/page.mako index 0510b699..14c8b1a6 100644 --- a/tailbone/templates/page.mako +++ b/tailbone/templates/page.mako @@ -6,9 +6,9 @@ <%def name="page_content()"> <%def name="render_this_page()"> -
    +
    -
    +
    ${self.page_content()}
    @@ -19,23 +19,15 @@
    -<%def name="render_this_page_buefy()"> +<%def name="render_this_page_template()"> - -
    - -
    -<%def name="modify_this_page()"> - ## NOTE: if you override this, must use -<%def name="finalize_page_components()"> +<%def name="modify_this_page_vars()"> ## NOTE: if you override this, must use % if use_buefy: - ${self.render_this_page_buefy()} - ${self.make_this_page_app()} + ${self.render_this_page_template()} + ${self.make_this_page_component()} % else: ${self.render_this_page()} % endif diff --git a/tailbone/templates/people/view.mako b/tailbone/templates/people/view.mako index 78eaec41..50804392 100644 --- a/tailbone/templates/people/view.mako +++ b/tailbone/templates/people/view.mako @@ -4,7 +4,7 @@ <%def name="extra_javascript()"> ${parent.extra_javascript()} - % if not instance.users and request.has_perm('users.create'): + % if not use_buefy and not instance.users and request.has_perm('users.create'): + + +<%def name="page_content()"> + ${parent.page_content()} + % if not instance.users and request.has_perm('users.create'): + % if use_buefy: + ${h.form(url('people.make_user'), ref='makeUserForm')} + % else: + ${h.form(url('people.make_user'), name='make-user-form')} + % endif + ${h.csrf_token(request)} + ${h.hidden('person_uuid', value=instance.uuid)} + ${h.end_form()} + % endif + + + ${parent.body()} -## TODO: should do this differently for Buefy themes -% if not instance.users and request.has_perm('users.create'): - ${h.form(url('people.make_user'), name='make-user-form')} - ${h.csrf_token(request)} - ${h.hidden('person_uuid', value=instance.uuid)} - ${h.end_form()} -% endif diff --git a/tailbone/templates/principal/find_by_perm.mako b/tailbone/templates/principal/find_by_perm.mako index c70aeacf..f055ce5d 100644 --- a/tailbone/templates/principal/find_by_perm.mako +++ b/tailbone/templates/principal/find_by_perm.mako @@ -1,5 +1,5 @@ ## -*- coding: utf-8; -*- -<%inherit file="/base.mako" /> +<%inherit file="/page.mako" /> <%def name="title()">Find ${model_title_plural} by Permission @@ -46,144 +46,149 @@ % endif +<%def name="page_content()"> + % if use_buefy: + + + % else: + ## not buefy + ${h.form(request.current_route_url(), id='find-by-perm-form')} + ${h.csrf_token(request)} -% if not use_buefy: -${h.form(request.current_route_url(), id='find-by-perm-form')} -${h.csrf_token(request)} - -
    - ${self.wtfield(form, 'permission_group')} - ${self.wtfield(form, 'permission')} -
    - ${h.submit('submit', "Find {}".format(model_title_plural))} -
    -
    - -${h.end_form()} - -% if principals is not None: -
    -
    -

    ${model_title_plural} with that permission (${len(principals)} total):

    - ${self.principal_table()} -
    -% endif - - -% else: -## use_buefy! - -
    - - -
    - - +
    + +
    + + + +
    +
    - + - submitForm() { - this.formSubmitting = true - this.formButtonText = "Working, please wait..." - } - } - }) +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} + -% endif + + + +<%def name="make_this_page_component()"> + ${parent.make_this_page_component()} + + + + +${parent.body()} diff --git a/tailbone/templates/reports/choose.mako b/tailbone/templates/reports/choose.mako index f6cf7d9c..35e6d90e 100644 --- a/tailbone/templates/reports/choose.mako +++ b/tailbone/templates/reports/choose.mako @@ -1,5 +1,5 @@ ## -*- coding: utf-8; -*- -<%inherit file="/base.mako" /> +<%inherit file="/page.mako" /> <%def name="title()">${index_title} @@ -56,19 +56,17 @@ % endif - -
    - +<%def name="page_content()"> % if use_form: -
    -

    Please select the type of report you wish to generate.

    +
    +

    Please select the type of report you wish to generate.

    -
    - ${form.render()|n} -
    -
    +
    + ${form.render()|n} +
    +
    -
    +
    % else:

    Please select the type of report you wish to generate.

    @@ -81,9 +79,7 @@
    % endif + -
      - ${self.context_menu_items()} -
    -
    +${parent.body()} diff --git a/tailbone/templates/roles/view.mako b/tailbone/templates/roles/view.mako index 3589ca41..ab3b49df 100644 --- a/tailbone/templates/roles/view.mako +++ b/tailbone/templates/roles/view.mako @@ -6,17 +6,22 @@ ${h.stylesheet_link(request.static_url('tailbone:static/css/perms.css'))} +<%def name="page_content()"> + ${parent.page_content()} + +

    Users

    + + % if instance is guest_role: +

    The guest role is implied for all anonymous users, i.e. when not logged in.

    + % elif instance is authenticated_role: +

    The authenticated role is implied for all users, but only when logged in.

    + % elif users: +

    The following users are assigned to this role:

    + ${users.render_grid()|n} + % else: +

    There are no users assigned to this role.

    + % endif + + + ${parent.body()} - -

    Users

    - -% if instance is guest_role: -

    The guest role is implied for all anonymous users, i.e. when not logged in.

    -% elif instance is authenticated_role: -

    The authenticated role is implied for all users, but only when logged in.

    -% elif users: -

    The following users are assigned to this role:

    - ${users.render_grid()|n} -% else: -

    There are no users assigned to this role.

    -% endif diff --git a/tailbone/templates/settings/email/view.mako b/tailbone/templates/settings/email/view.mako index 35b06ed4..1b527ec4 100644 --- a/tailbone/templates/settings/email/view.mako +++ b/tailbone/templates/settings/email/view.mako @@ -41,94 +41,96 @@ +<%def name="render_this_page_template()"> + ${parent.render_this_page_template()} + +
    - + - const EmailPreviewTools = { - template: '#email-preview-tools-template', - data() { - return { - previewFormButtonText: "Send Preview Email", - previewFormSubmitting: false, - } - }, - methods: { - submitPreviewForm() { - this.previewFormSubmitting = true - this.previewFormButtonText = "Working, please wait..." - } - } - } +<%def name="make_this_page_component()"> + ${parent.make_this_page_component()} + + Vue.component('email-preview-tools', EmailPreviewTools) + + + -% endif ${parent.body()} diff --git a/tailbone/templates/tempmon/probes/create.mako b/tailbone/templates/tempmon/probes/create.mako index 95dbd3d6..062997d7 100644 --- a/tailbone/templates/tempmon/probes/create.mako +++ b/tailbone/templates/tempmon/probes/create.mako @@ -1,8 +1,8 @@ ## -*- coding: utf-8 -*- <%inherit file="/master/create.mako" /> -<%def name="head_tags()"> - ${parent.head_tags()} +<%def name="extra_javascript()"> + ${parent.extra_javascript()} + + +<%def name="declare_whole_page_vars()"> + + + +<%def name="modify_whole_page_vars()"> + ## NOTE: if you override this, must use + + +<%def name="make_whole_page_app()"> + + + <%def name="wtfield(form, name, **kwargs)">
    diff --git a/tailbone/templates/upgrades/view.mako b/tailbone/templates/upgrades/view.mako index 28ea42b3..03fd9b6b 100644 --- a/tailbone/templates/upgrades/view.mako +++ b/tailbone/templates/upgrades/view.mako @@ -67,8 +67,8 @@ % endif -<%def name="modify_this_page()"> - ${parent.modify_this_page()} +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()}