created browse textbooks page
authorNishanth Amuluru <nishanth@fossee.in>
Tue, 11 Jan 2011 00:23:47 +0530
changeset 372 563fe356947d
parent 371 94497f8b1dae
child 373 014d812e625e
created browse textbooks page
pytask/taskapp/urls.py
pytask/taskapp/views.py
pytask/templates/task/browse_textbooks.html
--- a/pytask/taskapp/urls.py	Tue Jan 11 00:03:57 2011 +0530
+++ b/pytask/taskapp/urls.py	Tue Jan 11 00:23:47 2011 +0530
@@ -1,7 +1,8 @@
 from django.conf.urls.defaults import *
 
 from pytask.taskapp.views import create_task, view_task, claim_task, \
-        select_user, edit_task, create_textbook, view_textbook
+        select_user, edit_task, create_textbook, view_textbook, \
+        browse_textbooks
 
 from pytask.views import under_construction
 
@@ -16,5 +17,6 @@
 
             (r'^textbook/create/$', create_textbook),
             (r'^textbook/view/tid=(\w+)/$', view_textbook),
+            (r'^textbook/browse/$', browse_textbooks),
 )
 
--- a/pytask/taskapp/views.py	Tue Jan 11 00:03:57 2011 +0530
+++ b/pytask/taskapp/views.py	Tue Jan 11 00:23:47 2011 +0530
@@ -225,7 +225,7 @@
 
     user = request.user
     if not user.is_authenticated():
-        return render_to_response("task/view_textbook.html")
+        return render_to_response("task/view_textbook.html", {"user": user})
 
     profile = user.get_profile()
 
@@ -249,6 +249,26 @@
                     "can_approve": can_approve})
     return render_to_response("task/view_textbook.html", context)
 
+def browse_textbooks(request):
+
+    user = request.user
+
+    open_textbooks = TextBook.objects.filter(status="OP").\
+                                      order_by("creation_datetime")
+    comp_textbooks = TextBook.objects.filter(status="CM").\
+                                      order_by("creation_datetime")
+    context = {"user": user,
+               "open_textbooks": open_textbooks,
+               "comp_textbooks": comp_textbooks,
+              }
+
+    if user.is_authenticated() and user.get_profile().rights != "CT":
+        unpub_textbooks = TextBook.objects.filter(status="UP")
+
+        context.update({"unpub_textbooks": unpub_textbooks})
+
+    return render_to_response("task/browse_textbooks.html", context)
+
 @login_required
 def claim_task(request, tid):
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pytask/templates/task/browse_textbooks.html	Tue Jan 11 00:23:47 2011 +0530
@@ -0,0 +1,29 @@
+{% extends 'base.html' %}
+{% block content %}
+    {% if comp_textbooks %}
+    Textbooks that were completed recently<ul>
+    {% for textbook in comp_textbooks %}
+        <li><a href="/task/textbook/view/tid={{ textbook.uniq_key }}">{{ textbook.name }}</a></li>
+    {% endfor %}
+    </ul>
+    <br />
+    {% endif %}
+
+    {% if open_textbooks %}
+    textbooks that are open for contribution<ul>
+    {% for textbook in comp_textbooks %}
+        <li><a href="/task/textbook/view/tid={{ textbook.uniq_key }}">{{ textbook.name }}</a></li>
+    {% endfor %}
+    </ul>
+    <br />
+    {% endif %}
+
+    {% if unpub_textbooks %}
+    Textbooks that have been created but need approval<ul>
+    {% for textbook in unpub_textbooks %}
+        <li><a href="/task/textbook/view/tid={{ textbook.uniq_key }}">{{ textbook.name }}</a></li>
+    {% endfor %}
+    </ul>
+    <br />
+    {% endif %}
+{% endblock %}