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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
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 django.urls import reverse
from .models import Post
from .forms import PostUpdateForm
from notes.models import Note
"""
TODO:
crawl the RSS feed and compare url to stored url
if it matches update the pub_date.
Then scrape the HTML.
Then parse the scraped html for aff links and create products from them
"""
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], status__in=[0,1,2,3])
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
class PostUpdateView(LoginRequiredMixin, UpdateView):
model = Post
form_class = PostUpdateForm
def get_form_kwargs(self):
kwargs = super(PostUpdateView, self).get_form_kwargs()
kwargs.update({'user': self.request.user})
return kwargs
def get_success_url(self):
if 'add_new' in self.request.POST:
return reverse('posts:create')
else:
return reverse('posts:detail', kwargs={"pk": self.object.pk})
|