Commits

Anonymous committed 6bc1e59

Changed sitting admin to show Printable view by default, with link to Editable

  • Participants
  • Parent commits 409e62d

Comments (0)

Files changed (3)

 from django.contrib import admin
+from django.contrib.admin.util import unquote
+
+from django.conf.urls.defaults import patterns, url
+from django.utils.functional import update_wrapper
+
+from django.shortcuts import render
+
 from quiz import models
 
 class QuizAdmin(admin.ModelAdmin):
             'fields': ('question', 'choice',),
         }),
     )
+    extra = 0
 
 
 class SittingAdmin(admin.ModelAdmin):
     def out_of(self, obj):
         return obj.quiz.points()
 
+    # View/Print results view
+    def get_urls(self):
+        urlpatterns = super(SittingAdmin, self).get_urls()
+
+        def wrap(view):
+            def wrapper(*args, **kwargs):
+                return self.admin_site.admin_view(view)(*args, **kwargs)
+            return update_wrapper(wrapper, view)
+
+        info = self.model._meta.app_label, self.model._meta.module_name
+
+        urlpatterns = patterns('',
+            url(r'(\d+)/change/$',
+                wrap(self.change_view),
+                name='%s_%s_change' % info
+            ),
+            url(r'(\d+)/$',
+                wrap(self.print_view),
+                name='%s_%s_print' % info
+            ),
+        ) + urlpatterns
+        return urlpatterns
+
+    def print_view(self, request, object_id, extra_context=None):
+
+        obj = self.get_object(request, unquote(object_id))
+
+        context = {
+            'object': obj,
+        }
+        context.update(extra_context or {})
+
+        return render(request, 'admin/quiz/sitting/print_view.html', context,
+            current_app=self.admin_site.name,
+        )
+
 admin.site.register(models.Sitting, SittingAdmin)

quiz/templates/admin/quiz/sitting/change_form.html

+{% extends "admin/change_form.html" %}
+
+{% block object-tools-items %}
+    <li><a href="../" class="viewsitelink">Print View</a></li>
+    {{ block.super }}
+{% endblock %}

quiz/templates/admin/quiz/sitting/print_view.html

+{% extends "admin/base.html" %}
+
+{% load adminmedia %}
+
+{% block extrastyle %}
+{{ block.super }}
+<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />
+<style type="text/css" media="print">
+.noprint { display: none !important; }
+</style>
+{% endblock %}
+
+{% block content %}
+<h1> Quiz: {{ object.quiz }} </h1>
+<div id="content-main">
+  <ul class="object-tools">
+    <li class="noprint"><a href="change/">Edit</a></li>
+    <li><a href="#">Score: {{ object.score }} / {{ object.quiz.points }}</a></li>
+  </ul>
+
+<h2> Student: {{ object.student }} ( {{ object.date_sat }} ) </h2>
+
+<div class="inline-group">
+  <h2> Responses </h2>
+  {% for response in object.response_set.all %}
+  <div class="inline-related">
+    <h3> <b> Question </b> <span class="inline label">{{ response.question }}</span> </h3>
+
+    <div class="module">
+      <div class="form-row">
+
+        {% for answer in response.question.answer_set.all %}
+        <div style="border: solid transparent 1px;{% if answer == response.question.best_answer %} border-color: green; {% else %}{% if answer == response.choice %} border-color: red; {% endif%}{% endif %}">
+          <label {% if answer == response.choice %}class="required"{% endif %}>{{ answer.points }} point{{ answer.points|pluralize }}</label>
+          <p>{{ answer }}</p>
+        </div>
+        {% endfor %}
+
+      </div>
+    </div>
+
+  </div>
+  {% endfor %}
+</div>
+
+</div>
+{% endblock %}