app/soc/views/models/program.py
changeset 2180 7b8dcd7aab75
parent 2160 3f9dd37d98a8
child 2194 d5d061b0dfd0
equal deleted inserted replaced
2179:efc3a50a81ef 2180:7b8dcd7aab75
   521 
   521 
   522       # store information about the org
   522       # store information about the org
   523       orgs_data[org.key().id_or_name()] = org_data
   523       orgs_data[org.key().id_or_name()] = org_data
   524 
   524 
   525       fields = {'org': org,
   525       fields = {'org': org,
   526                 'mentor !=': None,
       
   527                 'status': 'pending'}
   526                 'status': 'pending'}
   528       order = ['-score']
   527       order = ['-score']
   529 
   528 
   530       # get the the number of proposals that would be assigned a slot
   529       # get the the number of proposals that would be assigned a slot
   531       student_proposal_entities = student_proposal_logic.logic.getForFields(
   530       query = student_proposal_logic.logic.getQueryForFields(
   532           fields, limit=slots_left_to_assign, order=order)
   531           fields, order=order)
       
   532 
       
   533       proposals = query.fetch(slots_left_to_assign)
       
   534       proposals = [i for i in proposals if i.mentor]
       
   535 
       
   536       offset = slots_left_to_assign
       
   537       stepsize = program_entity.max_slots
       
   538 
       
   539       # retrieve as many additional proposals as needed in case the top
       
   540       # N do not have a mentor assigned
       
   541       while len(proposals) < slots_left_to_assign:
       
   542         new_proposals = query.fetch(stepsize, offset=offset)
       
   543         # we ran out of proposals
       
   544         if not new_proposals:
       
   545           break
       
   546 
       
   547         new_proposals = [i for i in new_proposals if i.mentor]
       
   548         proposals += new_proposals
       
   549         offset += stepsize
       
   550 
       
   551       # cut off any superfluas proposals
       
   552       del proposals[slots_left_to_assign:]
   533 
   553 
   534       # store each proposal in the dictionary
   554       # store each proposal in the dictionary
   535       for proposal in student_proposal_entities:
   555       for proposal in proposals:
   536         student_entity = proposal.scope
   556         student_entity = proposal.scope
   537 
   557 
   538         proposals_data.append(
   558         proposals_data.append(
   539             {'key_name': proposal.key().id_or_name(),
   559             {'key_name': proposal.key().id_or_name(),
   540             'proposal_title': proposal.title,
   560             'proposal_title': proposal.title,