fix more 500s
This commit is contained in:
parent
61ddd8a478
commit
bb2bcc68c1
|
@ -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))
|
||||
|
||||
|
||||
|
|
8
model.py
8
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
|
||||
|
|
11
routes.py
11
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()
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@
|
|||
<div class='banner success'>Settings saved successfully</div>
|
||||
{% 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'>
|
||||
<p>Posts that are less than
|
||||
{{interval_input(g.viewer.account, 'policy_keep_younger', scales)}}
|
||||
|
|
Loading…
Reference in New Issue