List each department textbooks separately for now, think of a clever way later.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Thu, 20 Jan 2011 07:56:21 +0530
changeset 497 6386458d749b
parent 496 eb1982186306
child 498 9f04b7bcc333
List each department textbooks separately for now, think of a clever way later.
pytask/taskapp/views.py
pytask/templates/task/browse_textbooks.html
--- a/pytask/taskapp/views.py	Thu Jan 20 07:55:38 2011 +0530
+++ b/pytask/taskapp/views.py	Thu Jan 20 07:56:21 2011 +0530
@@ -9,6 +9,7 @@
 from django.template import RequestContext
 from django.utils import simplejson as json
 
+from tagging.managers import TaggedItem
 from tagging.models import Tag
 
 from pytask.views import show_msg
@@ -493,15 +494,29 @@
 
     user = request.user
 
-    # Fetch all the tasks tagged with Textbook
-    textbooks = taskapp_models.Task.tagged.with_any(['Textbook'])
 
     # Get all the textbooks that are Open.
-    open_textbooks = textbooks.filter(
+    open_textbooks = taskapp_models.Task.objects.filter(
       status=taskapp_models.TASK_STATUS_CHOICES[1][0]).order_by(
       'creation_datetime')
 
-    context = {'open_textbooks': open_textbooks,}
+
+    context = {
+      'aero_textbooks': TaggedItem.objects.get_by_model(
+        open_textbooks, ['Textbook', 'Aerospace']),
+      'chemical_textbooks': TaggedItem.objects.get_by_model(
+        open_textbooks, ['Textbook', 'Chemical']),
+      'computerscience_textbooks': TaggedItem.objects.get_by_model(
+        open_textbooks, ['Textbook', 'ComputerScience']),
+      'electrical_textbooks': TaggedItem.objects.get_by_model(
+        open_textbooks, ['Textbook', 'Electrical']),
+      'engineeringphysics_textbooks': TaggedItem.objects.get_by_model(
+        open_textbooks, ['Textbook', 'EngineeringPhysics']),
+      'mechanical_textbooks': TaggedItem.objects.get_by_model(
+        open_textbooks, ['Mechanical', 'Textbook']),
+      'metallurgical_textbooks': TaggedItem.objects.get_by_model(
+        open_textbooks, ['Textbook', 'Metallurgical']),
+      }
 
     # Nothing
     if user.is_authenticated() and (user.get_profile().role in
--- a/pytask/templates/task/browse_textbooks.html	Thu Jan 20 07:55:38 2011 +0530
+++ b/pytask/templates/task/browse_textbooks.html	Thu Jan 20 07:56:21 2011 +0530
@@ -1,18 +1,36 @@
 {% extends "base.html" %}
 
+
+{% load browse_helpers %}
+
+
 {% block content %}
-  {% if open_textbooks %}
-    Textbooks that are open for contribution
-    <ul>
-      {% for textbook in open_textbooks %}
-        <li>
-          <a href="{% url view_textbook textbook.id %}">
-            {{ textbook.title }}
-          </a>
-        </li>
-      {% endfor %}
-    </ul>
-    <br />
+  {% if aero_textbooks %}
+    {% as_list_textbooks aero_textbooks "Aerospace Engineering" %}
+  {% endif %}
+
+  {% if chemical_textbooks %}
+    {% as_list_textbooks chemical_textbooks "Chemical Engineering" %}
+  {% endif %}
+
+  {% if computerscience_textbooks %}
+    {% as_list_textbooks computerscience_textbooks "Computer Science and Engineering" %}
+  {% endif %}
+
+  {% if electrical_textbooks %}
+    {% as_list_textbooks electrical_textbooks "Electrical Engineering" %}
+  {% endif %}
+
+  {% if engineeringphysics_textbooks %}
+    {% as_list_textbooks engineeringphysics_textbooks "Engineering Physics Engineering" %}
+  {% endif %}
+
+  {% if mechanical_textbooks %}
+    {% as_list_textbooks mechanical_textbooks "Mechanical Engineering" %}
+  {% endif %}
+
+  {% if metallurgical_textbooks %}
+    {% as_list_textbooks metallurgical_textbooks "Metallurgical Engineering and Materials Science" %}
   {% endif %}