pytask/taskapp/views.py
changeset 497 6386458d749b
parent 495 773e886d9b80
child 500 42516ec56822
equal deleted inserted replaced
496:eb1982186306 497:6386458d749b
     7 from django.core.context_processors import csrf
     7 from django.core.context_processors import csrf
     8 from django.core.urlresolvers import reverse
     8 from django.core.urlresolvers import reverse
     9 from django.template import RequestContext
     9 from django.template import RequestContext
    10 from django.utils import simplejson as json
    10 from django.utils import simplejson as json
    11 
    11 
       
    12 from tagging.managers import TaggedItem
    12 from tagging.models import Tag
    13 from tagging.models import Tag
    13 
    14 
    14 from pytask.views import show_msg
    15 from pytask.views import show_msg
    15 
    16 
    16 from pytask.profile import models as profile_models
    17 from pytask.profile import models as profile_models
   491     tagged with Textbook.
   492     tagged with Textbook.
   492     """
   493     """
   493 
   494 
   494     user = request.user
   495     user = request.user
   495 
   496 
   496     # Fetch all the tasks tagged with Textbook
       
   497     textbooks = taskapp_models.Task.tagged.with_any(['Textbook'])
       
   498 
   497 
   499     # Get all the textbooks that are Open.
   498     # Get all the textbooks that are Open.
   500     open_textbooks = textbooks.filter(
   499     open_textbooks = taskapp_models.Task.objects.filter(
   501       status=taskapp_models.TASK_STATUS_CHOICES[1][0]).order_by(
   500       status=taskapp_models.TASK_STATUS_CHOICES[1][0]).order_by(
   502       'creation_datetime')
   501       'creation_datetime')
   503 
   502 
   504     context = {'open_textbooks': open_textbooks,}
   503 
       
   504     context = {
       
   505       'aero_textbooks': TaggedItem.objects.get_by_model(
       
   506         open_textbooks, ['Textbook', 'Aerospace']),
       
   507       'chemical_textbooks': TaggedItem.objects.get_by_model(
       
   508         open_textbooks, ['Textbook', 'Chemical']),
       
   509       'computerscience_textbooks': TaggedItem.objects.get_by_model(
       
   510         open_textbooks, ['Textbook', 'ComputerScience']),
       
   511       'electrical_textbooks': TaggedItem.objects.get_by_model(
       
   512         open_textbooks, ['Textbook', 'Electrical']),
       
   513       'engineeringphysics_textbooks': TaggedItem.objects.get_by_model(
       
   514         open_textbooks, ['Textbook', 'EngineeringPhysics']),
       
   515       'mechanical_textbooks': TaggedItem.objects.get_by_model(
       
   516         open_textbooks, ['Mechanical', 'Textbook']),
       
   517       'metallurgical_textbooks': TaggedItem.objects.get_by_model(
       
   518         open_textbooks, ['Textbook', 'Metallurgical']),
       
   519       }
   505 
   520 
   506     # Nothing
   521     # Nothing
   507     if user.is_authenticated() and (user.get_profile().role in
   522     if user.is_authenticated() and (user.get_profile().role in
   508       [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]):
   523       [profile_models.ROLES_CHOICES[0][0], profile_models.ROLES_CHOICES[1][0]]):
   509         unpub_textbooks = taskapp_models.TextBook.objects.filter(
   524         unpub_textbooks = taskapp_models.TextBook.objects.filter(