diff --git a/lib/interval.py b/lib/interval.py index 4b7eea1..4ed5ebd 100644 --- a/lib/interval.py +++ b/lib/interval.py @@ -44,8 +44,8 @@ def decompose_interval(attrname): try: value = int(value) assert value >= 0 - except (ValueError, AssertionError): - raise ValueError("Incorrect time interval") + except (ValueError, AssertionError) as e: + raise ValueError("Incorrect time interval", e) setattr(self, attrname, value * getattr(self, scl_name)) diff --git a/model.py b/model.py index 3947a91..195122c 100644 --- a/model.py +++ b/model.py @@ -34,7 +34,6 @@ class RemoteIDMixin(object): self.id = "twitter:{}".format(id) - @decompose_interval('policy_delete_every') @decompose_interval('policy_keep_younger') class Account(TimestampMixin, RemoteIDMixin): @@ -67,6 +66,13 @@ class Account(TimestampMixin, RemoteIDMixin): value = timedelta(minutes=1) return value + @db.validates('policy_keep_latest') + def validate_empty_string_is_zero(self, key, value): + if type(value) == str and value.strip() == '': + return 0 + return value + + # backref: tokens # backref: twitter_archives # backref: posts diff --git a/routes.py b/routes.py index e43f5f6..b4b8d2f 100644 --- a/routes.py +++ b/routes.py @@ -32,7 +32,9 @@ def touch_viewer(resp): def index(): if g.viewer: return render_template('logged_in.html', scales=lib.interval_scales, - tweet_archive_failed = 'tweet_archive_failed' in request.args) + tweet_archive_failed = 'tweet_archive_failed' in request.args, + settings_error = 'settings_error' in request.args + ) else: return render_template('index.html') @@ -90,8 +92,11 @@ def settings(): 'policy_keep_younger_significand', 'policy_keep_younger_scale', ): - if attr in request.form: - setattr(g.viewer.account, attr, request.form[attr]) + try: + if attr in request.form: + setattr(g.viewer.account, attr, request.form[attr]) + except ValueError: + return redirect(url_for('index', settings_error='')) db.session.commit() diff --git a/templates/logged_in.html b/templates/logged_in.html index 7b6ce95..3ae3879 100644 --- a/templates/logged_in.html +++ b/templates/logged_in.html @@ -37,6 +37,10 @@ {% endif %} +{% if settings_error %} + +{% endif %} +

Posts that are less than {{interval_input(g.viewer.account, 'policy_keep_younger', scales)}}