def read_user_cookie(name): uname = c.user.name if c.user_is_loggedin else "" cookie_name = uname + '_' + name if cookie_name in c.cookies: return c.cookies[cookie_name].value else: return '' def set_user_cookie(name, val, **kwargs): uname = c.user.name if c.user_is_loggedin else "" c.cookies[uname + '_' + name] = Cookie(value=val, **kwargs) valid_click_cookie = fullname_regex(Link, True).match def set_recent_clicks(): c.recent_clicks = [] if not c.user_is_loggedin: return click_cookie = read_user_cookie('recentclicks2') if click_cookie: if valid_click_cookie(click_cookie): names = [ x for x in UniqueIterator(click_cookie.split(',')) if x ] if len(names) > 5: names = names[:5] set_user_cookie('recentclicks2', ','.join(names)) #eventually this will look at the user preference names = names[:5]
def read_user_cookie(name): uname = c.user.name if c.user_is_loggedin else "" cookie_name = uname + '_' + name if cookie_name in c.cookies: return c.cookies[cookie_name].value else: return '' def set_user_cookie(name, val, **kwargs): uname = c.user.name if c.user_is_loggedin else "" c.cookies[uname + '_' + name] = Cookie(value=val, **kwargs) valid_click_cookie = fullname_regex(Link, True).match def set_recent_clicks(): c.recent_clicks = [] if not c.user_is_loggedin: return click_cookie = read_user_cookie('recentclicks2') if click_cookie: if valid_click_cookie(click_cookie): names = [x for x in UniqueIterator(click_cookie.split(',')) if x] if len(names) > 5: names = names[:5] set_user_cookie('recentclicks2', ','.join(names))