Rewrite meeting PUTs to POSTs. For no apparent reason, parts of the

meeting AJAX code is using PUT instead of POST (even if it's not
PUT'ing in the literal sense but POST'ing). Theoretical discussions
aside, Django has poor support for PUTs turned POSTs so rewriting them
removes the need for a couple of hacks, and makes it easier to test.
 - Legacy-Id: 7067
This commit is contained in:
Ole Laursen 2013-12-24 15:13:33 +00:00
parent 9cab5e8263
commit f8b1568c87
6 changed files with 25 additions and 25 deletions

View file

@ -2,7 +2,7 @@ import json
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, redirect
from django.http import HttpResponseRedirect, HttpResponse, QueryDict
from django.http import HttpResponseRedirect, HttpResponse
from dajaxice.decorators import dajaxice_register
from ietf.ietfauth.utils import role_required, has_role, user_is_person
@ -208,7 +208,7 @@ def timeslot_roomurl(request, num=None, roomid=None):
return HttpResponse(json.dumps(room.json_dict(request.build_absolute_uri('/'))),
content_type="application/json")
# XXX FIXME: timeslot_updroom() doesn't exist
# elif request.method == 'PUT':
# elif request.method == 'POST':
# return timeslot_updroom(request, meeting)
elif request.method == 'DELETE':
return timeslot_delroom(request, meeting, roomid)
@ -275,7 +275,7 @@ def timeslot_sloturl(request, num=None, slotid=None):
slot = get_object_or_404(meeting.timeslot_set, pk=slotid)
return HttpResponse(json.dumps(slot.json_dict(request.build_absolute_uri('/'))),
content_type="application/json")
elif request.method == 'PUT':
elif request.method == 'POST':
# not yet implemented!
#return timeslot_updslot(request, meeting)
return HttpResponse(status=406)
@ -317,8 +317,8 @@ def agenda_add(request, meeting):
@role_required('Area Director','Secretariat')
def agenda_update(request, meeting, schedule):
# forms are completely useless for update actions that want to
# accept a subset of values.
update_dict = QueryDict(request.body, encoding=request._encoding)
# accept a subset of values. (huh? just use required=False)
update_dict = request.POST
#debug.log("99 meeting.agenda: %s / %s / %s" %
# (schedule, update_dict, request.body))
@ -390,7 +390,7 @@ def agenda_infourl(request, num=None, schedule_name=None):
if request.method == 'GET':
return HttpResponse(json.dumps(schedule.json_dict(request.build_absolute_uri('/'))),
content_type="application/json")
elif request.method == 'PUT':
elif request.method == 'POST':
return agenda_update(request, meeting, schedule)
elif request.method == 'DELETE':
return agenda_del(request, meeting, schedule)
@ -409,7 +409,7 @@ def meeting_get(request, meeting):
@role_required('Secretariat')
def meeting_update(request, meeting):
# at present, only the official agenda can be updated from this interface.
update_dict = QueryDict(request.body, encoding=request._encoding)
update_dict = request.POST
#debug.log("1 meeting.agenda: %s / %s / %s" % (meeting.agenda, update_dict, request.body))
if "agenda" in update_dict:
@ -433,7 +433,7 @@ def meeting_json(request, num):
if request.method == 'GET':
return meeting_get(request, meeting)
elif request.method == 'PUT':
elif request.method == 'POST':
return meeting_update(request, meeting)
elif request.method == 'POST':
return meeting_update(request, meeting)

View file

@ -282,7 +282,7 @@ def edit_agenda(request, num=None, schedule_name=None):
##############################################################################
# show the properties associated with an agenda (visible, public)
# this page uses ajax PUT requests to the API
# this page uses ajax POST requests to the API
#
AgendaPropertiesForm = modelform_factory(Schedule, fields=('name','visible', 'public'))

View file

@ -52,7 +52,7 @@
</td></tr></table>
</div>
<form action="{{schedule.json_url}}" method="PUT">
<form action="{{schedule.json_url}}" method="POST">
<fieldset>
<table>
{{ form.as_table }}

View file

@ -52,21 +52,21 @@ function toggle_public(event) {
var agenda_url = $(event.target).closest('tr').attr('href');
var new_value = 1;
log("value "+current_value)
log("value "+current_value);
if(current_value == "public") {
new_value = 0
new_value = 0;
}
event.preventDefault();
$.ajax({ "url": agenda_url,
"type": "PUT",
"type": "POST",
"data": { "public" : new_value },
"dataType": "json",
"success": function(result) {
/* result is a json object */
value = result["public"]
log("new value "+value)
$(span_to_replace).html(value)
value = result["public"];
log("new value "+value);
$(span_to_replace).html(value);
}});
}
@ -76,14 +76,14 @@ function toggle_visible(event) {
var agenda_url = $(event.target).closest('tr').attr('href');
var new_value = 1;
log("value "+current_value)
log("value "+current_value);
if(current_value == "visible") {
new_value = 0
new_value = 0;
}
event.preventDefault();
$.ajax({ "url": agenda_url,
"type": "PUT",
"type": "POST",
"data": { "visible" : new_value },
"dataType": "json",
"success": function(result) {
@ -131,7 +131,7 @@ function toggle_official(event) {
//log("clicked on "+agenda_url+" sending to "+meeting_url);
$.ajax({ "url": meeting_url,
"type": "PUT",
"type": "POST",
"data": { "agenda" : new_value },
"dataType": "json",
"success": function(result) {
@ -151,12 +151,12 @@ function save_agenda(form) {
public_flag = form.elements["public"].checked ? true : false;
visible_flag = form.elements["visible"].checked ? true: false;
console.log("PUT to ",agenda_url," with name:", name_str,
console.log("POST to ",agenda_url," with name:", name_str,
"visible:", visible_flag,
"public:", public_flag);
$.ajax({"url": agenda_url,
"type": "PUT",
"type": "POST",
"data": { "public" : public_flag,
"visible": visible_flag,
"name" : name_str,

View file

@ -58,7 +58,7 @@ function toggle_public(event) {
event.preventDefault();
$.ajax({ "url": agenda_url,
"type": "PUT",
"type": "POST",
"data": { "public" : new_value },
"dataType": "json",
"success": function(result) {
@ -82,7 +82,7 @@ function toggle_visible(event) {
event.preventDefault();
$.ajax({ "url": agenda_url,
"type": "PUT",
"type": "POST",
"data": { "visible" : new_value },
"dataType": "json",
"success": function(result) {

View file

@ -94,7 +94,7 @@ function toggle_official(event) {
log("clicked on "+agenda_url+" sending to "+meeting_url);
$.ajax({ "url": meeting_url,
"type": "PUT",
"type": "POST",
"data": { "agenda" : new_value },
"dataType": "json",
"success": function(result) {