app/soc/views/models/organization.py
changeset 1685 4b48cd4e4aa9
parent 1683 866667e9343d
child 1700 599a5ff8f422
equal deleted inserted replaced
1684:83010029e2fb 1685:4b48cd4e4aa9
    21     '"Augie Fackler" <durin42@gmail.com>',
    21     '"Augie Fackler" <durin42@gmail.com>',
    22     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
    22     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
    23     '"Lennard de Rijk" <ljvderijk@gmail.com>',
    23     '"Lennard de Rijk" <ljvderijk@gmail.com>',
    24   ]
    24   ]
    25 
    25 
       
    26 
       
    27 import itertools
    26 
    28 
    27 from django import forms
    29 from django import forms
    28 from django.utils.translation import ugettext
    30 from django.utils.translation import ugettext
    29 
    31 
    30 from soc.logic import cleaning
    32 from soc.logic import cleaning
   184     """Lists all proposals for the organization given in kwargs.
   186     """Lists all proposals for the organization given in kwargs.
   185 
   187 
   186     For params see base.View.public().
   188     For params see base.View.public().
   187     """
   189     """
   188 
   190 
       
   191     from soc.logic.models.ranker_root import logic as ranker_root_logic
       
   192     from soc.models import student_proposal
   189     from soc.views.models import student_proposal as student_proposal_view
   193     from soc.views.models import student_proposal as student_proposal_view
   190 
   194 
   191     try:
   195     try:
   192       org_entity = self._logic.getFromKeyFieldsOr404(kwargs)
   196       org_entity = self._logic.getFromKeyFieldsOr404(kwargs)
   193     except out_of_band.Error, error:
   197     except out_of_band.Error, error:
   194       return helper.responses.errorResponse(
   198       return helper.responses.errorResponse(
   195           error, request, template=params['error_public'])
   199           error, request, template=params['error_public'])
   196 
   200 
   197     list_params = student_proposal_view.view.getParams().copy()
   201     list_params = student_proposal_view.view.getParams().copy()
   198     list_params['list_row'] = ('soc/%(module_name)s/list/'
   202 
       
   203     ranked_params = list_params.copy()# ranked proposals
       
   204     ranked_params['list_row'] = ('soc/%(module_name)s/list/'
   199         'detailed_row.html' % list_params)
   205         'detailed_row.html' % list_params)
   200     list_params['list_heading'] = ('soc/%(module_name)s/list/'
   206     ranked_params['list_heading'] = ('soc/%(module_name)s/list/'
   201         'detailed_heading.html' % list_params)
   207         'detailed_heading.html' % list_params)
   202 
       
   203     ranked_params = list_params.copy()# ranked proposals
       
   204     ranked_params['list_description'] = 'List of %s send to %s ' % (
   208     ranked_params['list_description'] = 'List of %s send to %s ' % (
   205         ranked_params['name_plural'], org_entity.name)
   209         ranked_params['name_plural'], org_entity.name)
   206     ranked_params['list_action'] = (redirects.getReviewRedirect, ranked_params)
   210     ranked_params['list_action'] = (redirects.getReviewRedirect, ranked_params)
   207 
   211 
   208     # TODO(ljvderijk) once sorting with IN operator is fixed, 
   212     # TODO(ljvderijk) once sorting with IN operator is fixed, 
   214     order = ['-score']
   218     order = ['-score']
   215 
   219 
   216     prop_list = lists.getListContent(
   220     prop_list = lists.getListContent(
   217         request, ranked_params, filter, order=order, idx=0)
   221         request, ranked_params, filter, order=order, idx=0)
   218 
   222 
       
   223     proposals = prop_list['data']
       
   224 
       
   225     # get a list of scores
       
   226     scores = [[proposal.score] for proposal in proposals]
       
   227 
       
   228     # retrieve the ranker
       
   229     fields = {'link_id': student_proposal.DEF_RANKER_NAME,
       
   230                 'scope': org_entity}
       
   231 
       
   232     ranker_root = ranker_root_logic.getForFields(fields, unique=True)
       
   233     ranker = ranker_root_logic.getRootFromEntity(ranker_root)
       
   234 
       
   235     # retrieve the ranks for these scores
       
   236     ranks = [rank+1 for rank in ranker.FindRanks(scores)]
       
   237 
       
   238     # link the proposals to the rank
       
   239     ranking = dict([i for i in itertools.izip(proposals, ranks)])
       
   240 
       
   241     # update the prop_list with the ranking information
       
   242     prop_list['info'] = ((lambda item, cache: {'rank': cache[item]}), ranking)
       
   243 
   219     new_params = list_params.copy() # new proposals
   244     new_params = list_params.copy() # new proposals
   220     new_params['list_description'] = 'List of new %s send to %s ' %(
   245     new_params['list_description'] = 'List of new %s send to %s ' %(
   221         new_params['name_plural'], org_entity.name)
   246         new_params['name_plural'], org_entity.name)
   222     new_params['list_action'] = (redirects.getReviewRedirect, new_params)
   247     new_params['list_action'] = (redirects.getReviewRedirect, new_params)
   223 
   248 
   224     filter['status'] = 'new'
   249     filter = {'org': org_entity,
       
   250         'status': 'new'}
   225 
   251 
   226     new_list = lists.getListContent(
   252     new_list = lists.getListContent(
   227         request, new_params, filter, idx=1)
   253         request, new_params, filter, idx=1)
   228 
   254 
   229     # fill contents with all the needed lists
   255     # fill contents with all the needed lists