def slots(self, request, acces_type, page_name=None, params=None, **kwargs): """Returns a JSON object with all orgs allocation. Args: request: the standard Django HTTP request object access_type : the name of the access type which should be checked page_name: the page name displayed in templates as page and header title params: a dict with params for this View, not used """ from django.utils import simplejson program = program_logic.logic.getFromKeyFieldsOr404(kwargs) program_slots = program.slots filter = { 'scope': program, 'status': 'active', } query = org_logic.logic.getQueryForFields(filter=filter) organizations = org_logic.logic.getAll(query) locked_slots = adjusted_slots = {} if request.method == 'POST' and 'result' in request.POST: result = request.POST['result'] submit = request.GET.get('submit') load = request.GET.get('load') stored = program.slots_allocation if load and stored: result = stored from_json = simplejson.loads(result) locked_slots = dicts.groupDictBy(from_json, 'locked', 'slots') if submit: program.slots_allocation = result program.put() orgs = {} applications = {} max = {} for org in organizations: orgs[org.link_id] = org applications[org.link_id] = org.nr_applications max[org.link_id] = min(org.nr_mentors, org.slots_desired) max_slots_per_org = program.max_slots min_slots_per_org = program.min_slots algorithm = 2 allocator = allocations.Allocator(orgs.keys(), applications, max, program_slots, max_slots_per_org, min_slots_per_org, algorithm) result = allocator.allocate(locked_slots) data = [] # TODO: remove adjustment here and in the JS for link_id, count in result.iteritems(): org = orgs[link_id] data.append({ 'link_id': link_id, 'slots': count, 'locked': locked_slots.get(link_id, 0), 'adjustment': adjusted_slots.get(link_id, 0), }) return self.json(request, data)
def slots(self, request, acces_type, page_name=None, params=None, **kwargs): """Returns a JSON object with all orgs allocation. Args: request: the standard Django HTTP request object access_type : the name of the access type which should be checked page_name: the page name displayed in templates as page and header title params: a dict with params for this View, not used """ from django.utils import simplejson program_entity = program_logic.getFromKeyFieldsOr404(kwargs) program_slots = program_entity.slots filter = { 'scope': program_entity, 'status': 'active', } query = org_logic.logic.getQueryForFields(filter=filter) organizations = org_logic.logic.getAll(query) locked_slots = adjusted_slots = {} if request.method == 'POST' and 'result' in request.POST: result = request.POST['result'] submit = request.GET.get('submit') load = request.GET.get('load') stored = program_entity.slots_allocation if load and stored: result = stored from_json = simplejson.loads(result) locked_slots = dicts.groupDictBy(from_json, 'locked', 'slots') if submit: program_entity.slots_allocation = result program_entity.put() orgs = {} applications = {} max = {} for org in organizations: orgs[org.link_id] = org applications[org.link_id] = org.nr_applications max[org.link_id] = min(org.nr_mentors, org.slots_desired) max_slots_per_org = program_entity.max_slots min_slots_per_org = program_entity.min_slots algorithm = 2 allocator = allocations.Allocator(orgs.keys(), applications, max, program_slots, max_slots_per_org, min_slots_per_org, algorithm) result = allocator.allocate(locked_slots) data = [] # TODO: remove adjustment here and in the JS for link_id, count in result.iteritems(): org = orgs[link_id] data.append({ 'link_id': link_id, 'slots': count, 'locked': locked_slots.get(link_id, 0), 'adjustment': adjusted_slots.get(link_id, 0), }) return self.json(request, data)