Created
October 6, 2017 04:40
-
-
Save paltman/67136c56943334be704d11540e1593ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ajax_notes_update(request, notebook_pk, pk): | |
notebook = get_object_or_404(Notebook, pk=notebook_pk) | |
data = {} | |
note = get_object_or_404(notebook.note_set, pk=pk) | |
if request.method == "POST": | |
form = NoteForm(request.POST, instance=note) | |
post_url = reverse("ajax_notes_update", kwargs=dict(notebook_pk=notebook.pk, pk=pk)) | |
if form.is_valid(): | |
note = form.save() | |
form = NoteForm() | |
post_url = reverse("ajax_notes_create", kwargs=dict(notebook_pk=notebook.pk)) | |
data["fragments"] = { | |
"#note-{}".format(note.pk): render_to_string("_note.html", {"note": note}) | |
} | |
else: | |
form = NoteForm(instance=note) | |
post_url = reverse("ajax_notes_update", kwargs=dict(notebook_pk=notebook.pk, pk=pk)) | |
data["html"] = render_to_string("_note_form.html", { | |
"note": note, | |
"form": form, | |
"post_url": post_url | |
}, request) | |
return JsonResponse(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment