add mini-live edit, for quick fixes
[chloro.git] / chloro / phyll / views.py
index 84b40e7fd0071ba633ceb553ffd05dfc20cafc3f..108a8eaca508bb9f3bfc01b5e8cdb3f2ff0231c8 100644 (file)
@@ -19,8 +19,10 @@ import urllib.parse
 from django.conf import settings
 from django.contrib.syndication.views import Feed
 from django.core.exceptions import PermissionDenied
-from django.http import Http404
+from django.http import HttpResponse, Http404
 from django.utils.feedgenerator import Atom1Feed
+from django.views import View
+from django.views.decorators.csrf import csrf_exempt
 from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView, TemplateView
 
 from .models import Note
@@ -50,6 +52,20 @@ class NoteEditView(UpdateView):
     fields = ['title', 'slug', 'text', 'tags', 'published']
 
 
+class NoteApiSaveView(View):
+    http_method_names = ['post']
+
+    @csrf_exempt
+    def dispatch(self, *args, **kwargs):
+        return super().dispatch(*args, **kwargs)
+
+    def post(self, request, *args, **kwargs):
+        note = Note.objects.get(slug=kwargs['slug'])
+        note.text = request.POST['text']
+        note.save()
+        return HttpResponse('ok')
+
+
 class NoteAddView(CreateView):
     model = Note
     fields = ['title', 'slug', 'text', 'tags', 'published']