diff --git a/nyaa/forms.py b/nyaa/forms.py index 1fec2ee..f6e35a8 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -129,7 +129,7 @@ class DisabledSelectField(SelectField): class CommentForm(FlaskForm): comment = TextAreaField('Make a comment', [ Length(max=255, message='Comment must be at most %(max)d characters long.'), - Required() + DataRequired() ]) is_anonymous = BooleanField('Anonymous') diff --git a/nyaa/models.py b/nyaa/models.py index a048edd..2f6d730 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -392,6 +392,15 @@ class User(db.Model): ] return all(checks) + def gravatar_url(self): + # from http://en.gravatar.com/site/implement/images/python/ + size = 40 + # construct the url + gravatar_url = 'https://www.gravatar.com/avatar/' + \ + hashlib.md5(self.email.encode('utf-8').lower()).hexdigest() + '?' + gravatar_url += urllib.parse.urlencode({'d': config.DEFAULT_AVATAR_URL, 's': str(size)}) + return gravatar_url + @property def ip_string(self): if self.last_login_ip: diff --git a/nyaa/routes.py b/nyaa/routes.py index 82aa062..4df27a6 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -615,7 +615,7 @@ def submit_comment(torrent_id): current_user_id = None else: current_user_id = flask.g.user.id - + comment = models.Comment( torrent=torrent_id, user_id=current_user_id, @@ -626,6 +626,7 @@ def submit_comment(torrent_id): return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id)) + @app.route('/view//delete_comment/') def delete_comment(torrent_id, comment_id): if flask.g.user is not None and flask.g.user.is_admin: @@ -633,8 +634,8 @@ def delete_comment(torrent_id, comment_id): db.session.commit() else: flask.abort(403) - - return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id)) + + return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id)) @app.route('/view//edit', methods=['GET', 'POST']) @@ -792,6 +793,34 @@ def _create_user_class_choices(user): return default, choices +# Modified from: http://flask.pocoo.org/snippets/33/ +@app.template_filter() +def timesince(dt, default='just now'): + """ + Returns string representing "time since" e.g. + 3 minutes ago, 5 hours ago etc. + Date and time (UTC) are returned if older than 1 day. + """ + + now = datetime.utcnow() + diff = now - dt + + periods = ( + (diff.days, 'day', 'days'), + (diff.seconds / 3600, 'hour', 'hours'), + (diff.seconds / 60, 'minute', 'minutes'), + (diff.seconds, 'second', 'seconds'), + ) + + if diff.days >= 1: + return dt.strftime('%Y-%m-%d %H:%M UTC') + else: + for period, singular, plural in periods: + + if period >= 1: + return '%d %s ago' % (period, singular if period == 1 else plural) + + return default # #################################### STATIC PAGES #################################### @app.route('/rules', methods=['GET']) diff --git a/nyaa/static/img/avatar/default.png b/nyaa/static/img/avatar/default.png new file mode 100644 index 0000000..7cde0a6 Binary files /dev/null and b/nyaa/static/img/avatar/default.png differ