app/soc/views/models/program.py
changeset 2139 43a02512ebf7
parent 2136 5d55e61dd338
child 2140 32b0731f0bf5
equal deleted inserted replaced
2138:70b4a5e90eb0 2139:43a02512ebf7
   301       submit = request.GET.get('submit')
   301       submit = request.GET.get('submit')
   302 
   302 
   303       from_json = simplejson.loads(result)
   303       from_json = simplejson.loads(result)
   304       locked_slots = dicts.groupDictBy(from_json, 'locked', 'slots')
   304       locked_slots = dicts.groupDictBy(from_json, 'locked', 'slots')
   305 
   305 
       
   306       if submit:
       
   307         program.slots_allocation = result
       
   308         program.put()
       
   309 
   306     orgs = {}
   310     orgs = {}
   307     applications = {}
   311     applications = {}
   308     max = {}
   312     max = {}
   309 
   313 
   310     for org in organizations:
   314     for org in organizations:
   311       orgs[org.link_id] = org
   315       orgs[org.link_id] = org
   312       applications[org.link_id] = org.nr_applications
   316       applications[org.link_id] = org.nr_applications
   313       max[org.link_id] = min(org.nr_mentors, org.slots_desired)
   317       max[org.link_id] = min(org.nr_mentors, org.slots_desired)
   314 
   318 
   315       if submit:
   319     max_slots_per_org = program.max_slots
   316         org_post = from_json[org.link_id]
   320     min_slots_per_org = program.min_slots
   317         org_slots = org_post['slots']
   321     algorithm = 1
   318         try:
       
   319           org_slots = int(org_slots)
       
   320         except ValueError:
       
   321           continue
       
   322         org.slots = org_slots
       
   323         org.put()
       
   324 
       
   325     # TODO: Use configuration variables here
       
   326     max_slots_per_org = 50
       
   327     min_slots_per_org = 2
       
   328     iterative = False
       
   329 
   322 
   330     allocator = allocations.Allocator(orgs.keys(), applications, max,
   323     allocator = allocations.Allocator(orgs.keys(), applications, max,
   331                                       program_slots, max_slots_per_org,
   324                                       program_slots, max_slots_per_org,
   332                                       min_slots_per_org, iterative)
   325                                       min_slots_per_org, algorithm)
   333 
   326 
   334     result = allocator.allocate(locked_slots)
   327     result = allocator.allocate(locked_slots)
   335 
   328 
   336     data = []
   329     data = []
   337 
   330 
       
   331     # TODO: remove adjustment here and in the JS
   338     for link_id, count in result.iteritems():
   332     for link_id, count in result.iteritems():
   339       org = orgs[link_id]
   333       org = orgs[link_id]
   340       data.append({
   334       data.append({
   341           'link_id': link_id,
   335           'link_id': link_id,
   342           'slots': count,
   336           'slots': count,