diff options
-rwxr-xr-x | pytask/taskapp/views.py | 27 | ||||
-rw-r--r-- | pytask/templates/task/browse_textbooks.html | 24 |
2 files changed, 40 insertions, 11 deletions
diff --git a/pytask/taskapp/views.py b/pytask/taskapp/views.py index e9b9174..e383845 100755 --- a/pytask/taskapp/views.py +++ b/pytask/taskapp/views.py @@ -487,20 +487,27 @@ def view_textbook(request, task_id): 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') + + context = {'open_textbooks': open_textbooks,} - 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]) + # 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 --git a/pytask/templates/task/browse_textbooks.html b/pytask/templates/task/browse_textbooks.html index 7797c2a..4bc7104 100644 --- a/pytask/templates/task/browse_textbooks.html +++ b/pytask/templates/task/browse_textbooks.html @@ -1,6 +1,27 @@ {% extends "base.html" %} {% 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 /> + {% endif %} + + + + + + <!-- TO BE REFORMATTED LATER. JUST PUSHING IT DOWN. --> + {% comment %} + {% if comp_textbooks %} Textbooks that were completed recently <ul> @@ -21,7 +42,7 @@ {% for textbook in open_textbooks %} <li> <a href="{% url view_textbook textbook.id %}"> - {{ textbook.name }} + {{ textbook.title }} </a> </li> {% endfor %} @@ -42,5 +63,6 @@ </ul> <br /> {% endif %} + {% endcomment %} {% endblock %} |