示例#1
0
def add_chapter(request, book_id, chapter_id):
	if request.POST:
		print 'Raw Data: "%s"' % request.raw_post_data 
		json_data = simplejson.loads(request.raw_post_data)
	else:
		to_json = {'success' : False }
		return HttpResponse(simplejson.dumps(to_json), mimetype='application/json')
		
	myBook = Book.objects.get(id=book_id)
	parentChap = Chapter.objects.get(id=chapter_id)
		
	newChapter = Chapter(title=json_data['title'], story=json_data['story'], book=myBook, parentChapter=parentChap)
	newChapter.save()
	to_json = { 'success' : True, 'Chapter ID' : str(newChapter.id) }
				
	return HttpResponse(simplejson.dumps(to_json), mimetype='application/json')		
示例#2
0
def new_book(request):
	#try to make a new book with the passed in data
	if request.POST:
		print 'Raw Data: "%s"' % request.raw_post_data 
		json_data = simplejson.loads(request.raw_post_data)
	
	if json_data:
		#try to create our chapter now
		newBook = Book(title=json_data['title'],tagline=json_data['tagline'])
		newBook.save()	
		newChapter = Chapter(title=json_data['chapter title'], story=json_data['chapter story'], book=newBook)
		newChapter.save()
		to_json = { 'success' : True, 'Book ID' : str(newBook.id) }
	else:
		to_json = { 'success' : False }
		
	return HttpResponse(simplejson.dumps(to_json), mimetype='application/json')