我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用django.conf.settings.VERSION。
def auth(request): try: username = request.POST['username'] password = request.POST['password'] except (KeyError): # Be very upset and just throw the fool back return index(request) else: # Attempt authentication user = authenticate(username=username, password=password) if user is not None: login(request, user) return redirect('/login') else: # Login failed return render(request, 'login/index.html', { 'version' : settings.VERSION, 'authfail' : True, })
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 start(request): #g = GeoIP() real_ip = None; geo = None try: real_ip = request.META['HTTP_X_FORWARDED_FOR'] #real_ip = request.META['REMOTE_ADDR'] except: #real_ip = '82.197.131.84' pass #if real_ip != None: # geo = g.city(real_ip) #geo = None if geo == None: geo = {'latitude': 37.4419, 'longitude': 122.1419, 'city': 'Shanghai', 'country_name': 'New Zealand'} return { "version": settings.VERSION, #"GOOGLE_MAPS_API_KEY": settings.GOOGLE_MAPS_API_KEY, "geo": geo, }
def index(request): # Test if the user is authenticated if request.user.is_authenticated: # Redirect to main site return redirect('/list') else: # Serve login page return render(request, 'login/index.html', { 'version' : settings.VERSION, 'authfail' : False, })
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 test_semantic_version(): """ Verify that we have a semantic compatible version. """ semantic_version.Version(settings.VERSION)
def extra_context(request): try: user = request.user except: user = None return {'base_url': settings.BASE_URL[:-1], 'sitename': site_name, 'user': user, 'members_area_nae': 'members', 'broker_base': broker_base, 'dev': settings.DEV_ENV, 'version': settings.VERSION, 'noncustomerlimit': settings.LIMIT_STRATEGIES_FOR_NON_CUSTOMERS }
def get_context_data(self, **kwargs): context = super(Index, self).get_context_data(**kwargs) context['version'] = settings.VERSION context['is_debug'] = settings.DEBUG context['is_prod'] = (settings.BUILD == 'prod') context['is_staging'] = (settings.BUILD == 'staging') context['is_dev'] = (settings.BUILD == 'dev') return context
def fillContext(opts, req): """ Given a set of already filled in options for a context render, fill in some of the additional details. """ nopts = { "notification_unread_count": getNotificationCount(req), "version": settings.VERSION, "request": req } for (k, v) in nopts.items(): if k not in opts: opts[k] = v return opts
def fillContext(opts, req): """ Given a set of already filled in options for a context render, fill in some of the additional details. """ nopts = { "version": settings.VERSION, "request": req } for (k, v) in nopts.items(): if k not in opts: opts[k] = v return opts
def global_template_vars(request): """ Adds variables to all templates. It uses memcached to minimize hitting the db. """ def get_user(): if request.user.is_authenticated(): return ExtendedUser.objects.get( id = request.user.id ) else: return None vars_funcs = { 'SITE_NAME': lambda: Site.objects.get_current().name, 'SITE_DOMAIN': lambda: Site.objects.get_current().domain, 'USERS_NR': lambda: User.objects.count(), 'EVENTS_NR': lambda: Event.objects.count(), 'GROUPS_NR': lambda: Group.objects.count(), } # protocol (computed below) vars_dic = cache.get_many( vars_funcs.keys() ) if not vars_dic: vars_dic = {} # we get the values for key, func in vars_funcs.items(): vars_dic[ key ] = func() # we put the values in the cache cache.set_many( vars_dic ) # we add protocol if request.is_secure(): vars_dic['PROTOCOL'] = "https" else: vars_dic['PROTOCOL'] = "http" vars_dic['VERSION'] = settings.VERSION vars_dic['MEDIA_URL'] = settings.MEDIA_URL # TODO: think on the trick to get the user out of a signed Django-1.4 cookie vars_dic['USER'] = get_user() vars_dic['READ_ONLY'] = settings.READ_ONLY # return return vars_dic
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["admin_name"] = settings.SUPPORT_NAME context["admin_email"] = settings.SUPPORT_EMAIL context["description"] = settings.INSTANCE_DESCRIPTION context["version"] = settings.VERSION return context
def version(request): """ Adds version-related context variables to the context. """ response = {} if django_settings.VERSION: response = { 'version': django_settings.VERSION.get('version', None), } commit = django_settings.VERSION.get('commit') if commit: response['commit'] = commit[:7] return response
def my_settings(request): return { "VERSION": settings.VERSION, "DEBUG": settings.DEBUG, "CERTS_PUBLIC_DOWNLOAD_URL_BASE": settings.CERTS_PUBLIC_DOWNLOAD_URL_BASE, "VPN_HOME_PAGE": settings.VPN_HOME_PAGE, "URL_PREFIX": settings.URL_PREFIX, }
def _get_version(self): """Return hub version or None (if settings.VERSION is not set).""" return getattr(settings, "VERSION", None)
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": "", } )