Add custom harvest sources search page

This commit is contained in:
amercader 2012-12-05 14:51:20 +00:00
parent a605564a41
commit 2dba7fbf78
4 changed files with 144 additions and 0 deletions

View File

@ -52,6 +52,9 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm):
def package_form(self):
return 'source/new_source_form.html'
def search_template(self):
return 'source/search.html'
def new_template(self):
return 'source/new.html'

View File

@ -0,0 +1,39 @@
{#
Displays a single harvest source result.
source - A source to display.
item_class - The class name to use on the list item.
hide_resources - If true hides the resources (default: false).
banner - If true displays a popular banner (default: false).
truncate - The length to trucate the description to (default: 180)
truncate_title - The length to truncate the title to (default: 80).
Example:
{% snippet 'snippets/source_item.html', source=c.sources[0] %}
#}
{% set truncate = truncate or 180 %}
{% set truncate_title = truncate_title or 80 %}
{% set title = source.title or source.name %}
<li class="{{ item_class or "dataset-item" }}">
<div class="dataset-content">
<h3 class="dataset-heading">
{{ h.link_to(h.truncate(title, truncate_title), h.url_for('harvest_source_read', id=source.name)) }}
{% if source.get(state, '').startswith('draft') %}
<span class="label label-info">{{ _('Draft') }}</span>
{% elif source.get(state, '').startswith('deleted') %}
<span class="label label-important">{{ _('Deleted') }}</span>
{% endif %}
{{ h.popular('recent views', source.tracking_summary.recent, min=10) if source.tracking_summary }}
</h3>
{% if banner %}
<span class="banner">Popular</span>
{% endif %}
<!-- TODO: nicer, include type, frequency (last run, errors, packages? will need to get those from the source object) -->
<div>{{ source.url }}</div>
</div>
</li>

View File

@ -0,0 +1,23 @@
{#
Displays a list of harvest sources.
sources - A list of harvest sources to display.
list_class - The class name for the list item.
item_class - The class name to use on each item.
hide_resources - If true hides the resources (default: false).
banner - If true displays a popular banner (default: false).
truncate - The length to trucate the description to (default: 180)
truncate_title - The length to truncate the title to (default: 80).
Example:
{% snippet 'snippets/sources_list.html', sources=c.sources %}
#}
{% if sources %}
<ul class="{{ list_class or 'dataset-list unstyled' }}">
{% for source in sources %}
{% snippet 'snippets/source_item.html', source=source, item_class=item_class, hide_resources=hide_resources, banner=banner, truncate=truncate, truncate_title=truncate_title %}
{% endfor %}
</ul>
{% endif %}

View File

@ -0,0 +1,79 @@
{% extends "page.html" %}
{% block subtitle %}{{ _("Harvest sources") }}{% endblock %}
{% block breadcrumb_content %}
<li class="active">{{ h.nav_named_link(_('Harvest Sources'), '{0}_search'.format(c.dataset_type)) }}</li>
{% endblock %}
{% 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) }}
</div>
{{ c.page.pager(q=c.q) }}
</section>
{% endblock %}
{% block secondary_content %}
{{ h.snippet('snippets/facet_list.html', title='Frequency', name='frequency', alternative_url=h.url_for('{0}_search'.format(c.dataset_type))) }}
{{ h.snippet('snippets/facet_list.html', title='Type', name='source_type', alternative_url=h.url_for('{0}_search'.format(c.dataset_type))) }}
{% endblock %}