[#70] Fix Add harvest source button not showing

Due to changes in the templates starting on 2.1 the add source button
was not showing. The whole search template has been simplified,
separating in a separate file the 2.0 only code.

Tested in 2.0, 2.1 and 2.2
This commit is contained in:
amercader 2014-01-10 13:48:02 +00:00
parent 928ea061aa
commit 1e94a11255
3 changed files with 105 additions and 80 deletions

View File

@ -0,0 +1,9 @@
{% set authorized_user = h.check_access('harvest_source_create') %}
{% if authorized_user %}
<a href="{{ h.url_for('{0}_new'.format(dataset_type)) }}" class="btn btn-primary">
<i class="icon-plus-sign-alt"></i>
{{ _('Add Harvest Source') }}
</a>
{% endif %}

View File

@ -2,91 +2,37 @@
{% block subtitle %}{{ _("Harvest sources") }}{% endblock %} {% block subtitle %}{{ _("Harvest sources") }}{% endblock %}
{% set authorized_user = h.check_access('harvest_source_create') %}
{% block add_link %}
{% if authorized_user %}
<a href="{{ h.url_for('{0}_new'.format(c.dataset_type)) }}" class="btn btn-primary">
<i class="icon-plus-sign-alt"></i>
{{ _('Add Harvest Source') }}
</a>
{% endif %}
{% endblock %}
{# CKAN 2.0 #}
{% block add_action_content %}
{{ self.add_link() }}
{% endblock %}
{# CKAN 2.1 #}
{% block content_action %}
{{ self.add_link() }}
{% endblock %}
{% block breadcrumb_content %} {% block breadcrumb_content %}
<li class="active">{{ h.nav_named_link(_('Harvest Sources'), '{0}_search'.format(c.dataset_type)) }}</li> <li class="active">{{ h.nav_named_link(_('Harvest Sources'), '{0}_search'.format(c.dataset_type)) }}</li>
{% endblock %} {% endblock %}
{% if g.ckan_base_version.startswith('2.0') %}
{# CKAN 2.0 #}
{% block add_action_content %}
{{ h.snippet('snippets/add_source_button.html', dataset_type=c.dataset_type) }}
{% endblock %}
{% endif %}
{% block primary_content %} {% block primary_content %}
<section class="module"> {% if g.ckan_base_version.startswith('2.0') %}
<div class="module-content"> {# CKAN 2.0 #}
{% if c.__version__.startswith('2.0') %}
<form id="dataset-search" class="dataset-search clearfix" method="get" data-module="select-switch">
<span class="control-group search-giant">
<input type="text" class="search" name="q" value="{{ c.q }}" autocomplete="off" placeholder="{{ _('Search...') }}" />
<button type="submit" value="{{ _('Search') }}">Submit</button>
</span>
{{ h.snippet('snippets/sort_by.html', sort=c.sort_by_selected) }} {% include 'source/search_2.0.html' %}
{% if c.fields -%} {% else %}
<span> {# > CKAN 2.0 #}
{%- for k, v in c.fields -%}
<input type="hidden" name="{{ k }}" value="{{ v }}" />
{% endfor -%}
</span>
{%- endif %}
</form> <section class="module">
<div class="results"> <div class="module-content">
<strong> {% block page_primary_action %}
{%- if request.params and c.page.item_count -%} <div class="page_primary_action">
{{ c.page.item_count }} harvest sources{{ _(" found for \"{query}\"").format(query=c.q) if c.q }} {{ h.snippet('snippets/add_source_button.html', dataset_type=c.dataset_type) }}
{%- elif request.params and c.page.item_count == 0 -%} </div>
{{ _('Sorry no harvest sources found for "{query}"').format(query=c.q) }} {% endblock %}
{%- else -%}
{{ _('All harvest sources') }}
{%- endif -%}
</strong>
<div class="filter-list">
{% for field in c.fields_grouped %}
<span class="facet">{{ c.facet_titles.get(field) }}:</span>
{% for value in c.fields_grouped[field] %}
<span class="filtered pill">
{%- if c.translated_fields and c.translated_fields.has_key((field,value)) -%}
{{ c.translated_fields[(field,value)] }}
{%- else -%}
{{ value }}
{%- endif %}
<a href="{{ c.remove_field(field, value) }}" class="remove" title="{{ _('Remove') }}"><i class="icon-remove"></i></a>
</span>
{% endfor %}
{% endfor %}
</div>
{% if request.params and c.page.item_count == 0 %}
<p class="extra">Try another search term,
browse the sources below or <a href="{{ h.url_for('{0}_new'.format(c.dataset_type)) }}">{{ _('add a new one') }}</a>.
</p>
{% endif %}
</div>
{% if c.query_error %}
{% trans %}
<p><strong>There was an error while searching.</strong> Please try again.</p>
{% endtrans %}
{% endif %}
{% else %}
{% set facets = { {% set facets = {
'fields': c.fields_grouped, 'fields': c.fields_grouped,
'search': c.search_facets, 'search': c.search_facets,
@ -103,17 +49,19 @@
%} %}
{% snippet 'snippets/search_form.html', type='harvest', query=c.q, sorting=sorting, sorting_selected=c.sort_by_selected, count=c.page.item_count, facets=facets, show_empty=request.params, error=c.query_error, placeholder=_("Search harvest sources...") %} {% snippet 'snippets/search_form.html', type='harvest', query=c.q, sorting=sorting, sorting_selected=c.sort_by_selected, count=c.page.item_count, facets=facets, show_empty=request.params, error=c.query_error, placeholder=_("Search harvest sources...") %}
{% endif %} {{ h.snippet('snippets/source_list.html', sources=c.page.items, show_organization=true) }}
{{ h.snippet('snippets/source_list.html', sources=c.page.items, show_organization=true) }} </div>
</div> {{ c.page.pager(q=c.q) }}
</section>
{{ c.page.pager(q=c.q) }} {% endif %}
</section>
{% endblock %} {% endblock %}
{% block secondary_content %} {% block secondary_content %}
{% for facet in c.facet_titles %} {% for facet in c.facet_titles %}
{{ h.snippet('snippets/facet_list.html', title=c.facet_titles[facet], name=facet, alternative_url=h.url_for('{0}_search'.format(c.dataset_type))) }} {{ h.snippet('snippets/facet_list.html', title=c.facet_titles[facet], name=facet, alternative_url=h.url_for('{0}_search'.format(c.dataset_type))) }}

View File

@ -0,0 +1,68 @@
{% block primary_content %}
<section class="module">
<div class="module-content">
<form id="dataset-search" class="dataset-search clearfix" method="get" data-module="select-switch">
<span class="control-group search-giant">
<input type="text" class="search" name="q" value="{{ c.q }}" autocomplete="off" placeholder="{{ _('Search...') }}" />
<button type="submit" value="{{ _('Search') }}">Submit</button>
</span>
{{ h.snippet('snippets/sort_by.html', sort=c.sort_by_selected) }}
{% if c.fields -%}
<span>
{%- for k, v in c.fields -%}
<input type="hidden" name="{{ k }}" value="{{ v }}" />
{% endfor -%}
</span>
{%- endif %}
</form>
<div class="results">
<strong>
{%- if request.params and c.page.item_count -%}
{{ c.page.item_count }} harvest sources{{ _(" found for \"{query}\"").format(query=c.q) if c.q }}
{%- elif request.params and c.page.item_count == 0 -%}
{{ _('Sorry no harvest sources found for "{query}"').format(query=c.q) }}
{%- else -%}
{{ _('All harvest sources') }}
{%- endif -%}
</strong>
<div class="filter-list">
{% for field in c.fields_grouped %}
<span class="facet">{{ c.facet_titles.get(field) }}:</span>
{% for value in c.fields_grouped[field] %}
<span class="filtered pill">
{%- if c.translated_fields and c.translated_fields.has_key((field,value)) -%}
{{ c.translated_fields[(field,value)] }}
{%- else -%}
{{ value }}
{%- endif %}
<a href="{{ c.remove_field(field, value) }}" class="remove" title="{{ _('Remove') }}"><i class="icon-remove"></i></a>
</span>
{% endfor %}
{% endfor %}
</div>
{% if request.params and c.page.item_count == 0 %}
<p class="extra">Try another search term,
browse the sources below or <a href="{{ h.url_for('{0}_new'.format(c.dataset_type)) }}">{{ _('add a new one') }}</a>.
</p>
{% endif %}
</div>
{% if c.query_error %}
{% trans %}
<p><strong>There was an error while searching.</strong> Please try again.</p>
{% endtrans %}
{% endif %}
{{ h.snippet('snippets/source_list.html', sources=c.page.items, show_organization=true) }}
</div>
{{ c.page.pager(q=c.q) }}
</section>
{% endblock %}