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):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.subscription = None
|
||||
self._syndicated_copies = []
|
||||
|
||||
def get_property(self, key, default=None):
|
||||
|
|
|
@ -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)):
|
||||
|
|
|
@ -31,10 +31,10 @@
|
|||
{% if entry.author_name %}
|
||||
{{ entry.author_name }} -
|
||||
{% endif %}
|
||||
{% if entry.feed %}
|
||||
<a href="{{ entry.feed.origin }}">{{ entry.feed.name }}</a>
|
||||
{% if entry.subscription %}
|
||||
<a href="{{ entry.subscription.feed.origin }}">{{ entry.subscription.name }}</a>
|
||||
<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>
|
||||
{% endif %}
|
||||
</header>
|
||||
|
|
|
@ -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
|
||||
"""
|
||||
|
|
|
@ -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)\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue