This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeeds.py
96 lines (73 loc) · 3.13 KB
/
feeds.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from django.contrib.syndication.feeds import Feed
from django.contrib.syndication.feeds import FeedDoesNotExist
from django.core.exceptions import ObjectDoesNotExist
from reportingon.questions.models import Question
from tagging.models import Tag, TaggedItem
from django.contrib.comments.models import Comment
from django.contrib.auth.models import User
class LatestQuestions(Feed):
title = "The latest questions from ReportingOn"
link = "/questions/"
description = "The most recent queries on topics from reporters like you"
def items(self):
return Question.objects.order_by('-created')[:10]
class LatestQuestionsByUser(Feed):
def get_object(self, bits):
if len(bits) != 1:
raise ObjectDoesNotExist
return User.objects.get(username__iexact=bits[0])
def title(self, obj):
name = "%s %s" % (obj.first_name, obj.last_name)
return "ReportingOn: The latest questions from %s%s" % (obj.username, " (%s)" % name if name is not '' else '')
def link(self, obj):
if not obj:
raise FeedDoesNotExist
return 'users/%s' % obj.id
def description(self, obj):
return "The most recent questions asked by %s" % obj.username
def items(self, obj):
return Question.objects.filter(author=obj).order_by('-created')
class LatestAnswersByQuestion(Feed):
def get_object(self, bits):
if len(bits) == 0 or len(bits) > 2:
raise ObjectDoesNotExist
return Question.objects.get(id__iexact=bits[0])
def title(self, obj):
return "ReportingOn: The latest answers to %s" % obj.question
def link(self, obj):
if not obj:
raise FeedDoesNotExist
return 'questions/%s/%s' % (obj.id, obj.slug)
def description(self, obj):
return "The most recent answers to the question %s" % obj.question
def items(self, obj):
return Comment.objects.filter(object_pk__iexact=obj.id).order_by('-submit_date')
class LatestQuestionsBySearch(Feed):
def get_object(self, bits):
return bits[0]
def title(self, obj):
return "ReportingOn search for %s" % obj
def link(self, obj):
return 'search/%s' % obj
def description(self, obj):
return "New question search results for %s" % obj
def items(self, obj):
raw_results = Question.search.query(obj)
raw_count = raw_results.count()
results = raw_results[0:raw_count if raw_count < 10 else 10]
return results
class LatestQuestionsByBeat(Feed):
def get_object(self, bits):
if len(bits) != 1:
raise ObjectDoesNotExist
return Tag.objects.get(name__iexact=bits[0])
def title(self, obj):
return "ReportingOn: The latest questions in %s" % obj.name
def link(self, obj):
if not obj:
raise FeedDoesNotExist
return 'beats/%s' % obj.name
def description(self, obj):
return "The most recent questions categorized in %s" % obj.name
def items(self, obj):
return Question.objects.filter(tags__icontains=obj.name).order_by('-created')[:10]