summaryrefslogtreecommitdiff
path: root/app/notes/views.py
blob: 86ad574fd9efae78d60d2878d4895713f0e6411b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from django.views.generic import UpdateView, DetailView, ListView 
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from django.urls import reverse

from .models import Note
from .forms import NoteCreateForm


class NoteCreateView(CreateView):
    model = Note
    form_class = NoteCreateForm

    def get_form_kwargs(self):
       kwargs = super(NoteCreateView, self).get_form_kwargs()
       kwargs.update({'user': self.request.user})
       return kwargs

    def get_success_url(self):
        return reverse('posts:detail', kwargs={"pk": self.object.post.pk})


class NoteUpdateView(UpdateView):
    model = Note
    fields = ['title', 'url', 'body_markdown', 'post', 'status', 'user']
    
    def get_context_data(self, **kwargs):
        context = super(NoteUpdateView, self).get_context_data(**kwargs)
        context['is_update'] = True
        return context

    def get_success_url(self):
        return reverse('posts:detail', kwargs={"pk": self.object.post.pk})


class NoteListView(ListView):
    model = Note

    def get_queryset(self):
        if self.kwargs['status']:
            if self.kwargs['status'] == "todo":
                status = "Call In"
            else:
                status = self.kwargs['status']
            status_reverse = dict((v, k) for k, v in Note.STATUS)
            qs = Note.objects.filter(user=self.request.user).filter(status=status_reverse[status])
        qs = Note.objects.filter(user=self.request.user)
        return qs