mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
[mod][fix] cookie expiration ++ pep8 compatibility
This commit is contained in:
parent
a9d075dcc1
commit
f104553af4
@ -57,6 +57,8 @@ babel = Babel(app)
|
|||||||
favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud',
|
favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud',
|
||||||
'twitter', 'stackoverflow', 'github']
|
'twitter', 'stackoverflow', 'github']
|
||||||
|
|
||||||
|
cookie_max_age = 60 * 60 * 24 * 365 * 23 # 23 years
|
||||||
|
|
||||||
|
|
||||||
@babel.localeselector
|
@babel.localeselector
|
||||||
def get_locale():
|
def get_locale():
|
||||||
@ -159,8 +161,10 @@ def index():
|
|||||||
|
|
||||||
# TODO, check if timezone is calculated right
|
# TODO, check if timezone is calculated right
|
||||||
if 'publishedDate' in result:
|
if 'publishedDate' in result:
|
||||||
if result['publishedDate'].replace(tzinfo=None) >= datetime.now() - timedelta(days=1):
|
if result['publishedDate'].replace(tzinfo=None)\
|
||||||
timedifference = datetime.now() - result['publishedDate'].replace(tzinfo=None)
|
>= datetime.now() - timedelta(days=1):
|
||||||
|
timedifference = datetime.now() - result['publishedDate']\
|
||||||
|
.replace(tzinfo=None)
|
||||||
minutes = int((timedifference.seconds / 60) % 60)
|
minutes = int((timedifference.seconds / 60) % 60)
|
||||||
hours = int(timedifference.seconds / 60 / 60)
|
hours = int(timedifference.seconds / 60 / 60)
|
||||||
if hours == 0:
|
if hours == 0:
|
||||||
@ -168,7 +172,8 @@ def index():
|
|||||||
else:
|
else:
|
||||||
result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes) # noqa
|
result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes) # noqa
|
||||||
else:
|
else:
|
||||||
result['pubdate'] = result['publishedDate'].strftime('%a, %d %b %Y %H:%M:%S %z')
|
result['pubdate'] = result['publishedDate']\
|
||||||
|
.strftime('%a, %d %b %Y %H:%M:%S %z')
|
||||||
result['publishedDate'] = format_date(result['publishedDate'])
|
result['publishedDate'] = format_date(result['publishedDate'])
|
||||||
|
|
||||||
if search.request_data.get('format') == 'json':
|
if search.request_data.get('format') == 'json':
|
||||||
@ -256,24 +261,21 @@ def preferences():
|
|||||||
user_blocked_engines = request.cookies.get('blocked_engines', '').split(',') # noqa
|
user_blocked_engines = request.cookies.get('blocked_engines', '').split(',') # noqa
|
||||||
|
|
||||||
if sorted(blocked_engines) != sorted(user_blocked_engines):
|
if sorted(blocked_engines) != sorted(user_blocked_engines):
|
||||||
# cookie max age: 4 weeks
|
|
||||||
resp.set_cookie(
|
resp.set_cookie(
|
||||||
'blocked_engines', ','.join(blocked_engines),
|
'blocked_engines', ','.join(blocked_engines),
|
||||||
max_age=60 * 60 * 24 * 7 * 4
|
max_age=cookie_max_age
|
||||||
)
|
)
|
||||||
|
|
||||||
if locale:
|
if locale:
|
||||||
# cookie max age: 4 weeks
|
|
||||||
resp.set_cookie(
|
resp.set_cookie(
|
||||||
'locale', locale,
|
'locale', locale,
|
||||||
max_age=60 * 60 * 24 * 7 * 4
|
max_age=cookie_max_age
|
||||||
)
|
)
|
||||||
|
|
||||||
if lang:
|
if lang:
|
||||||
# cookie max age: 4 weeks
|
|
||||||
resp.set_cookie(
|
resp.set_cookie(
|
||||||
'language', lang,
|
'language', lang,
|
||||||
max_age=60 * 60 * 24 * 7 * 4
|
max_age=cookie_max_age
|
||||||
)
|
)
|
||||||
|
|
||||||
if selected_categories:
|
if selected_categories:
|
||||||
|
Loading…
Reference in New Issue
Block a user