我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用django.conf.settings.ENVIRONMENT。
def terms_of_service(request): """ Handles the terms of service page """ return render( request, "terms_of_service.html", context={ "has_zendesk_widget": True, "is_public": True, "js_settings_json": json.dumps({ "release_version": settings.VERSION, "environment": settings.ENVIRONMENT, "sentry_dsn": sentry.get_public_dsn(), "user": serialize_maybe_user(request.user), }), "ga_tracking_id": "", } )
def standard_error_page(request, status_code, template_filename): """ Returns an error page with a given template filename and provides necessary context variables """ name = request.user.profile.preferred_name if not request.user.is_anonymous() else "" authenticated = not request.user.is_anonymous() username = get_social_username(request.user) response = render( request, template_filename, context={ "has_zendesk_widget": True, "is_public": True, "js_settings_json": json.dumps({ "release_version": settings.VERSION, "environment": settings.ENVIRONMENT, "sentry_dsn": sentry.get_public_dsn(), "user": serialize_maybe_user(request.user), }), "authenticated": authenticated, "name": name, "username": username, "is_staff": has_role(request.user, [Staff.ROLE_ID, Instructor.ROLE_ID]), "support_email": settings.EMAIL_SUPPORT, "sentry_dsn": sentry.get_public_dsn(), } ) response.status_code = status_code return response
def get_context(self, request, *args, **kwargs): programs = Program.objects.filter(live=True).select_related('programpage').order_by("id") js_settings = { "gaTrackingID": settings.GA_TRACKING_ID, "host": webpack_dev_server_host(request), "environment": settings.ENVIRONMENT, "sentry_dsn": sentry.get_public_dsn(), "release_version": settings.VERSION } username = get_social_username(request.user) context = super(HomePage, self).get_context(request) def get_program_page(program): """Return a None if ProgramPage does not exist, to avoid template errors""" try: return program.programpage except ProgramPage.DoesNotExist: return program_pairs = [(program, get_program_page(program)) for program in programs] context["programs"] = program_pairs context["is_public"] = True context["has_zendesk_widget"] = False context["google_maps_api"] = False context["authenticated"] = not request.user.is_anonymous() context["is_staff"] = has_role(request.user, [Staff.ROLE_ID, Instructor.ROLE_ID]) context["username"] = username context["js_settings_json"] = json.dumps(js_settings) context["title"] = self.title context["ga_tracking_id"] = "" context["coupon_code"] = get_coupon_code(request) return context
def get_program_page_context(programpage, request): """ Get context for the program page""" from cms.serializers import ProgramPageSerializer courses_query = ( programpage.program.course_set.all() ) js_settings = { "gaTrackingID": settings.GA_TRACKING_ID, "host": webpack_dev_server_host(request), "environment": settings.ENVIRONMENT, "sentry_dsn": sentry.get_public_dsn(), "release_version": settings.VERSION, "user": serialize_maybe_user(request.user), "program": ProgramPageSerializer(programpage).data, } username = get_social_username(request.user) context = super(ProgramPage, programpage).get_context(request) context["is_staff"] = has_role(request.user, [Staff.ROLE_ID, Instructor.ROLE_ID]) context["is_public"] = True context["has_zendesk_widget"] = True context["google_maps_api"] = False context["authenticated"] = not request.user.is_anonymous() context["username"] = username context["js_settings_json"] = json.dumps(js_settings) context["title"] = programpage.title context["courses"] = courses_query context["ga_tracking_id"] = programpage.program.ga_tracking_id return context
def notify(self, inserted): """Notify Gitter after task success.""" if settings.ENVIRONMENT == 'Development' or inserted == 0: return args = (settings.ENVIRONMENT, str(self), inserted) msg = "{}: {} added {} CO2 measurements just now" payload = {'message': msg.format(*args)} requests.post(settings.GITTER_URL, data=payload)
def get_context_data(self, *args, **kwargs): context = super(MasterView, self).get_context_data(*args, **kwargs) context['DEBUG'] = settings.TEMPLATE_DEBUG context['STATIC_URL'] = settings.STATIC_URL context['ANALYTICS_ID'] = settings.ANALYTICS_ID context['ENV'] = settings.ENVIRONMENT context['HOST_URL'] = self.request.get_host() context['OAUTH_SETTINGS'] = settings.OAUTH_SETTINGS context['CHANNELS_API_BASE'] = settings.CHANNELS_API_BASE context['API_BASE'] = settings.API_BASE return context
def should_remove_stack(self): """We should add the stack if the test cases is not expected to be an error""" return not settings.ENVIRONMENT == 'local' and not settings.TESTING
def robots_txt_view(request): """ robots.txt - blocks access on non-prod and refers to sitemap.xml @param request: the HTTP request """ if settings.ENVIRONMENT != 'prod': robots_txt = 'User-agent: *\nDisallow: /' else: robots_txt = 'Sitemap: %s' % request.build_absolute_uri(reverse('sitemap_xml')) response = HttpResponse(robots_txt, content_type='text/plain') return make_response_cacheable(response)
def get(self, request, *args, **kwargs): """ Handle GET requests to templates using React """ user = request.user roles = [] if not user.is_anonymous(): roles = [ { 'program': role.program.id, 'role': role.role, 'permissions': [perm for perm, value in available_perm_status(user).items() if value is True] } for role in user.role_set.all() ] js_settings = { "gaTrackingID": settings.GA_TRACKING_ID, "reactGaDebug": settings.REACT_GA_DEBUG, "host": webpack_dev_server_host(request), "edx_base_url": settings.EDXORG_BASE_URL, "roles": roles, "release_version": settings.VERSION, "environment": settings.ENVIRONMENT, "sentry_dsn": sentry.get_public_dsn(), "search_url": reverse('search_api', kwargs={"elastic_url": ""}), "support_email": settings.EMAIL_SUPPORT, "user": serialize_maybe_user(request.user), "es_page_size": settings.ELASTICSEARCH_DEFAULT_PAGE_SIZE, "public_path": public_path(request), "EXAMS_SSO_CLIENT_CODE": settings.EXAMS_SSO_CLIENT_CODE, "EXAMS_SSO_URL": settings.EXAMS_SSO_URL, "FEATURES": { "PROGRAM_LEARNERS": settings.FEATURES.get('PROGRAM_LEARNERS_ENABLED', False), "DISCUSSIONS_POST_UI": settings.FEATURES.get('OPEN_DISCUSSIONS_POST_UI', False), "DISCUSSIONS_CREATE_CHANNEL_UI": settings.FEATURES.get('OPEN_DISCUSSIONS_CREATE_CHANNEL_UI', False) }, "open_discussions_redirect_url": settings.OPEN_DISCUSSIONS_REDIRECT_URL, } return render( request, "dashboard.html", context={ "has_zendesk_widget": True, "is_public": False, "google_maps_api": False, "js_settings_json": json.dumps(js_settings), "ga_tracking_id": "", } )