506 |
506 |
507 if org_admin: |
507 if org_admin: |
508 org_data['admin_name'] = org_admin.name() |
508 org_data['admin_name'] = org_admin.name() |
509 org_data['admin_email'] = org_admin.email |
509 org_data['admin_email'] = org_admin.email |
510 |
510 |
511 # check if there are already slots taken by this org |
511 proposals = student_proposal_logic.logic.getProposalsToBeAcceptedForOrg( |
512 fields = {'org': org, |
512 org, stepsize=program_entity.max_slots) |
513 'status': 'accepted'} |
513 |
514 |
514 if not proposals: |
515 query = student_proposal_logic.logic.getQueryForFields(fields) |
515 # nothing to accept, next organization |
516 |
|
517 slots_left_to_assign = max(0, org.slots - query.count()) |
|
518 |
|
519 if slots_left_to_assign == 0: |
|
520 # no slots left so next org |
|
521 continue |
516 continue |
522 |
517 |
523 # store information about the org |
518 # store information about the org |
524 orgs_data[org.key().id_or_name()] = org_data |
519 orgs_data[org.key().id_or_name()] = org_data |
525 |
|
526 fields = {'org': org, |
|
527 'status': 'pending'} |
|
528 order = ['-score'] |
|
529 |
|
530 # get the the number of proposals that would be assigned a slot |
|
531 query = student_proposal_logic.logic.getQueryForFields( |
|
532 fields, order=order) |
|
533 |
|
534 proposals = query.fetch(slots_left_to_assign) |
|
535 proposals = [i for i in proposals if i.mentor] |
|
536 |
|
537 offset = slots_left_to_assign |
|
538 stepsize = program_entity.max_slots |
|
539 |
|
540 # retrieve as many additional proposals as needed in case the top |
|
541 # N do not have a mentor assigned |
|
542 while len(proposals) < slots_left_to_assign: |
|
543 new_proposals = query.fetch(stepsize, offset=offset) |
|
544 # we ran out of proposals |
|
545 if not new_proposals: |
|
546 break |
|
547 |
|
548 new_proposals = [i for i in new_proposals if i.mentor] |
|
549 proposals += new_proposals |
|
550 offset += stepsize |
|
551 |
|
552 # cut off any superfluas proposals |
|
553 del proposals[slots_left_to_assign:] |
|
554 |
520 |
555 # store each proposal in the dictionary |
521 # store each proposal in the dictionary |
556 for proposal in proposals: |
522 for proposal in proposals: |
557 student_entity = proposal.scope |
523 student_entity = proposal.scope |
558 |
524 |