set entry.subscription before rendering
This commit is contained in:
parent
793e714dcd
commit
c9e06a50fd
5 changed files with 37 additions and 21 deletions
|
@ -142,6 +142,8 @@ class Entry(db.Model):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.subscription = None
|
||||||
self._syndicated_copies = []
|
self._syndicated_copies = []
|
||||||
|
|
||||||
def get_property(self, key, default=None):
|
def get_property(self, key, default=None):
|
||||||
|
|
|
@ -237,13 +237,16 @@ def notify_feed_updated(session, feed, entries):
|
||||||
for s in feed.subscriptions:
|
for s in feed.subscriptions:
|
||||||
with flask_app.test_request_context():
|
with flask_app.test_request_context():
|
||||||
flask_login.login_user(s.user, remember=True)
|
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({
|
message = json.dumps({
|
||||||
'user': s.user.id,
|
'user': s.user.id,
|
||||||
'feed': feed.id,
|
'feed': feed.id,
|
||||||
'entries': [
|
'subscription': s.id,
|
||||||
render_template('_entry.jinja2', feed=feed, entry=e)
|
'entries': rendered,
|
||||||
for e in entries
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
for topic in ('user:{}'.format(s.user.id),
|
for topic in ('user:{}'.format(s.user.id),
|
||||||
'subsc:{}'.format(s.id)):
|
'subsc:{}'.format(s.id)):
|
||||||
|
|
|
@ -31,10 +31,10 @@
|
||||||
{% if entry.author_name %}
|
{% if entry.author_name %}
|
||||||
{{ entry.author_name }} -
|
{{ entry.author_name }} -
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if entry.feed %}
|
{% if entry.subscription %}
|
||||||
<a href="{{ entry.feed.origin }}">{{ entry.feed.name }}</a>
|
<a href="{{ entry.subscription.feed.origin }}">{{ entry.subscription.name }}</a>
|
||||||
<span style="font-size: 0.8em; float: right;">
|
<span style="font-size: 0.8em; float: right;">
|
||||||
<a href="{{ url_for('.index', feed=entry.feed.get_feed_code()) }}">more from this feed</a>
|
<a href="{{ url_for('.index', subscription=entry.subscription.id) }}">more from this feed</a>
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</header>
|
</header>
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import bleach
|
import bleach
|
||||||
import re
|
import re
|
||||||
|
|
||||||
bleach.ALLOWED_TAGS += ['a', 'img', 'p', 'br', 'marquee', 'blink',
|
bleach.ALLOWED_TAGS += [
|
||||||
'audio', 'video', 'table', 'tbody', 'td', 'tr',
|
'a', 'img', 'p', 'br', 'marquee', 'blink',
|
||||||
'div', 'span', 'pre',
|
'audio', 'video', 'table', 'tbody', 'td', 'tr', 'div', 'span',
|
||||||
|
'pre',
|
||||||
]
|
]
|
||||||
|
|
||||||
bleach.ALLOWED_ATTRIBUTES.update({
|
bleach.ALLOWED_ATTRIBUTES.update({
|
||||||
'img': ['src', 'alt', 'title'],
|
'img': ['src', 'alt', 'title'],
|
||||||
'audio': ['preload', 'controls', 'src'],
|
'audio': ['preload', 'controls', 'src'],
|
||||||
|
@ -12,6 +14,7 @@ bleach.ALLOWED_ATTRIBUTES.update({
|
||||||
'td': ['colspan'],
|
'td': ['colspan'],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def clean(text):
|
def clean(text):
|
||||||
"""Strip script tags and other possibly dangerous content
|
"""Strip script tags and other possibly dangerous content
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -25,7 +25,7 @@ def index():
|
||||||
ws_topic = None
|
ws_topic = None
|
||||||
solo = False
|
solo = False
|
||||||
all_tags = set()
|
all_tags = set()
|
||||||
|
|
||||||
if flask_login.current_user.is_authenticated():
|
if flask_login.current_user.is_authenticated():
|
||||||
for subsc in flask_login.current_user.subscriptions:
|
for subsc in flask_login.current_user.subscriptions:
|
||||||
if subsc.tags:
|
if subsc.tags:
|
||||||
|
@ -34,7 +34,7 @@ def index():
|
||||||
per_page = flask.current_app.config.get('PER_PAGE', 30)
|
per_page = flask.current_app.config.get('PER_PAGE', 30)
|
||||||
offset = (page - 1) * per_page
|
offset = (page - 1) * per_page
|
||||||
|
|
||||||
entry_query = Entry.query\
|
entry_query = db.session.query(Entry, Subscription)\
|
||||||
.options(
|
.options(
|
||||||
sqlalchemy.orm.subqueryload(Entry.feed),
|
sqlalchemy.orm.subqueryload(Entry.feed),
|
||||||
sqlalchemy.orm.subqueryload(Entry.reply_context)
|
sqlalchemy.orm.subqueryload(Entry.reply_context)
|
||||||
|
@ -46,12 +46,12 @@ def index():
|
||||||
|
|
||||||
if 'entry' in flask.request.args:
|
if 'entry' in flask.request.args:
|
||||||
entry_url = flask.request.args.get('entry')
|
entry_url = flask.request.args.get('entry')
|
||||||
entry = Entry.query.filter_by(permalink=entry_url)\
|
entry_tup = entry_query.filter(Entry.permalink == entry_url)\
|
||||||
.order_by(Entry.retrieved.desc())\
|
.order_by(Entry.retrieved.desc())\
|
||||||
.first()
|
.first()
|
||||||
if not entry:
|
if not entry_tup:
|
||||||
flask.abort(404)
|
flask.abort(404)
|
||||||
entries = [entry]
|
entry_tups = [entry_tup]
|
||||||
solo = True
|
solo = True
|
||||||
else:
|
else:
|
||||||
if 'tag' in flask.request.args:
|
if 'tag' in flask.request.args:
|
||||||
|
@ -68,9 +68,18 @@ def index():
|
||||||
else:
|
else:
|
||||||
ws_topic = 'user:{}'.format(flask_login.current_user.id)
|
ws_topic = 'user:{}'.format(flask_login.current_user.id)
|
||||||
|
|
||||||
entries = entry_query.order_by(Entry.retrieved.desc(),
|
entry_query = entry_query.order_by(Entry.retrieved.desc(),
|
||||||
Entry.published.desc())\
|
Entry.published.desc())\
|
||||||
.offset(offset).limit(per_page).all()
|
.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)
|
entries = dedupe_copies(entries)
|
||||||
return flask.render_template('feed.jinja2', entries=entries, page=page,
|
return flask.render_template('feed.jinja2', entries=entries, page=page,
|
||||||
|
@ -87,7 +96,6 @@ def install():
|
||||||
@views.route('/subscriptions')
|
@views.route('/subscriptions')
|
||||||
@flask_login.login_required
|
@flask_login.login_required
|
||||||
def subscriptions():
|
def subscriptions():
|
||||||
|
|
||||||
subscs = Subscription\
|
subscs = Subscription\
|
||||||
.query\
|
.query\
|
||||||
.filter_by(user_id=flask_login.current_user.id)\
|
.filter_by(user_id=flask_login.current_user.id)\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue