summaryrefslogtreecommitdiff
path: root/app/posts/views.py
blob: 3e0ac239c7ecd81a34d9c91eca6286ea05ee78ad (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
from django.views.generic import UpdateView, DetailView, ListView 
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q

from .models import Post
from notes.models import Note

class PostListView(LoginRequiredMixin, ListView):
    model = Post 
    template_name = 'posts/post_table.html'

    def get_queryset(self):
        return Post.objects.filter(user=self.request.user).order_by("-needs_update")


class PostNewView(LoginRequiredMixin, ListView):
    template_name = 'posts/post_list.html'
    
    def get_queryset(self):
        return Post.objects.filter(user=self.request.user).filter(is_live=0)

    def get_context_data(self, **kwargs):
        context = super(PostNewView, self).get_context_data(**kwargs)
        context['reviews'] = Note.objects.filter(plan__in=[1,2])
        return context


class PostTodoView(LoginRequiredMixin, ListView):
    template_name = 'posts/post_table.html'
    
    def get_queryset(self):
        qs = Post.objects.filter(user=self.request.user)
        qs = qs.filter(Q(needs_update=True) | Q(is_live=0))
        unsorted_results = qs.all()
        return sorted(unsorted_results, key=lambda a: a.days_overdue(), reverse=True)

    def get_context_data(self, **kwargs):
        context = super(PostTodoView, self).get_context_data(**kwargs)
        context['reviews'] = Note.objects.filter(plan=1)
        return context


class PostNotesView(LoginRequiredMixin, DetailView):
    model = Post