100 'soc.views.models.%(module_name)s.assign_slots', |
102 'soc.views.models.%(module_name)s.assign_slots', |
101 'Assign slots'), |
103 'Assign slots'), |
102 (r'^%(url_name)s/(?P<access_type>slots)/%(key_fields)s$', |
104 (r'^%(url_name)s/(?P<access_type>slots)/%(key_fields)s$', |
103 'soc.views.models.%(module_name)s.slots', |
105 'soc.views.models.%(module_name)s.slots', |
104 'Assign slots (JSON)'), |
106 'Assign slots (JSON)'), |
|
107 (r'^%(url_name)s/(?P<access_type>show_duplicates)/%(key_fields)s$', |
|
108 'soc.views.models.%(module_name)s.show_duplicates', |
|
109 'Show duplicate slot assignments'), |
|
110 (r'^%(url_name)s/(?P<access_type>assigned_proposals)/%(key_fields)s$', |
|
111 'soc.views.models.%(module_name)s.assigned_proposals', |
|
112 "Assigned proposals for multiple orgs"), |
105 ] |
113 ] |
106 |
114 |
107 new_params['extra_django_patterns'] = patterns |
115 new_params['extra_django_patterns'] = patterns |
108 |
|
109 |
116 |
110 # TODO add clean field to check for uniqueness in link_id and scope_path |
117 # TODO add clean field to check for uniqueness in link_id and scope_path |
111 new_params['create_extra_dynaproperties'] = { |
118 new_params['create_extra_dynaproperties'] = { |
112 'description': forms.fields.CharField(widget=helper.widgets.TinyMCE( |
119 'description': forms.fields.CharField(widget=helper.widgets.TinyMCE( |
113 attrs={'rows':10, 'cols':40})), |
120 attrs={'rows':10, 'cols':40})), |
264 'uses_slot_allocator': True, |
271 'uses_slot_allocator': True, |
265 'return_url': return_url, |
272 'return_url': return_url, |
266 } |
273 } |
267 |
274 |
268 return self._list(request, org_params, contents, page_name, context) |
275 return self._list(request, org_params, contents, page_name, context) |
|
276 |
|
277 @decorators.merge_params |
|
278 @decorators.check_access |
|
279 def showDuplicates(self, request, access_type, page_name=None, |
|
280 params=None, **kwargs): |
|
281 """View in which a host can see which students have been assigned multiple slots. |
|
282 |
|
283 For params see base.view.Public(). |
|
284 """ |
|
285 |
|
286 from django.utils import simplejson |
|
287 |
|
288 program_entity = program_logic.logic.getFromKeyFieldsOr404(kwargs) |
|
289 |
|
290 context = helper.responses.getUniversalContext(request) |
|
291 context['page_name'] = page_name |
|
292 |
|
293 # get all orgs for this program who are active and have slots assigned |
|
294 fields = {'scope': program_entity, |
|
295 'slots >': 0, |
|
296 'status': 'active'} |
|
297 |
|
298 query = org_logic.logic.getQueryForFields(fields) |
|
299 |
|
300 to_json = { |
|
301 'nr_of_orgs': query.count(), |
|
302 'program_key': program_entity.key().name()} |
|
303 json = simplejson.dumps(to_json) |
|
304 context['info'] = json |
|
305 |
|
306 # TODO(ljvderijk) cache the result of the duplicate calculation |
|
307 context['duplicate_cache_content'] = simplejson.dumps({}) |
|
308 |
|
309 template = 'soc/program/show_duplicates.html' |
|
310 |
|
311 return helper.responses.respond(request, template=template, context=context) |
|
312 |
|
313 @decorators.merge_params |
|
314 @decorators.check_access |
|
315 def assignedProposals(self, request, access_type, page_name=None, |
|
316 params=None, filter=None, **kwargs): |
|
317 """Returns a JSON dict containing all the proposals that would have |
|
318 a slot assigned for a specific set of orgs. |
|
319 |
|
320 The request.GET limit and offset determines how many and which |
|
321 organizations should be returned. |
|
322 |
|
323 For params see base.View.public(). |
|
324 |
|
325 Returns: JSON object with a collection of orgs and proposals. Containing |
|
326 identification information and contact information. |
|
327 """ |
|
328 |
|
329 get_dict = request.GET |
|
330 |
|
331 if not (get_dict.get('limit') or get_dict.get('offset')): |
|
332 return self.json(request, {}) |
|
333 |
|
334 try: |
|
335 limit = max(0, int(get_dict['limit'])) |
|
336 offset = max(0, int(get_dict['offset'])) |
|
337 except ValueError: |
|
338 return self.json(request, {}) |
|
339 |
|
340 program_entity = program_logic.logic.getFromKeyFieldsOr404(kwargs) |
|
341 |
|
342 fields = {'scope': program_entity, |
|
343 'slots >': 0, |
|
344 'status': 'active'} |
|
345 |
|
346 org_entities = org_logic.logic.getForFields(fields, limit=limit, offset=offset) |
|
347 |
|
348 orgs_data = {} |
|
349 proposals_data = {} |
|
350 |
|
351 # for each org get the proposals who will be assigned a slot |
|
352 for org in org_entities: |
|
353 |
|
354 org_data = {'name': org.name} |
|
355 |
|
356 fields = {'scope': org, |
|
357 'status': 'active', |
|
358 'user': org.founder} |
|
359 |
|
360 org_admin = org_admin_logic.logic.getForFields(fields, unique=True) |
|
361 |
|
362 if org_admin: |
|
363 org_data['admin_name'] = org_admin.name() |
|
364 org_data['admin_email'] = org_admin.email |
|
365 |
|
366 # check if there are already slots taken by this org |
|
367 fields = {'org': org, |
|
368 'status': 'accepted'} |
|
369 |
|
370 query = student_proposal_logic.logic.getQueryForFields(fields) |
|
371 test = query.count() |
|
372 |
|
373 slots_left_to_assign = max(0, org.slots - query.count()) |
|
374 |
|
375 if slots_left_to_assign == 0: |
|
376 # no slots left so next org |
|
377 continue |
|
378 |
|
379 # store information about the org |
|
380 orgs_data[org.key().name()] = org_data |
|
381 |
|
382 fields = {'org': org, |
|
383 'mentor !=': None, |
|
384 'status': 'pending'} |
|
385 order = ['-score'] |
|
386 |
|
387 # get the the number of proposals that would be assigned a slot |
|
388 student_proposal_entities = student_proposal_logic.logic.getForFields( |
|
389 fields, limit=slots_left_to_assign, order=order) |
|
390 |
|
391 proposal_data = {} |
|
392 |
|
393 # store each proposal in the dictionary |
|
394 for proposal in student_proposal_entities: |
|
395 student_entity = proposal.scope |
|
396 |
|
397 proposals_data[proposal.key().name()] = { |
|
398 'proposal_title': proposal.title, |
|
399 'student_key': student_entity.key().name(), |
|
400 'student_name': student_entity.name(), |
|
401 'student_contact': student_entity.email, |
|
402 'org_key': org.key().name() |
|
403 } |
|
404 |
|
405 # store it with the other org data |
|
406 proposals_data['proposals'] = proposal_data |
|
407 |
|
408 # return all the data in JSON format |
|
409 data = {'orgs': orgs_data, |
|
410 'proposals': proposals_data} |
|
411 |
|
412 return self.json(request, data) |
269 |
413 |
270 def _editPost(self, request, entity, fields): |
414 def _editPost(self, request, entity, fields): |
271 """See base._editPost(). |
415 """See base._editPost(). |
272 """ |
416 """ |
273 |
417 |
465 |
609 |
466 view = View() |
610 view = View() |
467 |
611 |
468 admin = decorators.view(view.admin) |
612 admin = decorators.view(view.admin) |
469 assign_slots = decorators.view(view.assignSlots) |
613 assign_slots = decorators.view(view.assignSlots) |
|
614 assigned_proposals = decorators.view(view.assignedProposals) |
470 create = decorators.view(view.create) |
615 create = decorators.view(view.create) |
471 delete = decorators.view(view.delete) |
616 delete = decorators.view(view.delete) |
472 edit = decorators.view(view.edit) |
617 edit = decorators.view(view.edit) |
473 list = decorators.view(view.list) |
618 list = decorators.view(view.list) |
474 public = decorators.view(view.public) |
619 public = decorators.view(view.public) |
475 export = decorators.view(view.export) |
620 export = decorators.view(view.export) |
|
621 show_duplicates = decorators.view(view.showDuplicates) |
476 slots = decorators.view(view.slots) |
622 slots = decorators.view(view.slots) |
477 home = decorators.view(view.home) |
623 home = decorators.view(view.home) |
478 pick = decorators.view(view.pick) |
624 pick = decorators.view(view.pick) |