diff --git a/woodwind/models.py b/woodwind/models.py
index b46bb3a..c64a043 100644
--- a/woodwind/models.py
+++ b/woodwind/models.py
@@ -142,6 +142,8 @@ class Entry(db.Model):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
+
+ self.subscription = None
self._syndicated_copies = []
def get_property(self, key, default=None):
diff --git a/woodwind/tasks.py b/woodwind/tasks.py
index 1e46e18..c256969 100644
--- a/woodwind/tasks.py
+++ b/woodwind/tasks.py
@@ -237,13 +237,16 @@ def notify_feed_updated(session, feed, entries):
for s in feed.subscriptions:
with flask_app.test_request_context():
flask_login.login_user(s.user, remember=True)
+ rendered = []
+ for e in entries:
+ e.subscription = s
+ rendered.append(render_template('_entry.jinja2', entry=e))
+
message = json.dumps({
'user': s.user.id,
'feed': feed.id,
- 'entries': [
- render_template('_entry.jinja2', feed=feed, entry=e)
- for e in entries
- ],
+ 'subscription': s.id,
+ 'entries': rendered,
})
for topic in ('user:{}'.format(s.user.id),
'subsc:{}'.format(s.id)):
diff --git a/woodwind/templates/_entry.jinja2 b/woodwind/templates/_entry.jinja2
index 618402c..9e52968 100644
--- a/woodwind/templates/_entry.jinja2
+++ b/woodwind/templates/_entry.jinja2
@@ -31,10 +31,10 @@
{% if entry.author_name %}
{{ entry.author_name }} -
{% endif %}
- {% if entry.feed %}
- {{ entry.feed.name }}
+ {% if entry.subscription %}
+ {{ entry.subscription.name }}
- more from this feed
+ more from this feed
{% endif %}
diff --git a/woodwind/util.py b/woodwind/util.py
index c8df9a7..2f1436a 100644
--- a/woodwind/util.py
+++ b/woodwind/util.py
@@ -1,10 +1,12 @@
import bleach
import re
-bleach.ALLOWED_TAGS += ['a', 'img', 'p', 'br', 'marquee', 'blink',
- 'audio', 'video', 'table', 'tbody', 'td', 'tr',
- 'div', 'span', 'pre',
+bleach.ALLOWED_TAGS += [
+ 'a', 'img', 'p', 'br', 'marquee', 'blink',
+ 'audio', 'video', 'table', 'tbody', 'td', 'tr', 'div', 'span',
+ 'pre',
]
+
bleach.ALLOWED_ATTRIBUTES.update({
'img': ['src', 'alt', 'title'],
'audio': ['preload', 'controls', 'src'],
@@ -12,6 +14,7 @@ bleach.ALLOWED_ATTRIBUTES.update({
'td': ['colspan'],
})
+
def clean(text):
"""Strip script tags and other possibly dangerous content
"""
diff --git a/woodwind/views.py b/woodwind/views.py
index 4e391c1..6f7ff91 100644
--- a/woodwind/views.py
+++ b/woodwind/views.py
@@ -25,7 +25,7 @@ def index():
ws_topic = None
solo = False
all_tags = set()
-
+
if flask_login.current_user.is_authenticated():
for subsc in flask_login.current_user.subscriptions:
if subsc.tags:
@@ -34,7 +34,7 @@ def index():
per_page = flask.current_app.config.get('PER_PAGE', 30)
offset = (page - 1) * per_page
- entry_query = Entry.query\
+ entry_query = db.session.query(Entry, Subscription)\
.options(
sqlalchemy.orm.subqueryload(Entry.feed),
sqlalchemy.orm.subqueryload(Entry.reply_context)
@@ -46,12 +46,12 @@ def index():
if 'entry' in flask.request.args:
entry_url = flask.request.args.get('entry')
- entry = Entry.query.filter_by(permalink=entry_url)\
- .order_by(Entry.retrieved.desc())\
- .first()
- if not entry:
+ entry_tup = entry_query.filter(Entry.permalink == entry_url)\
+ .order_by(Entry.retrieved.desc())\
+ .first()
+ if not entry_tup:
flask.abort(404)
- entries = [entry]
+ entry_tups = [entry_tup]
solo = True
else:
if 'tag' in flask.request.args:
@@ -68,9 +68,18 @@ def index():
else:
ws_topic = 'user:{}'.format(flask_login.current_user.id)
- entries = entry_query.order_by(Entry.retrieved.desc(),
- Entry.published.desc())\
- .offset(offset).limit(per_page).all()
+ entry_query = entry_query.order_by(Entry.retrieved.desc(),
+ Entry.published.desc())\
+ .offset(offset).limit(per_page)
+ print('found some entries:', len(entry_query.all()))
+ entry_tups = entry_query.all()
+
+ # stick the subscription into the entry.
+ # FIXME this is hacky
+ entries = []
+ for entry, subsc in entry_tups:
+ entry.subscription = subsc
+ entries.append(entry)
entries = dedupe_copies(entries)
return flask.render_template('feed.jinja2', entries=entries, page=page,
@@ -87,7 +96,6 @@ def install():
@views.route('/subscriptions')
@flask_login.login_required
def subscriptions():
-
subscs = Subscription\
.query\
.filter_by(user_id=flask_login.current_user.id)\