# HG changeset patch # User Madhusudan.C.S # Date 1295488034 -19800 # Node ID 773e886d9b80f802bc4222b603c4b2f3bd9d53f2 # Parent 066deed9fba0224f88384831a259a00cb9b45803 Textbooks list page should list all the tasks tagged with textbooks. diff -r 066deed9fba0 -r 773e886d9b80 pytask/taskapp/views.py --- 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}) diff -r 066deed9fba0 -r 773e886d9b80 pytask/templates/task/browse_textbooks.html --- a/pytask/templates/task/browse_textbooks.html Thu Jan 20 06:36:38 2011 +0530 +++ b/pytask/templates/task/browse_textbooks.html Thu Jan 20 07:17:14 2011 +0530 @@ -1,6 +1,27 @@ {% extends "base.html" %} {% block content %} + {% if open_textbooks %} + Textbooks that are open for contribution + +
+ {% endif %} + + + + + + + {% comment %} + {% if comp_textbooks %} Textbooks that were completed recently
{% endif %} + {% endcomment %} {% endblock %}