diff --git a/migrations/versions/564f5a5061f_.py b/migrations/versions/564f5a5061f_.py new file mode 100644 index 0000000..ab01906 --- /dev/null +++ b/migrations/versions/564f5a5061f_.py @@ -0,0 +1,74 @@ +"""empty message + +Revision ID: 564f5a5061f +Revises: 5824a5f06dd +Create Date: 2015-04-19 07:49:24.416817 + +""" + +# revision identifiers, used by Alembic. +revision = '564f5a5061f' +down_revision = '5824a5f06dd' + +from alembic import op +import sqlalchemy as sa +from woodwind.models import JsonType + + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + subsc = op.create_table( + 'subscription', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), sa.ForeignKey('user.id'), nullable=False), + sa.Column('feed_id', sa.Integer(), sa.ForeignKey('feed.id'), nullable=False), + sa.Column('name', sa.String(length=256), nullable=True), + sa.Column('tags', JsonType(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + + feed = sa.table( + 'feed', + sa.column('id', sa.Integer()), + sa.column('name', sa.String())) + + u2f = sa.table( + 'users_to_feeds', + sa.column('user_id', sa.Integer()), + sa.column('feed_id', sa.Integer())) + + values = sa.select( + [u2f.c.user_id, u2f.c.feed_id, feed.c.name] + ).select_from( + u2f.join(feed, feed.c.id == u2f.c.feed_id) + ) + + op.execute(subsc.insert().from_select( + ['user_id', 'feed_id', 'name'], values)) + + op.drop_table('users_to_feeds') + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + u2f = op.create_table( + 'users_to_feeds', + sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=True), + sa.Column('feed_id', sa.INTEGER(), autoincrement=False, nullable=True), + sa.ForeignKeyConstraint(['feed_id'], ['feed.id'], name='users_to_feeds_feed_id_fkey'), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], name='users_to_feeds_user_id_fkey') + ) + + subsc = sa.table( + 'subscription', + sa.Column('user_id', sa.Integer()), + sa.Column('feed_id', sa.Integer()), + ) + + op.execute(u2f.insert().from_select( + ['user_id', 'feed_id'], + sa.select([subsc.c.user_id, subsc.c.feed_id]))) + + op.drop_table('subscription') + ### end Alembic commands ### diff --git a/woodwind/models.py b/woodwind/models.py index c34cd3f..dfea7fc 100644 --- a/woodwind/models.py +++ b/woodwind/models.py @@ -71,7 +71,6 @@ class User(db.Model): class Feed(db.Model): id = db.Column(db.Integer, primary_key=True) - users = db.relationship(User, secondary='users_to_feeds', backref='feeds') # the name of this feed name = db.Column(db.String(256)) # url that we subscribed to; periodically check if the feed url @@ -108,12 +107,16 @@ class Feed(db.Model): class Subscription(db.Model): id = db.Column(db.Integer, primary_key=True) - users = db.relationship(User, backref='subscriptions') + user_id = db.Column(db.Integer, db.ForeignKey(User.id)) + feed_id = db.Column(db.Integer, db.ForeignKey(Feed.id)) + # user-editable name of this subscribed feed name = db.Column(db.String(256)) - feed = db.relationship(Feed, backref='subscriptions') tags = db.Column(JsonType) + user = db.relationship(User, backref='subscriptions') + feed = db.relationship(Feed, backref='subscriptions') + class Entry(db.Model): id = db.Column(db.Integer, primary_key=True) diff --git a/woodwind/static/open_in_new_window.png b/woodwind/static/open_in_new_window.png new file mode 100644 index 0000000..3e595aa Binary files /dev/null and b/woodwind/static/open_in_new_window.png differ diff --git a/woodwind/static/open_in_new_window2.png b/woodwind/static/open_in_new_window2.png new file mode 100644 index 0000000..69dface Binary files /dev/null and b/woodwind/static/open_in_new_window2.png differ diff --git a/woodwind/static/style.css b/woodwind/static/style.css index 5fe1835..47a0c87 100644 --- a/woodwind/static/style.css +++ b/woodwind/static/style.css @@ -405,7 +405,7 @@ article { article.reply-context { margin-bottom: 0; background-color: #f3f3f3; } - article.reply-context img { + article.reply-context .content img { max-height: 240px; max-width: 240px; } article div { @@ -421,7 +421,7 @@ article { border-bottom: 1px solid #687d77; margin-bottom: 0.5em; } article header img { - vertical-align: text-middle; + vertical-align: middle; margin: inherit; display: inline; max-width: 1.2em; diff --git a/woodwind/static/style.scss b/woodwind/static/style.scss index 8b35cfb..867d0b5 100644 --- a/woodwind/static/style.scss +++ b/woodwind/static/style.scss @@ -76,8 +76,7 @@ article { &.reply-context { margin-bottom: 0; background-color: #f3f3f3; - - img { + .content img { max-height: 240px; max-width: 240px; } @@ -100,7 +99,7 @@ article { header { img { - vertical-align: text-middle; + vertical-align: middle; margin: inherit; display: inline; max-width: 1.2em; diff --git a/woodwind/tasks.py b/woodwind/tasks.py index 6158de7..f4eff84 100644 --- a/woodwind/tasks.py +++ b/woodwind/tasks.py @@ -234,19 +234,21 @@ def notify_feed_updated(session, feed, entries): entries = sorted(entries, key=lambda e: (e.retrieved, e.published), reverse=True) - for user in feed.users: - with flask_app.test_request_context(): - flask_login.login_user(user, remember=True) - message = json.dumps({ - 'user': user.id, - 'feed': feed.id, - 'entries': [ - render_template('_entry.jinja2', feed=feed, entry=e) - for e in entries - ], - }) - for topic in 'user:{}'.format(user.id), 'feed:{}'.format(feed.id): - redis.publish('woodwind_notify:{}'.format(topic), message) + for s in feed.subscriptions: + for user in s.users: + with flask_app.test_request_context(): + flask_login.login_user(user, remember=True) + message = json.dumps({ + 'user': user.id, + 'feed': feed.id, + 'entries': [ + render_template('_entry.jinja2', feed=feed, entry=e) + for e in entries + ], + }) + for topic in ('user={}'.format(user.id), + 'user={}&feed={}'.format(user.id, feed.id)): + redis.publish('woodwind_notify:{}'.format(topic), message) def is_content_equal(e1, e2): diff --git a/woodwind/templates/_entry.jinja2 b/woodwind/templates/_entry.jinja2 index 04e9ebf..76ba386 100644 --- a/woodwind/templates/_entry.jinja2 +++ b/woodwind/templates/_entry.jinja2 @@ -13,7 +13,7 @@

{{ context.title }}

{% endif %} {% if context.content %} -
+
{{ context.content_cleaned | add_preview }}
{% endif %} @@ -42,7 +42,7 @@

{{ entry.title }}

{% endif %} {% if entry.content %} -
+
{{ entry.content_cleaned | add_preview }}
{% endif %} @@ -50,7 +50,9 @@