From bab5d2f9b113d941e77c30cd5161660e4499a8eb Mon Sep 17 00:00:00 2001 From: Thorge Petersen <petersen@rz.uni-kiel.de> Date: Mon, 31 Jul 2023 12:27:43 +0200 Subject: [PATCH] Removed usage of c var where possible (wip) --- .../odsh/templates/organization/index.html | 51 +++++++++---------- .../templates/package/new_package_form.html | 38 +++++++------- ckanext/odsh/templates/package/read.html | 6 +-- .../odsh/templates/package/resource_edit.html | 2 +- ckanext/odsh/templates/package/search.html | 8 +-- .../package/snippets/package_form.html | 45 ++++++++-------- .../odsh/templates/snippets/search_box.html | 19 +++---- .../odsh/templates/user/edit_user_form.html | 2 +- ckanext/odsh/templates/user/login.html | 2 +- .../templates/user/snippets/login_form.html | 4 +- 10 files changed, 82 insertions(+), 95 deletions(-) diff --git a/ckanext/odsh/templates/organization/index.html b/ckanext/odsh/templates/organization/index.html index 48ff2e50..453cdc99 100644 --- a/ckanext/odsh/templates/organization/index.html +++ b/ckanext/odsh/templates/organization/index.html @@ -9,26 +9,25 @@ {% block page_header %}{% endblock %} {% block toolbar %} -{{ super() }} -<form id='organization-search-form' class="section site-search simple-input" method="get" data-module="select-switch"> -<div class='search-box-container'> - <div class='search-box'> - <div class="field"> - <input id="field-sitewide-search" type="text" name="q" value="{{c.q}}" placeholder="{{ _('Search organizations') }}" /> - <button class="btn-search" type="submit"> - </div> + {{ super() }} + <form id='organization-search-form' class="section site-search simple-input" method="get" data-module="select-switch"> + <div class='search-box-container'> + <div class='search-box'> + <div class="field"> + <input id="field-sitewide-search" type="text" name="q" value="{{q}}" placeholder="{{ _('Search organizations') }}" /> + <button class="btn-search" type="submit"> + </div> + </div> </div> -</div> {% endblock %} {% block page_primary_action %} {% endblock %} {% block primary %} -<div class="primary organization"> + <div class="primary organization"> {% if h.check_access('organization_create') %} - {% link_for _('Add Organization'), named_route='organization.new', class_='btn btn-primary', - icon='plus-square' %} + {% link_for _('Add Organization'), named_route='organization.new', class_='btn btn-primary', icon='plus-square' %} {% endif %} <h1 class="hide-heading">{% block page_heading %}{{ _('Organizations') }}{% endblock %}</h1> <div class="search-form"> @@ -37,28 +36,28 @@ {% endblock %} </div> {% block organizations_list %} - {% if c.page.items or request.args %} - {% if c.page.items %} - {% snippet "organization/snippets/odsh_organization_list.html", organizations=c.page.items %} - {% endif %} - {% else %} - <p class="empty"> - {{ _('There are currently no organizations for this site') }}. - {% if h.check_access('organization_create') %} - {% link_for _('How about creating one?'), named_route='organization.new' %}</a>. + {% if page.items or request.args %} + {% if page.items %} + {% snippet "organization/snippets/odsh_organization_list.html", organizations=c.page.items %} {% endif %} - </p> - {% endif %} + {% else %} + <p class="empty"> + {{ _('There are currently no organizations for this site') }}. + {% if h.check_access('organization_create') %} + {% link_for _('How about creating one?'), named_route='organization.new' %}</a>. + {% endif %} + </p> + {% endif %} {% endblock %} {% block page_pagination %} - {{ c.page.pager(q=c.q or '', sort=c.sort_by_selected or '') }} + {{ page.pager(q=q or '', sort=sort_by_selected or '') }} {% endblock %} -</div> + </div> {% endblock %} {% block secondary %} {% endblock %} {% block pre_wrap %} -</form> + </form> {% endblock %} \ No newline at end of file diff --git a/ckanext/odsh/templates/package/new_package_form.html b/ckanext/odsh/templates/package/new_package_form.html index 5d411f4b..891a455e 100644 --- a/ckanext/odsh/templates/package/new_package_form.html +++ b/ckanext/odsh/templates/package/new_package_form.html @@ -1,34 +1,30 @@ {% extends 'package/snippets/package_form.html' %} -{% set form_style = c.form_style or c.action %} - {% block stages %} -{% if form_style != 'edit' %} -<div class='search-form'> - <h2>{{ _('Create Dataset') }}</h2> -</div> -{{ super() }} -{% else %} - -{% endif %} + {% if form_style != 'edit' %} + <div class='search-form'> + <h2>{{ _('Create Dataset') }}</h2> + </div> + {{ super() }} + {% endif %} {% endblock %} {% block save_button_text %} -{% if form_style != 'edit' %} -{{ _('next') }} -{% else %} -{{ _('Update Dataset') }} -{% endif %} + {% if form_style != 'edit' %} + {{ _('next') }} + {% else %} + {{ _('Update Dataset') }} + {% endif %} {% endblock %} {% block cancel_button %} -{% if form_style != 'edit' %} -{{ super() }} -{% endif %} + {% if form_style != 'edit' %} + {{ super() }} + {% endif %} {% endblock %} {% block delete_button %} -{% if form_style == 'edit' and h.check_access('package_delete', {'id': pkg_dict.id}) %} -{{ super() }} -{% endif %} + {% if form_style == 'edit' and h.check_access('package_delete', {'id': pkg_dict.id}) %} + {{ super() }} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/ckanext/odsh/templates/package/read.html b/ckanext/odsh/templates/package/read.html index 448b05e1..dc955d8f 100644 --- a/ckanext/odsh/templates/package/read.html +++ b/ckanext/odsh/templates/package/read.html @@ -1,6 +1,6 @@ {% extends "package/read_base.html" %} -{% set pkg = c.pkg_dict %} +{% set pkg = pkg_dict %} {% set collection = h.get_collection(pkg) %} {% set collection_title = collection['title'] if collection else None %} {% set collection_url = collection['url'] if collection else None %} @@ -100,10 +100,10 @@ {% endblock package_description %} {% block package_resources %} -{% snippet "package/snippets/resources_list.html", pkg=pkg, resources=pkg.resources %} + {% snippet "package/snippets/resources_list.html", pkg=pkg, resources=pkg.resources %} {% if h.check_access('package_update', {'id':pkg.id }) %} <div class='add-resource-container'> - {% link_for _('Add new resource'), named_route='resource.new', id=c.pkg_dict.name, class_='btn btn-primary', icon='plus' %} + {% link_for _('Add new resource'), named_route='resource.new', id=pkg.name, class_='btn btn-primary', icon='plus' %} </div> {% endif %} {% endblock package_resources %} diff --git a/ckanext/odsh/templates/package/resource_edit.html b/ckanext/odsh/templates/package/resource_edit.html index e45c3f3e..7c1a93de 100644 --- a/ckanext/odsh/templates/package/resource_edit.html +++ b/ckanext/odsh/templates/package/resource_edit.html @@ -9,7 +9,7 @@ errors=errors, error_summary=error_summary, pkg_name=pkg.name, - form_action=c.form_action, + form_action=form_action, allow_upload=g.ofs_impl and logged_in, resource_form_snippet=resource_form_snippet, dataset_type=dataset_type %} diff --git a/ckanext/odsh/templates/package/search.html b/ckanext/odsh/templates/package/search.html index f99631a1..39b2b58d 100644 --- a/ckanext/odsh/templates/package/search.html +++ b/ckanext/odsh/templates/package/search.html @@ -31,12 +31,12 @@ method="get" data-module="select-switch"> {% endblock %} </div> {% block package_search_results_list %} - {{ h.snippet('snippets/package_list.html', packages=c.page.items) }} + {{ h.snippet('snippets/package_list.html', packages=page.items) }} {% endblock %} </div> {% block page_pagination %} - {{ c.page.pager(q=c.q,symbol_next='>') }} + {{ page.pager(q=q,symbol_next='>') }} {% endblock %} </section> @@ -57,8 +57,8 @@ method="get" data-module="select-switch"> <div class="filters"> <div> - {% for facet in c.facet_titles %} - {{ h.snippet('snippets/facet_list.html', title=c.facet_titles[facet], name=facet, search_facets=search_facets) }} + {% for facet in facet_titles %} + {{ h.snippet('snippets/facet_list.html', title=facet_titles[facet], name=facet, search_facets=search_facets) }} {% endfor %} </div> diff --git a/ckanext/odsh/templates/package/snippets/package_form.html b/ckanext/odsh/templates/package/snippets/package_form.html index c3c08cb4..91201618 100644 --- a/ckanext/odsh/templates/package/snippets/package_form.html +++ b/ckanext/odsh/templates/package/snippets/package_form.html @@ -1,12 +1,12 @@ {% import 'macros/form.html' as form %} -{% set action = c.form_action or '' %} -{% set form_style = c.form_style or c.action %} +{% set action = g.form_action or '' %} +{% set form_style = g.form_style or g.action %} <form id="dataset-edit" class="dataset-form {% if(form_style=='edit') %} dataset-edit-form {%endif%} " method="post" action="{{ action }}" data-module="basic-form" novalidate> {{ h.csrf_input() }} {% block stages %} - {{ h.snippet('package/snippets/stages.html', stages=stage) }} + {{ h.snippet('package/snippets/stages.html', stages=stage) }} {% endblock %} <input type="hidden" name="_ckan_phase" value="dataset_new_1" /> @@ -15,34 +15,33 @@ {# {% block errors %}{{ form.errors(error_summary) }}{% endblock %} #} {% block basic_fields %} - {% snippet 'package/snippets/package_basic_fields.html', data=data, errors=errors, licenses=c.licenses, - groups_available=c.groups_available %} + {% snippet 'package/snippets/package_basic_fields.html', data=data, errors=errors %} {% endblock %} {% block metadata_fields %} - {% snippet 'package/snippets/package_metadata_fields.html', data=data, errors=errors %} + {% snippet 'package/snippets/package_metadata_fields.html', data=data, errors=errors %} {% endblock %} {% block form_actions %} - <div class="form-actions"> - <div class="row-fluid"> - <div class="span6"> - {% block delete_button %} - {% if h.check_access('package_delete', {'id': data.id}) and not data.state == 'deleted' %} - <a class="btn btn-danger pull-left" href="{% url_for 'dataset.delete', id=data.id %}" - data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this dataset?') }}"> - {% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a> - {% endif %} - {% endblock %} - {% block save_button %} - <button class="btn btn-primary btn-arrow-right" type="submit" name="save"> - {% block save_button_text %}{{ - _('Next: Add Data') - }}{% endblock %}</button> - {% endblock %} + <div class="form-actions"> + <div class="row-fluid"> + <div class="span6"> + {% block delete_button %} + {% if h.check_access('package_delete', {'id': data.id}) and not data.state == 'deleted' %} + <a class="btn btn-danger pull-left" href="{% url_for 'dataset.delete', id=data.id %}" + data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this dataset?') }}"> + {% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a> + {% endif %} + {% endblock %} + {% block save_button %} + <button class="btn btn-primary btn-arrow-right" type="submit" name="save"> + {% block save_button_text %}{{ + _('Next: Add Data') + }}{% endblock %}</button> + {% endblock %} + </div> </div> </div> - </div> {% endblock %} <span class='required-text'>*{{ _('Required information') }}</span> </form> \ No newline at end of file diff --git a/ckanext/odsh/templates/snippets/search_box.html b/ckanext/odsh/templates/snippets/search_box.html index 912eac5c..707e40fd 100644 --- a/ckanext/odsh/templates/snippets/search_box.html +++ b/ckanext/odsh/templates/snippets/search_box.html @@ -1,16 +1,9 @@ <div class='search-box-container'> - <div class='search-box'> - <div class="field search-field"> - <input - aria-label="{{ _('Enter search query for datasets') }}" - id="field-sitewide-search" - class="search" - type="text" - value="{{c.q}}" - name="q" - placeholder="{{ _('Search dataset') }}" - /> - <button class="btn-search" type="submit" aria-label="{{ _('Search dataset') }}"></button> - </div> + <div class='search-box'> + <div class="field search-field"> + <input aria-label="{{ _('Enter search query for datasets') }}" id="field-sitewide-search" class="search" + type="text" value="{{ query }}" name="q" placeholder="{{ _('Search dataset') }}" /> + <button class="btn-search" type="submit" aria-label="{{ _('Search dataset') }}"></button> </div> + </div> </div> \ No newline at end of file diff --git a/ckanext/odsh/templates/user/edit_user_form.html b/ckanext/odsh/templates/user/edit_user_form.html index 497c0849..e33ba52b 100644 --- a/ckanext/odsh/templates/user/edit_user_form.html +++ b/ckanext/odsh/templates/user/edit_user_form.html @@ -58,7 +58,7 @@ <legend>{{ _('Change password') }}</legend> {{ form.input('old_password', type='password', - label=_('Sysadmin Password') if c.is_sysadmin else _('Old Password'), + label=_('Old Password'), id='field-password', value=data.oldpassword, error=errors.oldpassword, diff --git a/ckanext/odsh/templates/user/login.html b/ckanext/odsh/templates/user/login.html index e9e93b45..af9f18ad 100644 --- a/ckanext/odsh/templates/user/login.html +++ b/ckanext/odsh/templates/user/login.html @@ -15,7 +15,7 @@ <div class="module-content"> <h2 class="page-heading">{% block page_heading %}{{ _('Login') }}{% endblock %}</h2> {% block form %} - {% snippet "user/snippets/login_form.html", action=c.login_handler, error_summary=error_summary %} + {% snippet "user/snippets/login_form.html", error_summary=error_summary %} {% endblock %} </div> </section> diff --git a/ckanext/odsh/templates/user/snippets/login_form.html b/ckanext/odsh/templates/user/snippets/login_form.html index 08565405..bc50b6e0 100644 --- a/ckanext/odsh/templates/user/snippets/login_form.html +++ b/ckanext/odsh/templates/user/snippets/login_form.html @@ -1,12 +1,12 @@ {# Renders the login form. -action - The url that the form should be submitted to. +action - The url that the form should be submitted to. error_summary - A tuple/list of form errors. Example: -{% snippet "user/snippets/login_form.html", action=c.login_handler, error_summary=error_summary %} + {% snippet "user/snippets/login_form.html", action=g.login_handler, error_summary=error_summary %} #} {% import 'macros/form.html' as form %} -- GitLab