Make the /harvest page more robust if source.status is not set

This prevents exceptions from appearing in the log from Jinja:
  [error] [client 1.2.3.4] Error - <class 'jinja2.exceptions.UndefinedError'>: 'dict object' has no attribute 'status'
This commit is contained in:
Stefan Oderbolz 2013-08-14 11:52:11 +02:00
parent cb745c3c3e
commit 4dfd091aec
4 changed files with 14 additions and 5 deletions

View File

@ -38,7 +38,9 @@ Example:
{% endif %}
<p class="muted">
{{ _('Datasets') }}: {{ source.status.total_datasets }}
{% if source.status %}
{{ _('Datasets') }}: {{ source.status.total_datasets }}
{% endif %}
{% if not within_organization and source.organization %}
&mdash; {{ _('Organization') }}: {{ h.link_to(source.organization.title or source.organization.name, h.url_for('organization_read', id=source.organization.name)) }}</a>
{% endif %}

View File

@ -3,7 +3,7 @@
{% block primary_content_inner %}
<section class="module-content">
<h1>Last Harvest Job</h1>
{% if source.status.last_job %}
{% if source.status and source.status.last_job %}
{% snippet "snippets/job_details.html", job=source.status.last_job %}
<div class="form-actions">
<a href="{{ h.url_for(controller='ckanext.harvest.controllers.view:ViewController', action='show_last_job', source=source.name) }}" class="btn pull-right">

View File

@ -8,7 +8,7 @@
{% endblock %}
{% block actions_content %}
{% if source.status.last_job and (source.status.last_job.status == 'New' or source.status.last_job.status == 'Running') %}
{% if source.status and source.status.last_job and (source.status.last_job.status == 'New' or source.status.last_job.status == 'Running') %}
<li><a class="btn disabled" rel="tooltip" title="There already is an unrun job for this source"><i class="icon-refresh icon-large"></i> Reharvest</a></li>
{% else %}
{% set locale = h.dump_json({'content': _('This will re-run the harvesting for this source. Any updates at the source will overwrite the local datasets. Sources with a large number of datasets may take a significant amount of time to finish harvesting. Please confirm you would like us to start reharvesting.')}) %}

View File

@ -21,8 +21,15 @@
{% endif %}
<div class="nums">
<dl>
<dt>{{ _('Datasets') }}</dt>
<dd>{{ c.harvest_source.status.total_datasets }}</dd>
<dt>
{{ _('Datasets') }}
</dt>
<dd>
{% if c.harvest_source.status %}
{{ c.harvest_source.status.total_datasets }}
{% endif %}
</dd>
</dl>
</div>
</section>