pytask/taskapp/views.py
changeset 495 773e886d9b80
parent 489 9cd090b8cd52
child 497 6386458d749b
--- a/pytask/taskapp/views.py	Thu Jan 20 06:36:38 2011 +0530
+++ b/pytask/taskapp/views.py	Thu Jan 20 07:17:14 2011 +0530
@@ -487,20 +487,27 @@
                                         RequestContext(request, context))
 
 def browse_textbooks(request):
+    """View to list all the open textbooks. This view fetches tasks
+    tagged with Textbook.
+    """
 
     user = request.user
 
-    open_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[1][0]).\
-                                      order_by("creation_datetime")
-    comp_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[3][0]).\
-                                      order_by("creation_datetime")
-    context = {"user": user,
-               "open_textbooks": open_textbooks,
-               "comp_textbooks": comp_textbooks,
-              }
+    # 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(
+      status=taskapp_models.TASK_STATUS_CHOICES[1][0]).order_by(
+      'creation_datetime')
 
-    if user.is_authenticated() and user.get_profile().role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]:
-        unpub_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[0][0])
+    context = {'open_textbooks': open_textbooks,}
+
+    # Nothing
+    if user.is_authenticated() and (user.get_profile().role in
+      [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]):
+        unpub_textbooks = taskapp_models.TextBook.objects.filter(
+          status=taskapp_models.TB_STATUS_CHOICES[0][0])
 
         context.update({"unpub_textbooks": unpub_textbooks})