aboutsummaryrefslogtreecommitdiff
path: root/apps/notes/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/notes/views.py')
-rw-r--r--apps/notes/views.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/apps/notes/views.py b/apps/notes/views.py
new file mode 100644
index 0000000..ddb72ed
--- /dev/null
+++ b/apps/notes/views.py
@@ -0,0 +1,41 @@
+from django.views.generic import CreateView, ListView, UpdateView, DeleteView
+from django.views.generic.detail import DetailView
+from django.utils.decorators import method_decorator
+from django.contrib.auth.decorators import login_required
+
+from rest_framework import viewsets
+from .serializers import NoteSerializer, FolderSerializer
+from .models import Note
+from .forms import NoteForm
+
+
+@method_decorator(login_required, name='dispatch')
+class LoggedInCreateViewWithUser(CreateView):
+
+ def get_form_kwargs(self, **kwargs):
+ kwargs = super().get_form_kwargs(**kwargs)
+ kwargs.update({'user': self.request.user})
+ return kwargs
+
+
+class NoteListView(ListView):
+ model = Note
+
+ def get_queryset(self):
+ return Note.objects.filter(created_by=self.request.user)
+
+
+class NoteCreateView(LoggedInCreateViewWithUser):
+ model = Note
+ form_class = NoteForm
+ template_name = "notes/create.html"
+
+
+class NoteViewSet(viewsets.ModelViewSet):
+ """
+ API endpoint that allows users to be viewed or edited.
+ """
+ serializer_class = NoteSerializer
+
+ def get_queryset(self):
+ return Note.objects.filter(created_by=self.request.user).order_by('-date_created')