diff --git a/assets/styles.css b/assets/styles.css index c75c90b..1b9e102 100644 --- a/assets/styles.css +++ b/assets/styles.css @@ -267,6 +267,7 @@ section > pre.error-log { .radiostrip { display: inline-flex; flex-direction: row; + flex-wrap: wrap; } .radiostrip input[type=radio] { @@ -280,8 +281,6 @@ section > pre.error-log { cursor: pointer; user-select: none; background-color: #ededed; - will-change: transform; - transition: transform 50ms; } .radiostrip label:not(:last-of-type) { @@ -293,7 +292,6 @@ section > pre.error-log { } .radiostrip input[type=radio]:checked + label { - transform: scale(.95); background: #37d; color: white; } diff --git a/migrations/versions/583cdac8eba1_add_three_way_media_policy.py b/migrations/versions/583cdac8eba1_add_three_way_media_policy.py new file mode 100644 index 0000000..a93b4a8 --- /dev/null +++ b/migrations/versions/583cdac8eba1_add_three_way_media_policy.py @@ -0,0 +1,59 @@ +"""add three-way media policy + +Revision ID: 583cdac8eba1 +Revises: 7e255d4ea34d +Create Date: 2017-12-28 00:46:56.023649 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '583cdac8eba1' +down_revision = '7e255d4ea34d' +branch_labels = None +depends_on = None + +transitional = sa.table('accounts', + sa.column('policy_keep_media'), + sa.column('old_policy_keep_media')) + + + +def upgrade(): + ThreeWayPolicyEnum = sa.Enum('keeponly', 'deleteonly', 'none', + name='enum_3way_policy') + op.execute(""" + CREATE TYPE enum_3way_policy AS ENUM ('keeponly', 'deleteonly', 'none') + """) + op.alter_column('accounts', 'policy_keep_media', + new_column_name='old_policy_keep_media') + op.add_column( + 'accounts', + sa.Column('policy_keep_media', ThreeWayPolicyEnum, + nullable=False, server_default='none')) + + op.execute(transitional.update() + .where(transitional.c.old_policy_keep_media) + .values(policy_keep_media=op.inline_literal('keeponly'))) + + op.drop_column('accounts', 'old_policy_keep_media') + + +def downgrade(): + op.alter_column('accounts', 'policy_keep_media', + new_column_name='old_policy_keep_media') + op.add_column( + 'accounts', + sa.Column('policy_keep_media', sa.Boolean(), + nullable=False, server_default='f')) + + op.execute(transitional.update() + .where(transitional.c.old_policy_keep_media == op.inline_literal('keeponly')) + .values(policy_keep_media=op.inline_literal('t'))) + + op.drop_column('accounts', 'old_policy_keep_media') + op.execute(""" + DROP TYPE enum_3way_policy + """) diff --git a/model.py b/model.py index 003dc23..a155767 100644 --- a/model.py +++ b/model.py @@ -67,6 +67,10 @@ class RemoteIDMixin(object): self.id = "mastodon:{}@{}".format(id_, self.mastodon_instance) +ThreeWayPolicyEnum = db.Enum('keeponly', 'deleteonly', 'none', + name='enum_3way_policy') + + @decompose_interval('policy_delete_every') @decompose_interval('policy_keep_younger') class Account(TimestampMixin, RemoteIDMixin): @@ -79,7 +83,7 @@ class Account(TimestampMixin, RemoteIDMixin): nullable=False) policy_keep_favourites = db.Column(db.Boolean, server_default='TRUE', nullable=False) - policy_keep_media = db.Column(db.Boolean, server_default='FALSE', + policy_keep_media = db.Column(ThreeWayPolicyEnum, server_default='none', nullable=False) policy_delete_every = db.Column(db.Interval, server_default='30 minutes', nullable=False) @@ -174,9 +178,11 @@ class Account(TimestampMixin, RemoteIDMixin): db.func.now() - self.policy_keep_younger) .except_(latest_n_posts)) if(self.policy_keep_favourites): - query = query.filter(db.or_(Post.favourite == False, Post.is_reblog)) - if(self.policy_keep_media): - query = query.filter(db.or_(Post.has_media == False, Post.is_reblog)) + query = query.filter(db.or_(~Post.favourite, Post.is_reblog)) + if(self.policy_keep_media != 'none'): + query = query.filter(db.or_( + Post.has_media == (self.policy_keep_media == 'deleteonly'), + Post.is_reblog)) if(self.policy_keep_direct): query = query.filter(~Post.direct) return query.count() diff --git a/tasks.py b/tasks.py index 42fd3a3..d2f6ebb 100644 --- a/tasks.py +++ b/tasks.py @@ -170,26 +170,30 @@ def delete_from_account(account_id): to_delete = None + def is_eligible(post): + return ( + post.is_reblog or + ( + ( + not account.policy_keep_favourites or not post.favourite + ) and ( + account.policy_keep_media == 'none' or + (account.policy_keep_media == 'keeponly' and not post.has_media) or + (account.policy_keep_media == 'deleteonly' and post.has_media) + ) + ) + ) + action = noop if account.service == 'twitter': action = libforget.twitter.delete posts = refresh_posts(posts) - if posts: - eligible = list(( # nosec - post for post in posts if - (not account.policy_keep_favourites or not post.favourite or post.is_reblog) - and (not account.policy_keep_media or not post.has_media or post.is_reblog) - )) - if eligible: - to_delete = random.choice(eligible) + to_delete = next(filter(is_eligible, posts), None) elif account.service == 'mastodon': action = libforget.mastodon.delete for post in posts: refreshed = refresh_posts((post,)) - if refreshed and \ - (not account.policy_keep_favourites or not post.favourite or post.is_reblog) \ - and (not account.policy_keep_media or not post.has_media or post.is_reblog)\ - and (not account.policy_keep_direct or not post.direct): + if refreshed and is_eligible(refreshed[0]): to_delete = refreshed[0] break diff --git a/templates/logged_in.html b/templates/logged_in.html index 88a7a77..841a61e 100644 --- a/templates/logged_in.html +++ b/templates/logged_in.html @@ -78,12 +78,14 @@

-

Keep posts that have media attached +

Keep posts - - - - + + + + + +

{% if g.viewer.account.service == 'mastodon' %}