Skip to content

Commit

Permalink
Merge pull request #1358 from okfn/1358-datastore-ui
Browse files Browse the repository at this point in the history
New DataStore UI fixes and tweaks
  • Loading branch information
johnmartin committed Dec 10, 2013
2 parents 210ecae + a691bd3 commit 5426295
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
14 changes: 9 additions & 5 deletions ckan/templates/package/resource_data.html
Expand Up @@ -9,7 +9,7 @@

<form method="post" action="{{ action }}" >
<button class="btn btn-primary" name="save" type="submit">
<i class="icon-cloud-upload"></i> {{ _('Upload Data') }}
<i class="icon-cloud-upload"></i> {{ _('Upload to DataStore') }}
</button>
</form>

Expand All @@ -32,11 +32,15 @@
</colgroup>
<tr>
<th>{{ _('Status') }}</th>
<td>{{ status.status.capitalize() if status.status else _('Not Uploaded Yet') }}</td>
<td>{{ h.datapusher_status_description(status) }}</td>
</tr>
<tr>
<th>{{ _('Last updated') }}</th>
<td>{{ h.time_ago_from_timestamp(status.last_updated) if status.status else _('Never') }}</td>
{% if status.status %}
<td><span class="date" title="{{ h.render_datetime(status.last_updated, with_hours=True) }}">{{ h.time_ago_from_timestamp(status.last_updated) }}</span></td>
{% else %}
<td>{{ _('Never') }}</td>
{% endif %}
</tr>
</table>

Expand All @@ -51,9 +55,9 @@ <h3>{{ _('Upload Log') }}</h3>
<i class="icon icon-{{ icon }}"></i>
<p>
{{ item.message | urlize }}<br>
<span class="date">
<span class="date" title="{{ h.render_datetime(item.timestamp, with_hours=True) }}">
{{ h.time_ago_from_timestamp(item.timestamp) }}
<a href="#" data-target="popover" data-content="<dl>{% for key, value in item.iteritems() %}<dt>{{ key }}</dt><dd>{{ value }}</dd>{% endfor %}</dl>" data-html="true">more info</a>
<a href="#" data-target="popover" data-content="<dl>{% for key, value in item.iteritems() %}<dt>{{ key }}</dt><dd>{{ value }}</dd>{% endfor %}</dl>" data-html="true">{{ _('Details') }}</a>
</span>
</p>
</li>
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/package/resource_edit_base.html
Expand Up @@ -21,7 +21,7 @@
{% block content_primary_nav %}
{{ h.build_nav_icon('resource_edit', _('Edit resource'), id=pkg.name, resource_id=res.id) }}
{% if 'datapusher' in g.plugins %}
{{ h.build_nav_icon('resource_data', _('Resource Data'), id=pkg.name, resource_id=res.id) }}
{{ h.build_nav_icon('resource_data', _('DataStore'), id=pkg.name, resource_id=res.id) }}
{% endif %}
{% endblock %}

Expand Down
16 changes: 16 additions & 0 deletions ckanext/datapusher/helpers.py
Expand Up @@ -9,3 +9,19 @@ def datapusher_status(resource_id):
return {
'status': 'unknown'
}


def datapusher_status_description(status):
_ = toolkit._

if status.get('status'):
captions = {
'complete': _('Complete'),
'pending': _('Pending'),
'submitting': _('Submitting'),
'error': _('Error'),
}

return captions.get(status['status'], status['status'].capitalize())
else:
return _('Not Uploaded Yet')
1 change: 1 addition & 0 deletions ckanext/datapusher/logic/action.py
Expand Up @@ -153,6 +153,7 @@ def datapusher_hook(context, data_dict):
task['state'] = status
task['last_updated'] = str(datetime.datetime.now())

context['ignore_auth'] = True
p.toolkit.get_action('task_status_update')(context, task)


Expand Down
5 changes: 4 additions & 1 deletion ckanext/datapusher/plugin.py
Expand Up @@ -128,4 +128,7 @@ def get_auth_functions(self):

def get_helpers(self):
return {
'datapusher_status': helpers.datapusher_status}
'datapusher_status': helpers.datapusher_status,
'datapusher_status_description':
helpers.datapusher_status_description,
}
12 changes: 10 additions & 2 deletions ckanext/datapusher/tests/test.py
Expand Up @@ -138,7 +138,7 @@ def test_send_datapusher_creates_task(self):

assert task['state'] == 'pending', task

def test_datapusher_hook(self):
def _call_datapusher_hook(self, user):
package = model.Package.get('annakarenina')
resource = package.resources[0]

Expand All @@ -163,7 +163,7 @@ def test_datapusher_hook(self):
}
}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
auth = {'Authorization': str(user.apikey)}
res = self.app.post('/api/action/datapusher_hook', params=postparams,
extra_environ=auth, status=200)
print res.body
Expand All @@ -182,3 +182,11 @@ def test_datapusher_hook(self):
task_type='datapusher', key='datapusher')

assert task['state'] == 'success', task

def test_datapusher_hook_sysadmin(self):

self._call_datapusher_hook(self.sysadmin_user)

def test_datapusher_hook_normal_user(self):

self._call_datapusher_hook(self.normal_user)

0 comments on commit 5426295

Please sign in to comment.