485 "can_approve": can_approve}) |
485 "can_approve": can_approve}) |
486 return shortcuts.render_to_response("task/view_textbook.html", |
486 return shortcuts.render_to_response("task/view_textbook.html", |
487 RequestContext(request, context)) |
487 RequestContext(request, context)) |
488 |
488 |
489 def browse_textbooks(request): |
489 def browse_textbooks(request): |
490 |
490 """View to list all the open textbooks. This view fetches tasks |
491 user = request.user |
491 tagged with Textbook. |
492 |
492 """ |
493 open_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[1][0]).\ |
493 |
494 order_by("creation_datetime") |
494 user = request.user |
495 comp_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[3][0]).\ |
495 |
496 order_by("creation_datetime") |
496 # Fetch all the tasks tagged with Textbook |
497 context = {"user": user, |
497 textbooks = taskapp_models.Task.tagged.with_any(['Textbook']) |
498 "open_textbooks": open_textbooks, |
498 |
499 "comp_textbooks": comp_textbooks, |
499 # Get all the textbooks that are Open. |
500 } |
500 open_textbooks = textbooks.filter( |
501 |
501 status=taskapp_models.TASK_STATUS_CHOICES[1][0]).order_by( |
502 if user.is_authenticated() and user.get_profile().role in [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]: |
502 'creation_datetime') |
503 unpub_textbooks = taskapp_models.TextBook.objects.filter(status=taskapp_models.TB_STATUS_CHOICES[0][0]) |
503 |
|
504 context = {'open_textbooks': open_textbooks,} |
|
505 |
|
506 # Nothing |
|
507 if user.is_authenticated() and (user.get_profile().role in |
|
508 [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]): |
|
509 unpub_textbooks = taskapp_models.TextBook.objects.filter( |
|
510 status=taskapp_models.TB_STATUS_CHOICES[0][0]) |
504 |
511 |
505 context.update({"unpub_textbooks": unpub_textbooks}) |
512 context.update({"unpub_textbooks": unpub_textbooks}) |
506 |
513 |
507 return shortcuts.render_to_response("task/browse_textbooks.html", |
514 return shortcuts.render_to_response("task/browse_textbooks.html", |
508 RequestContext(request, context)) |
515 RequestContext(request, context)) |