Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up c object #178

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<section class="module span6 offset3">
<div class="module-content">
{% block form %}
<p>{{ _('Are you sure you want to remove this user as a Showcase Admin - {name}?').format(name=c.user_dict.name) }}</p>
<p>{{ _('Are you sure you want to remove this user as a Showcase Admin - {name}?').format(name=user_dict.name) }}</p>
<p class="form-actions">
<form action="{{ h.url_for(showcase_admin_remove_route) }}" method="post">
{{ h.csrf_input() if 'csrf_input' in h }}
<input type="hidden" name="user" value="{{ c.user_id }}" />
<input type="hidden" name="user" value="{{ user_id }}" />
<button class="btn" type="submit" name="cancel" >{{ _('Cancel') }}</button>
<button class="btn btn-primary" type="submit" name="delete" >{{ _('Confirm Remove') }}</button>
</form>
Expand Down
6 changes: 3 additions & 3 deletions ckanext/showcase/templates/admin/manage_showcase_admins.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% import 'macros/form.html' as form %}

{% set user = c.user_dict %}
{% set user = user_dict %}
{% set showcase_admin_remove_route = 'showcase_blueprint.admin_remove' %}


Expand Down Expand Up @@ -39,15 +39,15 @@ <h1 class="page-heading">
{% endblock %}

<h3 class="page-heading">{{ _('Showcase Admins') }}</h3>
{% if c.showcase_admins %}
{% if showcase_admins %}
<table class="table table-header table-hover table-bordered">
<thead>
<tr>
<th scope="col">{{ _('User') }}</th>
</tr>
</thead>
<tbody>
{% for user_dict in c.showcase_admins %}
{% for user_dict in showcase_admins %}
<tr>
<td class="media">
{{ h.linked_user(user_dict['id'], maxlength=20) }}
Expand Down
10 changes: 5 additions & 5 deletions ckanext/showcase/templates/package/dataset_showcase_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
{% block subtitle %}{{ _('Showcases') }} - {{ super() }}{% endblock %}

{% block primary_content_inner %}
{% if h.check_access('ckanext_showcase_update') and c.showcase_dropdown %}
{% if h.check_access('ckanext_showcase_update') and showcase_dropdown %}
<form method="post" class="form-horizontal" id="showcase-add">
{{ h.csrf_input() if 'csrf_input' in h }}
<select id="field-add_showcase" name="showcase_added" data-module="autocomplete">
{% for option in c.showcase_dropdown %}
{% for option in showcase_dropdown %}
<option value="{{ option[0] }}"> {{ option[1] }}</option>
{% endfor %}
</select>
<button type="submit" class="btn btn-primary" title="{{ _('Associate this showcase with this dataset') }}">{{ _('Add to showcase') }}</button>
</form>
{% endif %}

<h2>{% block page_heading %}{{ _('Showcases featuring {dataset_name}').format(dataset_name=h.dataset_display_name(c.pkg_dict)) }}{% endblock %}</h2>
<h2>{% block page_heading %}{{ _('Showcases featuring {dataset_name}').format(dataset_name=h.dataset_display_name(pkg_dict)) }}{% endblock %}</h2>
{% block showcase_list %}
{% if c.showcase_list %}
{% snippet "showcase/snippets/showcase_list.html", packages=c.showcase_list, pkg_id=c.pkg_dict.name, show_remove=h.check_access('ckanext_showcase_update') %}
{% if showcase_list %}
{% snippet "showcase/snippets/showcase_list.html", packages=showcase_list, pkg_id=pkg_dict.name, show_remove=h.check_access('ckanext_showcase_update') %}
{% else %}
<p class="empty">{{ _('There are no showcases that feature this dataset') }}</p>
{% endif %}
Expand Down
18 changes: 9 additions & 9 deletions ckanext/showcase/templates/showcase/add_datasets.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<div class="module-content">
{% block form %}
{% set facets = {
'fields': c.fields_grouped,
'search': c.search_facets,
'titles': c.facet_titles,
'translated_fields': c.translated_fields,
'remove_field': c.remove_field }
'fields': fields_grouped,
'search': search_facets,
'titles': facet_titles,
'translated_fields': translated_fields,
'remove_field': remove_field }
%}
{% set sorting = [
(_('Relevance'), 'score desc, metadata_modified desc'),
Expand All @@ -24,15 +24,15 @@
(_('Last Modified'), 'metadata_modified desc'),
(_('Popular'), 'views_recent desc') if g.tracking_enabled else (false, false) ]
%}
{% snippet 'snippets/search_form.html', type='dataset', query=c.q, sorting=sorting, sorting_selected=c.sort_by_selected, count=c.page.item_count, facets=facets, show_empty=request.args, error=c.query_error, fields=c.fields %}
{% snippet 'snippets/search_form.html', type='dataset', query=q, sorting=sorting, sorting_selected=sort_by_selected, count=page.item_count, facets=facets, show_empty=request.args, error=query_error, fields=fields %}
{% endblock %}
<h3 class="page-heading">
{% block page_heading %}
{{ _('Datasets available to add to this showcase') }}
{% endblock %}
</h3>
{% block package_search_results_list %}
{% if c.page.items %}
{% if page.items %}
<form method="POST" data-module="basic-form">
{{ h.csrf_input() if 'csrf_input' in h }}
{#{% block errors %}{{ form.errors(error_summary) }}{% endblock %}#}
Expand All @@ -53,7 +53,7 @@ <h3 class="page-heading">
</tr>
</thead>
<tbody>
{% for package in c.page.items %}
{% for package in page.items %}
{% set truncate = truncate or 180 %}
{% set truncate_title = truncate_title or 80 %}
{% set title = package.title or package.name %}
Expand Down Expand Up @@ -82,7 +82,7 @@ <h3 class="dataset-heading">
</div>

{% block page_pagination %}
{{ c.page.pager(q=c.q) }}
{{ page.pager(q=q) }}
{% endblock %}
</section>

Expand Down
4 changes: 2 additions & 2 deletions ckanext/showcase/templates/showcase/confirm_delete.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "page.html" %}

{% set pkg = pkg_dict or c.pkg_dict %}
{% set pkg = pkg_dict %}
{% set showcase_delete_route = 'showcase_blueprint.delete' %}

{% block subtitle %}{{ _("Confirm Delete") }}{% endblock %}
Expand All @@ -15,7 +15,7 @@
{% block form %}
<p>{{ _('Are you sure you want to delete showcase - {showcase_name}?').format(showcase_name=pkg.name) }}</p>
<p class="form-actions">
<form action="{{ h.url_for(showcase_delete_route, id=c.pkg_dict.name) }}" method="post">
<form action="{{ h.url_for(showcase_delete_route, id=pkg_dict.name) }}" method="post">
{{ h.csrf_input() if 'csrf_input' in h }}
<button class="btn" type="submit" name="cancel" >{{ _('Cancel') }}</button>
<button class="btn btn-primary" type="submit" name="delete" >{{ _('Confirm Delete') }}</button>
Expand Down
2 changes: 1 addition & 1 deletion ckanext/showcase/templates/showcase/edit_base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'page.html' %}

{% set pkg = pkg_dict or c.pkg_dict %}
{% set pkg = pkg_dict %}

{% set showcase_index_route = 'showcase_blueprint.index' %}
{% set showcase_read_route = 'showcase_blueprint.read' %}
Expand Down
24 changes: 12 additions & 12 deletions ckanext/showcase/templates/showcase/manage_datasets.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

<div class="module-content">
{% set facets = {
'fields': c.fields_grouped,
'search': c.search_facets,
'titles': c.facet_titles,
'translated_fields': c.translated_fields,
'remove_field': c.remove_field }
'fields': fields_grouped,
'search': search_facets,
'titles': facet_titles,
'translated_fields': translated_fields,
'remove_field': remove_field }
%}
{% set sorting = [
(_('Relevance'), 'score desc, metadata_modified desc'),
Expand All @@ -27,15 +27,15 @@
(_('Last Modified'), 'metadata_modified desc'),
(_('Popular'), 'views_recent desc') if g.tracking_enabled else (false, false) ]
%}
{% snippet 'snippets/search_form.html', type='dataset', query=c.q, sorting=sorting, sorting_selected=c.sort_by_selected, count=c.page.item_count, facets=facets, show_empty=request.args, error=c.query_error, fields=c.fields %}
{% snippet 'snippets/search_form.html', type='dataset', query=q, sorting=sorting, sorting_selected=sort_by_selected, count=page.item_count, facets=facets, show_empty=request.args, error=query_error, fields=fields %}
</div>

<div class="row row2">
<section class="span6">
<div class="module-content">
<h3 class="page-heading">{{ _('Datasets available to add to this showcase') }}</h3>
{% block package_search_results_list %}
{% if c.page.items %}
{% if page.items %}
<form method="POST" data-module="basic-form">
{{ h.csrf_input() if 'csrf_input' in h }}
{#{% block errors %}{{ form.errors(error_summary) }}{% endblock %}#}
Expand All @@ -56,7 +56,7 @@ <h3 class="page-heading">{{ _('Datasets available to add to this showcase') }}</
</tr>
</thead>
<tbody>
{% for package in c.page.items %}
{% for package in page.items %}
{% set truncate = truncate or 180 %}
{% set truncate_title = truncate_title or 80 %}
{% set title = package.title or package.name %}
Expand All @@ -76,10 +76,10 @@ <h3 class="dataset-heading">
</tr>
{% endfor %}
</tbody>
{% if c.page.pager() %}
{% if page.pager() %}
<tfoot>
<tr>
<td colspan="2" class="ckanext_showcase_pagination_footer">{{ c.page.pager(q=c.q) }}</td>
<td colspan="2" class="ckanext_showcase_pagination_footer">{{ page.pager(q=q) }}</td>
</tr>
</tfoot>
{% endif %}
Expand All @@ -95,7 +95,7 @@ <h3 class="dataset-heading">
<section class="span6">
<div class="module-content">
<h3 class="page-heading">{{ _('Datasets in this showcase') }}</h3>
{% if c.showcase_pkgs %}
{% if showcase_pkgs %}
<form method="POST" data-module="basic-form">
{{ h.csrf_input() if 'csrf_input' in h }}
<table class="table table-bordered table-header table-hover table-bulk-edit table-edit-hover" data-module="table-selectable-rows">
Expand All @@ -115,7 +115,7 @@ <h3 class="page-heading">{{ _('Datasets in this showcase') }}</h3>
</tr>
</thead>
<tbody>
{% for package in c.showcase_pkgs %}
{% for package in showcase_pkgs %}
{% set truncate = truncate or 180 %}
{% set truncate_title = truncate_title or 80 %}
{% set title = package.title or package.name %}
Expand Down
4 changes: 2 additions & 2 deletions ckanext/showcase/templates/showcase/read.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "page.html" %}

{% set pkg = pkg_dict or c.pkg_dict %}
{% set pkg = pkg_dict %}
{% set name = pkg.title or pkg.name %}
{% set editor = h.showcase_get_wysiwyg_editor() %}

Expand Down Expand Up @@ -105,7 +105,7 @@ <h1>
{% block secondary_help_content %}{% endblock %}

{% block package_info %}
{% snippet 'showcase/snippets/showcase_info.html', pkg=pkg, showcase_pkgs=c.showcase_pkgs %}
{% snippet 'showcase/snippets/showcase_info.html', pkg=pkg, showcase_pkgs=showcase_pkgs %}
{% endblock %}

{% block package_social %}
Expand Down
16 changes: 8 additions & 8 deletions ckanext/showcase/templates/showcase/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

{% block form %}
{% set facets = {
'fields': c.fields_grouped,
'search': c.search_facets,
'titles': c.facet_titles,
'translated_fields': c.translated_fields,
'fields': fields_grouped,
'search': search_facets,
'titles': facet_titles,
'translated_fields': translated_fields,
'remove_field': h.facet_remove_field }
%}
{% set sorting = [
Expand All @@ -34,11 +34,11 @@
(_('Last Modified'), 'metadata_modified desc'),
(_('Popular'), 'views_recent desc') if g.tracking_enabled else (false, false) ]
%}
{% snippet 'showcase/snippets/showcase_search_form.html', type='showcase', placeholder=_('Search showcases...'), query=c.q, sorting=sorting, sorting_selected=c.sort_by_selected, count=c.page.item_count, facets=facets, show_empty=request.args, error=c.query_error, fields=c.fields, no_bottom_border=true %}
{% snippet 'showcase/snippets/showcase_search_form.html', type='showcase', placeholder=_('Search showcases...'), query=q, sorting=sorting, sorting_selected=sort_by_selected, count=page.item_count, facets=facets, show_empty=request.args, error=query_error, fields=fields, no_bottom_border=true %}
{% endblock %}

{% block package_search_results_list %}
{{ h.snippet('showcase/snippets/showcase_list.html', packages=c.page.items) }}
{{ h.snippet('showcase/snippets/showcase_list.html', packages=page.items) }}
{% endblock %}

{% block package_search_results_api %}
Expand All @@ -48,8 +48,8 @@
{{ h.snippet('showcase/snippets/helper.html') }}
<div class="filters">
<div>
{% for facet in c.facet_titles %}
{{ h.snippet('snippets/facet_list.html', title=c.facet_titles[facet], name=facet) }}
{% for facet in facet_titles %}
{{ h.snippet('snippets/facet_list.html', title=facet_titles[facet], name=facet, search_facets=search_facets) }}
{% endfor %}
</div>
<a class="close no-text hide-filters"><i class="fa fa-times-circle icon-remove-sign"></i><span class="text">close</span></a>
Expand Down
30 changes: 25 additions & 5 deletions ckanext/showcase/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def read_view(id):

package_type = DATASET_TYPE_NAME
return tk.render('showcase/read.html',
extra_vars={'dataset_type': package_type})
extra_vars={'dataset_type': package_type,
'pkg_dict': tk.g.pkg_dict,})


def manage_datasets_view(id):
Expand Down Expand Up @@ -182,7 +183,18 @@ def manage_datasets_view(id):
'showcase_id': tk.g.pkg_dict['id']
})

return tk.render('showcase/manage_datasets.html')
extra_vars = {
'facet_titles': tk.g.facet_titles,
'fields_grouped': tk.g.fields_grouped,
'page': tk.g.page,
'pkg_dict': tk.g.pkg_dict,
'remove_field': tk.g.remove_field,
'search_facets': tk.g.search_facets,
'showcase_pkgs': tk.g.showcase_pkgs
}

return tk.render('showcase/manage_datasets.html',
extra_vars=extra_vars)


def _add_dataset_search(showcase_id, showcase_name):
Expand Down Expand Up @@ -423,7 +435,8 @@ def delete_view(id):
tk.abort(404, _('Showcase not found'))

return tk.render('showcase/confirm_delete.html',
extra_vars={'dataset_type': DATASET_TYPE_NAME})
extra_vars={'dataset_type': DATASET_TYPE_NAME,
'pkg_dict': tk.g.pkg_dict})


def dataset_showcase_list(id):
Expand Down Expand Up @@ -500,8 +513,14 @@ def dataset_showcase_list(id):
for showcase in site_showcases
if showcase['id'] not in pkg_showcase_ids]

extra_vars = {
'pkg_dict': tk.g.pkg_dict,
'showcase_dropdown': tk.g.showcase_dropdown,
'showcase_list': tk.g.showcase_list,
}

return tk.render("package/dataset_showcase_list.html",
extra_vars={'pkg_dict': tk.g.pkg_dict})
extra_vars=extra_vars)


def manage_showcase_admins():
Expand Down Expand Up @@ -540,7 +559,8 @@ def manage_showcase_admins():

tk.g.showcase_admins = tk.get_action('ckanext_showcase_admin_list')({},{})

return tk.render('admin/manage_showcase_admins.html')
return tk.render('admin/manage_showcase_admins.html',
extra_vars={'showcase_admins': tk.g.showcase_admins})


def remove_showcase_admin():
Expand Down
2 changes: 1 addition & 1 deletion ckanext/showcase/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def post(self, id):
error_summary = e.error_summary
return self.get(id, data_dict, errors, error_summary)

tk.c.pkg_dict = pkg
tk.g.pkg_dict = pkg

# redirect to showcase details page
url = h.url_for('showcase_blueprint.read', id=pkg['name'])
Expand Down