Commits

Steve Losh committed e863c43

Add the build_detail view.

Comments (0)

Files changed (4)

integration/views.py

 from django.http import HttpResponseRedirect, HttpResponseForbidden
 from django.contrib.auth.decorators import login_required
 from django.db.models import Max
-from tinpan.integration.models import Project
+from tinpan.integration.models import Project, BuildRun
 
 def overview(request):
     """An overview of all projects."""
     project = get_object_or_404(Project, slug=slug)
     
     return render_to_response('integration/project.html',
-        { 'project': project }, context_instance=RequestContext(request) )
+        { 'project': project }, context_instance=RequestContext(request) )
+
+def build_detail(request, slug, id):
+    run = get_object_or_404(BuildRun, id=id)
+    length = run.end_time - run.start_time
+    
+    hours, remainder = divmod(length.seconds, 3600)
+    minutes, seconds = divmod(remainder, 60)
+    
+    return render_to_response('integration/build.html',
+        { 'run': run, 'hours': hours, 'minutes': minutes, 'seconds': seconds },
+        context_instance=RequestContext(request) )

templates/integration/build.html

+{% extends 'base.html' %}
+
+
+{% block title %}{{ run.project.name }} - {% endblock title %}
+
+{% block header %}
+    /
+    <a href="{% url project_detail slug=run.project.slug %}">{{ run.project.name }}</a>
+    /
+    <a href="{% url build_detail slug=run.project.slug,id=run.id %}">build</a>
+{% endblock header %}
+
+{% block content %}
+    <p>
+        Started at {{ run.start_time|date:"f A" }} on {{ run.start_time|date:"l, F jS Y" }} ({{ run.start_time|timesince }} ago).<br/>
+        Finished at {{ run.end_time|date:"f A" }} on {{ run.end_time|date:"l, F jS Y" }} ({{ run.end_time|timesince }} ago).
+    </p>
+    
+    <p>
+        This build took
+        {% if hours %}{{ hours }} hour{{ hours|pluralize }},{% endif %}
+        {% if hours or minutes %}{{ minutes }} minute{{ minutes|pluralize }},{% endif %}
+        {{ seconds }} second{{ seconds|pluralize }}
+        to finish.
+    </p>
+{% endblock content %}

templates/integration/project.html

     <h2>Builds</h2>
     {% for run in project.buildrun_set.all %}
         <p class="project-run {% if forloop.last %}last{% endif %}">
-            A build of {{ project.name }}
+            <a href="{% url build_detail slug=project.slug,id=run.id %}">A build of {{ project.name }}</a>
             {% if run.end_time %}
                 finished {{ run.end_time|timesince }} ago and
                 {% if run.success %}
 
 admin.autodiscover()
 
-urlpatterns = patterns('',
+urlpatterns = patterns('tinpan.integration.views',
+    url(r'^$',                                     'overview',       name='overview'),
+    url(r'^(?P<slug>[\w_-]+)/$',                   'project_detail', name='project_detail'),
+    url(r'^(?P<slug>[\w_-]+)/build/(?P<id>\d+)/$', 'build_detail',   name='build_detail'),
+)
+
+urlpatterns += patterns('',
     (r'^admin/', include(admin.site.urls)),
-    url(r'^$', 'tinpan.integration.views.overview', name='overview'),
-    url(r'^(?P<slug>[\w_-]*)/$', 'tinpan.integration.views.project_detail', name='project_detail'),
 )