fix more 500s

This commit is contained in:
codl 2017-08-07 16:26:25 +02:00
parent 61ddd8a478
commit bb2bcc68c1
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
4 changed files with 21 additions and 6 deletions

View File

@ -44,8 +44,8 @@ def decompose_interval(attrname):
try: try:
value = int(value) value = int(value)
assert value >= 0 assert value >= 0
except (ValueError, AssertionError): except (ValueError, AssertionError) as e:
raise ValueError("Incorrect time interval") raise ValueError("Incorrect time interval", e)
setattr(self, attrname, value * getattr(self, scl_name)) setattr(self, attrname, value * getattr(self, scl_name))

View File

@ -34,7 +34,6 @@ class RemoteIDMixin(object):
self.id = "twitter:{}".format(id) self.id = "twitter:{}".format(id)
@decompose_interval('policy_delete_every') @decompose_interval('policy_delete_every')
@decompose_interval('policy_keep_younger') @decompose_interval('policy_keep_younger')
class Account(TimestampMixin, RemoteIDMixin): class Account(TimestampMixin, RemoteIDMixin):
@ -67,6 +66,13 @@ class Account(TimestampMixin, RemoteIDMixin):
value = timedelta(minutes=1) value = timedelta(minutes=1)
return value 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: tokens
# backref: twitter_archives # backref: twitter_archives
# backref: posts # backref: posts

View File

@ -32,7 +32,9 @@ def touch_viewer(resp):
def index(): def index():
if g.viewer: if g.viewer:
return render_template('logged_in.html', scales=lib.interval_scales, 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: else:
return render_template('index.html') return render_template('index.html')
@ -90,8 +92,11 @@ def settings():
'policy_keep_younger_significand', 'policy_keep_younger_significand',
'policy_keep_younger_scale', 'policy_keep_younger_scale',
): ):
try:
if attr in request.form: if attr in request.form:
setattr(g.viewer.account, attr, request.form[attr]) setattr(g.viewer.account, attr, request.form[attr])
except ValueError:
return redirect(url_for('index', settings_error=''))
db.session.commit() db.session.commit()

View File

@ -37,6 +37,10 @@
<div class='banner success'>Settings saved successfully</div> <div class='banner success'>Settings saved successfully</div>
{% endif %} {% endif %}
{% if settings_error %}
<div class='banner error'>Something went wrong trying to save your settings. Please try again later.</div>
{% endif %}
<form action='{{url_for("settings")}}' method='post' enctype='multipart/form-data'> <form action='{{url_for("settings")}}' method='post' enctype='multipart/form-data'>
<p>Posts that are less than <p>Posts that are less than
{{interval_input(g.viewer.account, 'policy_keep_younger', scales)}} {{interval_input(g.viewer.account, 'policy_keep_younger', scales)}}