better formatting of timestamps, add pre to bleach whitelist
This commit is contained in:
parent
67c617e9dc
commit
d62c58cae8
3 changed files with 31 additions and 22 deletions
|
@ -31,8 +31,8 @@ TAG_RE = re.compile(r'</?\w+[^>]*?>')
|
|||
COMMENT_RE = re.compile(r'<!--[^>]*?-->')
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
#logger.setLevel(logging.DEBUG)
|
||||
#logger.addHandler(logging.StreamHandler(sys.stdout))
|
||||
engine = sqlalchemy.create_engine(Config.SQLALCHEMY_DATABASE_URI)
|
||||
Session = sqlalchemy.orm.sessionmaker(bind=engine)
|
||||
redis = StrictRedis()
|
||||
|
@ -249,8 +249,9 @@ def is_content_equal(e1, e2):
|
|||
syntax highlighting (crayon) generates slightly different
|
||||
markup every time it's called.
|
||||
"""
|
||||
content = TAG_RE.sub('', content)
|
||||
content = COMMENT_RE.sub('', content)
|
||||
if content:
|
||||
content = TAG_RE.sub('', content)
|
||||
content = COMMENT_RE.sub('', content)
|
||||
return content
|
||||
|
||||
return (e1.title == e2.title
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import bleach
|
||||
import re
|
||||
|
||||
bleach.ALLOWED_TAGS += ['a', 'img', 'p', 'br', 'marquee', 'blink',
|
||||
'audio', 'video', 'table', 'tbody', 'td', 'tr']
|
||||
bleach.ALLOWED_TAGS += [
|
||||
'a', 'img', 'p', 'br', 'marquee', 'blink', 'audio', 'video', 'table',
|
||||
'tbody', 'td', 'tr', 'pre',
|
||||
]
|
||||
bleach.ALLOWED_ATTRIBUTES.update({
|
||||
'img': ['src', 'alt', 'title'],
|
||||
'audio': ['preload', 'controls', 'src'],
|
||||
|
|
|
@ -380,13 +380,14 @@ def relative_time(dt):
|
|||
now = datetime.datetime.utcnow()
|
||||
diff = now - dt
|
||||
zero = datetime.timedelta(0)
|
||||
years = diff.days // 365
|
||||
hours = diff.seconds // 60 // 60
|
||||
minutes = diff.seconds // 60
|
||||
|
||||
if diff == zero:
|
||||
pretty = 'Right now'
|
||||
if diff > zero:
|
||||
elif diff > zero:
|
||||
years = diff.days // 365
|
||||
hours = diff.seconds // 60 // 60
|
||||
minutes = diff.seconds // 60
|
||||
|
||||
if years > 1:
|
||||
pretty = str(years) + ' years ago'
|
||||
elif diff.days == 1:
|
||||
|
@ -404,22 +405,27 @@ def relative_time(dt):
|
|||
else:
|
||||
pretty = str(diff.seconds) + ' seconds ago'
|
||||
else:
|
||||
if years < -1:
|
||||
pretty = str(-years) + ' years from now'
|
||||
elif diff.days == -1:
|
||||
diff = abs(diff)
|
||||
years = diff.days // 365
|
||||
hours = diff.seconds // 60 // 60
|
||||
minutes = diff.seconds // 60
|
||||
|
||||
if years > 1:
|
||||
pretty = str(years) + ' years from now'
|
||||
elif diff.days == 1:
|
||||
pretty = 'A day from now'
|
||||
elif diff.days < -1:
|
||||
pretty = str(-diff.days) + ' days from now'
|
||||
elif hours == -1:
|
||||
elif diff.days > 1:
|
||||
pretty = str(diff.days) + ' days from now'
|
||||
elif hours == 1:
|
||||
pretty = 'An hour from now'
|
||||
elif hours < -1:
|
||||
pretty = str(-hours) + ' hours from now'
|
||||
elif minutes == -1:
|
||||
elif hours > 1:
|
||||
pretty = str(hours) + ' hours from now'
|
||||
elif minutes == 1:
|
||||
pretty = 'A minute from now'
|
||||
elif minutes < -1:
|
||||
pretty = str(-minutes) + ' minutes from now'
|
||||
elif minutes > 1:
|
||||
pretty = str(minutes) + ' minutes from now'
|
||||
else:
|
||||
pretty = str(-diff.seconds) + ' seconds from now'
|
||||
pretty = str(diff.seconds) + ' seconds from now'
|
||||
|
||||
return '<time datetime="{}">{}</time>'.format(dt.isoformat(), pretty)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue