Add a submit method and button to slots view
authorSverre Rabbelier <srabbelier@gmail.com>
Wed, 08 Apr 2009 23:45:41 +0000
changeset 2136 5d55e61dd338
parent 2135 cafa4caec14f
child 2137 3d5692ae414c
Add a submit method and button to slots view Patch by: Sverre Rabbelier
app/soc/content/js/slot-allocator-090320.js
app/soc/templates/soc/program/allocation/allocation.html
app/soc/views/models/program.py
--- a/app/soc/content/js/slot-allocator-090320.js	Wed Apr 08 22:47:46 2009 +0000
+++ b/app/soc/content/js/slot-allocator-090320.js	Wed Apr 08 23:45:41 2009 +0000
@@ -52,6 +52,11 @@
   $.postJSON(url, current_slots, updateFromJSON);
 }
 
+function submit() {
+  url = RETURN_URL+"?submit=1&_="+(new Date().getTime())
+  $.postJSON(url, current_slots, updateFromJSON);
+}
+
 function updateOverlay() {
   updateCurrentSlots();
   var remaining_slots = MAX_AVAILABLE_SLOTS - current_allocated_slots;
--- a/app/soc/templates/soc/program/allocation/allocation.html	Wed Apr 08 22:47:46 2009 +0000
+++ b/app/soc/templates/soc/program/allocation/allocation.html	Wed Apr 08 23:45:41 2009 +0000
@@ -19,6 +19,8 @@
 {% block body %}
 
 <input type="button" class="button" onclick="javascript:reCalculate()" value="Recalculate slots" />
+<input type="button" class="button" onclick="javascript:submit()" value="Submit" />
 
 {{ block.super }}
+
 {% endblock %}
--- a/app/soc/views/models/program.py	Wed Apr 08 22:47:46 2009 +0000
+++ b/app/soc/views/models/program.py	Wed Apr 08 23:45:41 2009 +0000
@@ -298,9 +298,9 @@
 
     if request.method == 'POST' and 'result' in request.POST:
       result = request.POST['result']
+      submit = request.GET.get('submit')
 
       from_json = simplejson.loads(result)
-
       locked_slots = dicts.groupDictBy(from_json, 'locked', 'slots')
 
     orgs = {}
@@ -312,6 +312,16 @@
       applications[org.link_id] = org.nr_applications
       max[org.link_id] = min(org.nr_mentors, org.slots_desired)
 
+      if submit:
+        org_post = from_json[org.link_id]
+        org_slots = org_post['slots']
+        try:
+          org_slots = int(org_slots)
+        except ValueError:
+          continue
+        org.slots = org_slots
+        org.put()
+
     # TODO: Use configuration variables here
     max_slots_per_org = 50
     min_slots_per_org = 2