Skip to content

Commit

Permalink
Added files missing in last commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter L committed Jan 10, 2011
1 parent a72eb3f commit 84a4b33
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
41 changes: 41 additions & 0 deletions admin_views.py
@@ -0,0 +1,41 @@
import os

from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib.admin.views.decorators import staff_member_required

def _collect_batch_info(uuid):
path = './media/batches/%s/' % uuid
return {
'uuid': uuid,
'finished': os.path.exists(os.path.join(path,'batch.tar.gz')),
'num_indicators': len([entry for entry in os.listdir(path) if entry.endswith('.csv')]) / 2
}

@staff_member_required
def indicator_batch_list(request):
""" Displays the status of an indicator debug batch.
The directory with the name specified by the uuid parameter is searched for
output, debug and log files. Return 404 if not found. If log.txt exists, but
the "end batch" marker isn't found, output the log file contents, but do not
offer a download link.
If the batch is complete, provide a tar/gzip of the files.
"""
return render_to_response('admin/indicator_batch_list.html',
{'batches': map(lambda b: _collect_batch_info(b), os.listdir('./media/batches/'))},
context_instance=RequestContext(request))

@staff_member_required
def indicator_batch(request, uuid):
""" Displays the status of an indicator debug batch.
The directory with the name specified by the uuid parameter is searched for
output, debug and log files. Return 404 if not found. If log.txt exists, but
the "end batch" marker isn't found, output the log file contents, but do not
offer a download link.
If the batch is complete, provide a tar/gzip of the files.
"""
pass
Empty file.
30 changes: 30 additions & 0 deletions templates/admin/indicator_batch_list.html
@@ -0,0 +1,30 @@
{% extends "admin/change_list.html" %}

{% block title %}List of debug batches{% endblock %}

{% block content %}
<div id="content-main">
<h1>List of debug batches completed or in progress:</h1>
{% if batches %}
<table>
<thead>
<tr>
<th>uuid</th>
<th># indicators</th>
<th>Finished?</th>
</tr>
</thead>
<tbody>
{% for batch in batches %}
<tr class="{% cycle "row1" "row2" %}">
<td><a href="#">{{ batch.uuid }}</a></td>
<td>{{ batch.num_indicators }}</td>
<td>{{ batch.finished }}</td>
</tr>

{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock content %}

15 changes: 15 additions & 0 deletions templates/admin/indicators/app_index.html
@@ -0,0 +1,15 @@
{% extends "admin/app_index.html" %}

{% block content %}
{{ block.super }}
<div id="content-main">
<div class="module">
<table>
<tr>
<th scope="row"><a href="{% url indicators_admin_batch_list %}">Debug Batches</a></th>
</tr>
</table>
</div>
</div>
{% endblock %}

7 changes: 7 additions & 0 deletions urls_admin.py
@@ -0,0 +1,7 @@
from django.conf.urls.defaults import *

urlpatterns = patterns('',
url(r'^indicator_batches/$', 'indicators.admin_views.indicator_batch_list', name="indicators_admin_batch_list"),
url(r'^indicator_batches/([a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12})$', 'indicators.admin_views.indicator_batch', name="indicators_admin_batch"),
)

0 comments on commit 84a4b33

Please sign in to comment.