Skip to content

Instantly share code, notes, and snippets.

@0x46616c6b
Created January 14, 2011 17:30
Show Gist options
  • Save 0x46616c6b/779925 to your computer and use it in GitHub Desktop.
Save 0x46616c6b/779925 to your computer and use it in GitHub Desktop.
function submitNewEntry() {
var text = $('.new-entry').val();
if (text == 'Neuen Eintrag schreiben...')
return false;
if ( $('.is-public:checkbox:checked').val() == 'on' )
var isPublic = parseInt(1);
else
var isPublic = parseInt(0);
new_entry = "{ text : '" + text + "', isPublic: " + isPublic + " }"
$.ajax({
type: "POST",
// format: { "text" : "text body", "isPublic" : 0|1 }
data: { "new_entry" : new_entry, "submit" : "submit", "format" : "json" },
success: function() {
$('.new-entry').val('Neuen Eintrag schreiben...');
getEntries('reload');
}
});
}
def manage(request):
if (request.method == 'POST'):
if ('format' in request.POST):
format = request.POST['format']
else:
format = 'json'
if ('submit' in request.POST) and (format == 'json'):
if ('new_entry' in request.POST):
# format: { "text" : "text body", "isPublic" : 0|1 }
entry = json.loads(request.POST['new_entry'])
entry_text = escape(entry.get('text'))
entry_published = datetime.now()
entry_isPublic = int(entry.get('isPublic'))
new_entry = Entry(text=entry_text, published=entry_published, isPublic=entry_isPublic)
new_entry.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment