forked from mirrors/bookwyrm
First pass at basic RSS
This commit is contained in:
parent
0700a71803
commit
0fe2e7a356
5 changed files with 92 additions and 0 deletions
1
bookwyrm/templates/snippets/rss_content.html
Normal file
1
bookwyrm/templates/snippets/rss_content.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ obj.pure_content | safe }}
|
15
bookwyrm/templates/snippets/rss_title.html
Normal file
15
bookwyrm/templates/snippets/rss_title.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
{{ obj.user.username }}{% if obj.status_type == 'GeneratedNote' %}
|
||||
{{ obj.content | safe }}
|
||||
{% elif obj.status_type == 'Review' and not obj.name and not obj.content%}
|
||||
rated
|
||||
{% elif obj.status_type == 'Review' %}
|
||||
reviewed
|
||||
{% elif obj.status_type == 'Comment' %}
|
||||
commented on
|
||||
{% elif obj.status_type == 'Quotation' %}
|
||||
quoted
|
||||
{% endif %}
|
||||
{% if obj.book %}{{ obj.book.title | safe}}
|
||||
{% elif obj.mention_books %}
|
||||
{{ obj.mention_books.first.title }}
|
||||
{% endif %}
|
44
bookwyrm/tests/views/test_rss_feed.py
Normal file
44
bookwyrm/tests/views/test_rss_feed.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
''' testing import '''
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import RequestFactory, TestCase
|
||||
import responses
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.views import rss_feed
|
||||
from bookwyrm.settings import DOMAIN
|
||||
|
||||
class RssFeed(TestCase):
|
||||
''' rss feed behaves as expected '''
|
||||
def setUp(self):
|
||||
self.user = models.User.objects.create_user(
|
||||
'rss_user', 'rss@test.rss', 'password', local=True)
|
||||
|
||||
work = models.Work.objects.create(title='Test Work')
|
||||
self.book = models.Edition.objects.create(
|
||||
title='Example Edition',
|
||||
remote_id='https://example.com/book/1',
|
||||
parent_work=work
|
||||
)
|
||||
|
||||
self.review = models.Review.objects.create(
|
||||
name='Review name', content='test content', rating=3,
|
||||
user=self.user, book=self.book)
|
||||
|
||||
self.quote = models.Quotation.objects.create(
|
||||
quote='a sickening sense', content='test content',
|
||||
user=self.user, book=self.book)
|
||||
|
||||
self.generatednote = models.GeneratedNote.objects.create(
|
||||
content='test content', user=self.user)
|
||||
|
||||
self.factory = RequestFactory()
|
||||
|
||||
|
||||
def test_rss_feed(self):
|
||||
request = self.factory.get('/user/rss_user/rss')
|
||||
response = RssFeed(request)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(False, True)
|
||||
|
|
@ -3,7 +3,9 @@ from django.conf.urls.static import static
|
|||
from django.contrib import admin
|
||||
from django.urls import path, re_path
|
||||
|
||||
|
||||
from bookwyrm import incoming, settings, views, wellknown
|
||||
from bookwyrm.views.rss_feed import RssFeed
|
||||
from bookwyrm.utils import regex
|
||||
|
||||
user_path = r'^user/(?P<username>%s)' % regex.username
|
||||
|
@ -75,6 +77,7 @@ urlpatterns = [
|
|||
re_path(r'%s/followers(.json)?/?$' % user_path, views.Followers.as_view()),
|
||||
re_path(r'%s/following(.json)?/?$' % user_path, views.Following.as_view()),
|
||||
re_path(r'^edit-profile/?$', views.EditUser.as_view()),
|
||||
re_path(r'%s/rss' % user_path, views.rss_feed.RssFeed()),
|
||||
|
||||
# reading goals
|
||||
re_path(r'%s/goal/(?P<year>\d{4})/?$' % user_path, views.Goal.as_view()),
|
||||
|
|
29
bookwyrm/views/rss_feed.py
Normal file
29
bookwyrm/views/rss_feed.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
''' '''
|
||||
|
||||
from django.contrib.syndication.views import Feed
|
||||
from django.urls import reverse
|
||||
from bookwyrm.models.user import User
|
||||
from .helpers import get_activity_feed, get_user_from_username
|
||||
|
||||
class RssFeed(Feed):
|
||||
|
||||
description_template = "snippets/rss_content.html"
|
||||
title_template = "snippets/rss_title.html"
|
||||
|
||||
def get_object(self, request, username):
|
||||
return get_user_from_username(username)
|
||||
|
||||
def link(self, obj):
|
||||
return obj.local_path
|
||||
|
||||
def title(self, obj):
|
||||
return f"Status updates from {obj.username}"
|
||||
|
||||
|
||||
def items(self, obj):
|
||||
return get_activity_feed(obj, ['public', 'unlisted', 'followers'])
|
||||
|
||||
|
||||
def item_link(self, item):
|
||||
return item.local_path
|
||||
|
Loading…
Reference in a new issue