def get_globals(): """Context variables that are available for every template rendered by OSFWebRenderer. """ user = _get_current_user() user_institutions = [{'id': inst._id, 'name': inst.name, 'logo_path': inst.logo_path} for inst in user.affiliated_institutions] if user else [] all_institutions = [{'id': inst._id, 'name': inst.name, 'logo_path': inst.logo_path} for inst in Institution.find().sort('name')] if request.host_url != settings.DOMAIN: try: inst_id = (Institution.find_one(Q('domains', 'eq', request.host.lower())))._id request_login_url = '{}institutions/{}'.format(settings.DOMAIN, inst_id) except NoResultsFound: request_login_url = request.url.replace(request.host_url, settings.DOMAIN) else: request_login_url = request.url return { 'private_link_anonymous': is_private_link_anonymous_view(), 'user_name': user.username if user else '', 'user_full_name': user.fullname if user else '', 'user_id': user._primary_key if user else '', 'user_locale': user.locale if user and user.locale else '', 'user_timezone': user.timezone if user and user.timezone else '', 'user_url': user.url if user else '', 'user_gravatar': profile_views.current_user_gravatar(size=25)['gravatar_url'] if user else '', 'user_email_verifications': user.unconfirmed_email_info if user else [], 'user_api_url': user.api_url if user else '', 'user_entry_point': metrics.get_entry_point(user) if user else '', 'user_institutions': user_institutions if user else None, 'all_institutions': all_institutions, 'display_name': get_display_name(user.fullname) if user else '', 'use_cdn': settings.USE_CDN_FOR_CLIENT_LIBS, 'piwik_host': settings.PIWIK_HOST, 'piwik_site_id': settings.PIWIK_SITE_ID, 'sentry_dsn_js': settings.SENTRY_DSN_JS if sentry.enabled else None, 'dev_mode': settings.DEV_MODE, 'allow_login': settings.ALLOW_LOGIN, 'cookie_name': settings.COOKIE_NAME, 'status': status.pop_status_messages(), 'domain': settings.DOMAIN, 'api_domain': settings.API_DOMAIN, 'disk_saving_mode': settings.DISK_SAVING_MODE, 'language': language, 'noteworthy_links_node': settings.NEW_AND_NOTEWORTHY_LINKS_NODE, 'popular_links_node': settings.POPULAR_LINKS_NODE, 'web_url_for': util.web_url_for, 'api_url_for': util.api_url_for, 'api_v2_url': util.api_v2_url, # URL function for templates 'api_v2_base': util.api_v2_url(''), # Base url used by JS api helper 'sanitize': sanitize, 'sjson': lambda s: sanitize.safe_json(s), 'webpack_asset': paths.webpack_asset, 'waterbutler_url': settings.WATERBUTLER_URL, 'login_url': cas.get_login_url(request_login_url), 'reauth_url': util.web_url_for('auth_logout', redirect_url=request.url, reauth=True), 'profile_url': cas.get_profile_url(), 'enable_institutions': settings.ENABLE_INSTITUTIONS, 'keen_project_id': settings.KEEN_PROJECT_ID, 'keen_write_key': settings.KEEN_WRITE_KEY, 'maintenance': maintenance.get_maintenance(), }
def get_globals(): """Context variables that are available for every template rendered by OSFWebRenderer. """ user = _get_current_user() if request.host_url != settings.DOMAIN: try: inst_id = (Institution.find_one(Q('domains', 'eq', request.host.lower())))._id login_url = '{}institutions/{}'.format(settings.DOMAIN, inst_id) except NoResultsFound: login_url = request.url.replace(request.host_url, settings.DOMAIN) else: login_url = request.url return { 'private_link_anonymous': is_private_link_anonymous_view(), 'user_name': user.username if user else '', 'user_full_name': user.fullname if user else '', 'user_id': user._primary_key if user else '', 'user_locale': user.locale if user and user.locale else '', 'user_timezone': user.timezone if user and user.timezone else '', 'user_url': user.url if user else '', 'user_gravatar': profile_views.current_user_gravatar(size=25)['gravatar_url'] if user else '', 'user_api_url': user.api_url if user else '', 'display_name': get_display_name(user.fullname) if user else '', 'use_cdn': settings.USE_CDN_FOR_CLIENT_LIBS, 'piwik_host': settings.PIWIK_HOST, 'piwik_site_id': settings.PIWIK_SITE_ID, 'sentry_dsn_js': settings.SENTRY_DSN_JS if sentry.enabled else None, 'dev_mode': settings.DEV_MODE, 'allow_login': settings.ALLOW_LOGIN, 'cookie_name': settings.COOKIE_NAME, 'status': status.pop_status_messages(), 'domain': settings.DOMAIN, 'api_domain': settings.API_DOMAIN, 'disk_saving_mode': settings.DISK_SAVING_MODE, 'language': language, 'noteworthy_links_node': settings.NEW_AND_NOTEWORTHY_LINKS_NODE, 'popular_links_node': settings.POPULAR_LINKS_NODE, 'web_url_for': util.web_url_for, 'api_url_for': util.api_url_for, 'api_v2_url': util.api_v2_url, # URL function for templates 'api_v2_base': util.api_v2_url(''), # Base url used by JS api helper 'sanitize': sanitize, 'js_str': lambda x: x.replace("'", r"\'").replace('"', r'\"'), 'sjson': lambda s: sanitize.safe_json(s), 'webpack_asset': paths.webpack_asset, 'waterbutler_url': settings.WATERBUTLER_URL, 'login_url': cas.get_login_url(login_url, auto=True), 'reauth_url': util.web_url_for('auth_logout', redirect_url=request.url, reauth=True), 'profile_url': cas.get_profile_url(), 'enable_institutions': settings.ENABLE_INSTITUTIONS, 'keen_project_id': settings.KEEN_PROJECT_ID, 'keen_write_key': settings.KEEN_WRITE_KEY, }
def get_globals(): """Context variables that are available for every template rendered by OSFWebRenderer. """ user = _get_current_user() return { 'private_link_anonymous': is_private_link_anonymous_view(), 'user_name': user.username if user else '', 'user_full_name': user.fullname if user else '', 'user_id': user._primary_key if user else '', 'user_url': user.url if user else '', 'user_gravatar': profile_views.current_user_gravatar(size=25)['gravatar_url'] if user else '', 'user_api_url': user.api_url if user else '', 'display_name': get_display_name(user.fullname) if user else '', 'use_cdn': settings.USE_CDN_FOR_CLIENT_LIBS, 'piwik_host': settings.PIWIK_HOST, 'piwik_site_id': settings.PIWIK_SITE_ID, 'sentry_dsn_js': settings.SENTRY_DSN_JS if sentry.enabled else None, 'dev_mode': settings.DEV_MODE, 'allow_login': settings.ALLOW_LOGIN, 'cookie_name': settings.COOKIE_NAME, 'status': status.pop_status_messages(), 'domain': settings.DOMAIN, 'api_domain': settings.API_DOMAIN, 'disk_saving_mode': settings.DISK_SAVING_MODE, 'language': language, 'web_url_for': util.web_url_for, 'api_url_for': util.api_url_for, 'api_v2_url': util.api_v2_url, # URL function for templates 'api_v2_base': util.api_v2_url(''), # Base url used by JS api helper 'sanitize': sanitize, 'js_str': lambda x: x.replace("'", r"\'").replace('"', r'\"'), 'sjson': lambda s: sanitize.safe_json(s), 'webpack_asset': paths.webpack_asset, 'waterbutler_url': settings.WATERBUTLER_URL, 'login_url': cas.get_login_url(request.url, auto=True), 'reauth_url': util.web_url_for('auth_logout', redirect_url=request.url, reauth=True), 'profile_url': cas.get_profile_url(), 'enable_institutions': settings.ENABLE_INSTITUTIONS, 'keen_project_id': settings.KEEN_PROJECT_ID, 'keen_write_key': settings.KEEN_WRITE_KEY, }
def get_globals(): """Context variables that are available for every template rendered by OSFWebRenderer. """ user = _get_current_user() return { 'user_name': user.username if user else '', 'user_full_name': user.fullname if user else '', 'user_id': user._primary_key if user else '', 'user_url': user.url if user else '', 'user_gravatar': profile_views.current_user_gravatar(size=25)['gravatar_url'] if user else '', 'user_api_url': user.api_url if user else '', 'display_name': get_display_name(user.fullname) if user else '', 'use_cdn': settings.USE_CDN_FOR_CLIENT_LIBS, 'piwik_host': settings.PIWIK_HOST, 'piwik_site_id': settings.PIWIK_SITE_ID, 'sentry_dsn_js': settings.SENTRY_DSN_JS if sentry.enabled else None, 'dev_mode': settings.DEV_MODE, 'allow_login': settings.ALLOW_LOGIN, 'cookie_name': settings.COOKIE_NAME, 'status': status.pop_status_messages(), 'domain': settings.DOMAIN, 'api_domain': settings.API_DOMAIN, 'disk_saving_mode': settings.DISK_SAVING_MODE, 'language': language, 'web_url_for': util.web_url_for, 'api_url_for': util.api_url_for, 'api_v2_url': util.api_v2_url, # URL function for templates 'api_v2_base': util.api_v2_url(''), # Base url used by JS api helper 'sanitize': sanitize, 'js_str': lambda x: x.replace("'", r"\'").replace('"', r'\"'), 'sjson': lambda s: sanitize.safe_json(s), 'webpack_asset': paths.webpack_asset, 'waterbutler_url': settings.WATERBUTLER_URL, 'login_url': cas.get_login_url(request.url, auto=True), 'reauth_url': util.web_url_for('auth_logout', redirect_url=request.url, reauth=True), 'profile_url': cas.get_profile_url(), }
def get_globals(): """Context variables that are available for every template rendered by OSFWebRenderer. """ user = _get_current_user() return { "user_name": user.username if user else "", "user_full_name": user.fullname if user else "", "user_id": user._primary_key if user else "", "user_url": user.url if user else "", "user_gravatar": profile_views.current_user_gravatar(size=25)["gravatar_url"] if user else "", "user_api_url": user.api_url if user else "", "display_name": get_display_name(user.fullname) if user else "", "use_cdn": settings.USE_CDN_FOR_CLIENT_LIBS, "piwik_host": settings.PIWIK_HOST, "piwik_site_id": settings.PIWIK_SITE_ID, "sentry_dsn_js": settings.SENTRY_DSN_JS if sentry.enabled else None, "dev_mode": settings.DEV_MODE, "allow_login": settings.ALLOW_LOGIN, "cookie_name": settings.COOKIE_NAME, "status": status.pop_status_messages(), "domain": settings.DOMAIN, "disk_saving_mode": settings.DISK_SAVING_MODE, "language": language, "web_url_for": util.web_url_for, "api_url_for": util.api_url_for, "api_v2_url": util.api_v2_url, # URL function for templates "api_v2_base": util.api_v2_url(""), # Base url used by JS api helper "sanitize": sanitize, "js_str": lambda x: x.replace("'", r"\'").replace('"', r"\""), "sjson": lambda s: sanitize.safe_json(s), "webpack_asset": paths.webpack_asset, "waterbutler_url": settings.WATERBUTLER_URL, "login_url": cas.get_login_url(request.url, auto=True), "access_token": session.data.get("auth_user_access_token") or "", "auth_url": cas.get_login_url(request.url), "profile_url": cas.get_profile_url(), }
def test_safe_json(self): """Add escaping of forward slashes, but only where string literal contains closing markup""" assert_equal( sanitize.safe_json( "I'm a string with / containing </closingtags>"), '"I\'m a string with / containing <\\/closingtags>"')
def test_safe_json(self): """Add escaping of forward slashes, but only where string literal contains closing markup""" assert_equal( sanitize.safe_json("I'm a string with / containing </closingtags>"), '"I\'m a string with / containing <\\/closingtags>"' )