Change all the queries to Textbook model to Tasks.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Thu, 20 Jan 2011 17:46:49 +0530
changeset 501 b84d6a1d4603
parent 500 42516ec56822
child 502 1e5df997eb01
Change all the queries to Textbook model to Tasks. Since Textbook model is deprecated now, implemented the changes in the views to query respected queries and make corresponding changes in the views.
pytask/taskapp/views.py
pytask/templates/task/view_textbook.html
--- a/pytask/taskapp/views.py	Thu Jan 20 17:45:39 2011 +0530
+++ b/pytask/taskapp/views.py	Thu Jan 20 17:46:49 2011 +0530
@@ -454,14 +454,24 @@
 
 def view_textbook(request, task_id):
 
-    textbook = shortcuts.get_object_or_404(taskapp_models.TextBook, pk=task_id)
-    chapters = textbook.chapters.all()
+    # Shortcut to get_object_or_404 is not used since django-tagging
+    # api expects a queryset object for tag filtering.
+    task = taskapp_models.Task.objects.filter(pk=task_id)
+
+    textbooks = TaggedItem.objects.get_by_model(task, ['Textbook'])
+
+    if textbooks:
+        textbook = textbooks[0]
+    else:
+        raise http.Http404
+
+    #chapters = textbook.chapters.all()
 
     user = request.user
 
     context = {"user": user,
                "textbook": textbook,
-               "chapters": chapters,
+    #           "chapters": chapters,
               }
 
     if not user.is_authenticated():
--- a/pytask/templates/task/view_textbook.html	Thu Jan 20 17:45:39 2011 +0530
+++ b/pytask/templates/task/view_textbook.html	Thu Jan 20 17:46:49 2011 +0530
@@ -6,7 +6,7 @@
 
 
 {% block title %}
-    {{textbook.name}}
+    {{ textbook.title }}
 {% endblock %}
 
 {% block content %}
@@ -31,6 +31,7 @@
         <hr />
     {% endif %}
 
+    Chapters: <br />
     {% if chapters %}
       <table>
       {% for chap in chapters %}
@@ -41,7 +42,7 @@
       {% endfor %}
       </table>
     {% else %}
-    There are no chapters in this textbook as of now.<br />
+      (Chapters are yet to be added by the Coordinator or T/A.)<br />
     {% endif %}
 
         <hr />