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 test_status_view_with_maintenance(self): maintenance.set_maintenance(message='test') url = '/{}status/'.format(API_BASE) res = self.app.get(url) m = maintenance.get_maintenance() assert_equal(res.status_code, 200) assert_equal(res.json['maintenance']['level'], 1) assert_equal(res.json['maintenance']['start'], m['start']) assert_equal(res.json['maintenance']['end'], m['end']) assert_equal(res.json['maintenance']['message'], 'test')
def set_maintenance(ctx, start=None, end=None): from website.maintenance import set_maintenance, get_maintenance """Set the time period for the maintenance notice to be displayed. If no start or end values are displayed, default to starting now and ending 24 hours from now. If no timezone info is passed along, everything will be converted to UTC. If a given end time results in a start that is after the end, start will be changed to be 24 hours before the end time. Examples: invoke set_maintenance_state invoke set_maintenance_state --start 2016-03-16T15:41:00-04:00 invoke set_maintenance_state --end 2016-03-16T15:41:00-04:00 """ set_maintenance(start, end) state = get_maintenance() print('Maintenance notice up for {} to {}.'.format(state['start'], state['end']))
def status_check(request, format=None, **kwargs): return Response({ 'maintenance': maintenance.get_maintenance(), })
def test_get_maintenance_in_future(self): start = (timezone.now() + timedelta(1)).isoformat() maintenance.set_maintenance(start=start) assert MaintenanceState.objects.exists() state = maintenance.get_maintenance() assert state['start'] == start
def test_get_maintenance(self): start = timezone.now() maintenance.set_maintenance(start=start.isoformat()) state = maintenance.get_maintenance() assert state['start'] == start.isoformat() assert state['end'] == (start + timedelta(1)).isoformat()
def test_status_view_with_maintenance(self): maintenance.set_maintenance() url = '/{}status/'.format(API_BASE) res = self.app.get(url) assert_equal(res.status_code, 200) assert_equal(res.json, {'maintenance': maintenance.get_maintenance()})
def maintenance_alert(): maintenance.set_maintenance('') return maintenance.get_maintenance()