1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 19:40:00 +00:00

comments can be added+removed. gravatar for user avatar

This commit is contained in:
nyaadev 2017-05-22 18:35:48 +02:00
parent 9bd71af1b2
commit fee55c1792
4 changed files with 42 additions and 4 deletions

View file

@ -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')

View file

@ -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:

View file

@ -626,6 +626,7 @@ def submit_comment(torrent_id):
return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id))
@app.route('/view/<int:torrent_id>/delete_comment/<int:comment_id>')
def delete_comment(torrent_id, comment_id):
if flask.g.user is not None and flask.g.user.is_admin:
@ -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'])

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB