Python django.conf.settings.ENVIRONMENT Examples
The following are 16
code examples of django.conf.settings.ENVIRONMENT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example #1
Source File: places.py From pasportaservo with GNU Affero General Public License v3.0 | 6 votes |
def send_email(self, user, place): config = SiteConfiguration.get_solo() email_template_subject = get_template('email/new_authorization_subject.txt') email_template_text = get_template('email/new_authorization.txt') email_template_html = get_template('email/new_authorization.html') # TODO : Unsubscribe link in the email email_context = { 'site_name': config.site_name, 'ENV': settings.ENVIRONMENT, 'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL, 'user': user, 'place': place, } # TODO : send mail only if the user chose to receive this type send_mail( ''.join(email_template_subject.render(email_context).splitlines()), email_template_text.render(email_context), settings.DEFAULT_FROM_EMAIL, recipient_list=[user.email], html_message=email_template_html.render(email_context), fail_silently=False, )
Example #2
Source File: forms.py From pasportaservo with GNU Affero General Public License v3.0 | 6 votes |
def send_mail(self, subject_template_name, email_template_name, context, *args, html_email_template_name=None, **kwargs): user_is_active = context['user'].is_active html_email_template_name = html_email_template_name[user_is_active] email_template_name = email_template_name[user_is_active] if not user_is_active: case_id = str(uuid4()).upper() auth_log.warning( (self.admin_inactive_user_notification + ", but the account is deactivated [{cid}].") .format(u=context['user'], cid=case_id) ) context['restore_request_id'] = case_id args = [subject_template_name, email_template_name, context, *args] kwargs.update(html_email_template_name=html_email_template_name) context.update({'ENV': settings.ENVIRONMENT, 'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL}) super().send_mail(*args, **kwargs)
Example #3
Source File: views.py From micromasters with BSD 3-Clause "New" or "Revised" License | 6 votes |
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": settings.SENTRY_DSN, "user": serialize_maybe_user(request.user), }), "ga_tracking_id": "", } )
Example #4
Source File: models.py From micromasters with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_context(self, request, *args, **kwargs): js_settings = { "gaTrackingID": settings.GA_TRACKING_ID, "host": webpack_dev_server_host(request), "environment": settings.ENVIRONMENT, "sentry_dsn": settings.SENTRY_DSN, "release_version": settings.VERSION } username = get_social_username(request.user) context = super().get_context(request) context["is_public"] = True context["has_zendesk_widget"] = True 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"] = "" return context
Example #5
Source File: views.py From pasportaservo with GNU Affero General Public License v3.0 | 5 votes |
def post(self, request, *args, **kwargs): config = SiteConfiguration.get_solo() email_to_verify = value_without_invalid_marker(request.user.email) url, token = create_unique_url({ 'action': 'email_update', 'v': True, 'pk': request.user.pk, 'email': email_to_verify, }) context = { 'site_name': config.site_name, 'ENV': settings.ENVIRONMENT, 'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL, 'url': url, 'url_first': url[:url.rindex('/')+1], 'url_second': token, 'user': request.user, } email_template_subject = get_template('email/system-email_verify_subject.txt') email_template_text = get_template('email/system-email_verify.txt') email_template_html = get_template('email/system-email_verify.html') send_mail( ''.join(email_template_subject.render(context).splitlines()), # no newlines allowed in subject. email_template_text.render(context), settings.DEFAULT_FROM_EMAIL, recipient_list=[email_to_verify], html_message=email_template_html.render(context), fail_silently=False) if request.is_ajax(): return JsonResponse({'success': 'verification-requested'}) else: return TemplateResponse(request, self.template_name)
Example #6
Source File: forms.py From pasportaservo with GNU Affero General Public License v3.0 | 5 votes |
def save(self): """ Saves nothing but sends a warning email to old email address, and sends a confirmation link to the new email address. """ config = SiteConfiguration.get_solo() old_email = self.previous_email new_email = self.cleaned_data['email'] if old_email == new_email: return self.instance url, token = create_unique_url({ 'action': 'email_update', 'v': False, 'pk': self.instance.pk, 'email': new_email, }) context = { 'site_name': config.site_name, 'ENV': settings.ENVIRONMENT, 'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL, 'url': url, 'url_first': url[:url.rindex('/')+1], 'url_second': token, 'user': self.instance, 'email': new_email, } for old_new in ['old', 'new']: email_template_subject = get_template('email/{type}_email_subject.txt'.format(type=old_new)) email_template_text = get_template('email/{type}_email_update.txt'.format(type=old_new)) email_template_html = get_template('email/{type}_email_update.html'.format(type=old_new)) send_mail( ''.join(email_template_subject.render(context).splitlines()), # no newlines allowed in subject. email_template_text.render(context), settings.DEFAULT_FROM_EMAIL, recipient_list=[{'old': old_email, 'new': new_email}[old_new]], html_message=email_template_html.render(context), fail_silently=False) return self.instance
Example #7
Source File: tasks.py From open with MIT License | 5 votes |
def check_services_running(): if settings.ENVIRONMENT != PRODUCTION: return post_data = { "prompt": "We know that this is an important moment in the history of our country he said. We are proud to support the work of the American Civil Liberties Union and we will continue to fight for the rights of all Americans. The ACLU is currently suing the government over its surveillance programs. The ACLU said it had been monitoring the surveillance program since September 2011.", "temperature": 1, "api_key": settings.ML_SERVICE_ENDPOINT_API_KEY, "length": 20, "top_k": 30, } endpoints = [ settings.GPT2_MEDIUM_API_ENDPOINT, # settings.GPT2_LARGE_API_ENDPOINT, settings.GPT2_MEDIUM_HP_API_ENDPOINT, # settings.GPT2_MEDIUM_LEGAL_API_ENDPOINT, settings.GPT2_MEDIUM_RESEARCH_API_ENDPOINT, settings.GPT2_MEDIUM_COMPANIES_API_ENDPOINT, ] for url in endpoints: response = requests.post(url, json=post_data) data = response.json() assert response.status_code == 200 # make sure it returns text_4 assert len(data["text_4"]) > 30
Example #8
Source File: models.py From logtacts with MIT License | 5 votes |
def get_complete_url(self): protocol = 'https' if settings.ENVIRONMENT == 'dev': protocol = 'http' return "{}://{}{}".format( protocol, Site.objects.get_current().domain, self.get_absolute_url(), )
Example #9
Source File: models.py From logtacts with MIT License | 5 votes |
def get_complete_settings_url(self): protocol = 'https' if settings.ENVIRONMENT == 'dev': protocol = 'http' return "{}://{}{}".format( protocol, Site.objects.get_current().domain, self.get_settings_url(), )
Example #10
Source File: context_processors.py From logtacts with MIT License | 5 votes |
def selected_settings(request): return { 'ENVIRONMENT': settings.ENVIRONMENT, }
Example #11
Source File: views.py From micromasters with BSD 3-Clause "New" or "Revised" License | 5 votes |
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": settings.SENTRY_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": settings.SENTRY_DSN, } ) response.status_code = status_code return response
Example #12
Source File: models.py From micromasters with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_context(self, request, *args, **kwargs): programs = Program.objects.filter(live=True).select_related('programpage').order_by("id") benefits_page = BenefitsPage.objects.filter(live=True).first() js_settings = { "gaTrackingID": settings.GA_TRACKING_ID, "host": webpack_dev_server_host(request), "environment": settings.ENVIRONMENT, "sentry_dsn": settings.SENTRY_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 None program_pairs = [(program, get_program_page(program)) for program in programs] context["programs"] = program_pairs context["is_public"] = True context["has_zendesk_widget"] = True 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) context["benefits_url"] = benefits_page.get_url() if benefits_page else "" return context
Example #13
Source File: cache_buster.py From horas with MIT License | 5 votes |
def _get_buster(): if settings.ENVIRONMENT == "development": return int(time.time()) else: ref = os.getenv("HEAD_COMMIT_ID") if ref: # Use the first 7 chars of SHA like git log pretty format short_ref = ref[:7] return str(short_ref) else: # Missing HEAD_COMMIT_ID environment variable return "BAD_HEAD_COMMIT_ID"
Example #14
Source File: cache_buster.py From horas with MIT License | 5 votes |
def get_head_cached(): if settings.ENVIRONMENT == "development" or not CacheBusterTag.head: CacheBusterTag.head = CacheBusterTag._get_buster() return CacheBusterTag.head
Example #15
Source File: listing.py From pasportaservo with GNU Affero General Public License v3.0 | 4 votes |
def get_queryset(self): most_recent_moniker, most_recent = pgettext("value::plural", "MOST RECENT"), False if self.query in (most_recent_moniker, most_recent_moniker.replace(" ", "_")): most_recent = True self.query = '' qs = ( self.queryset .select_related(None) .defer('description', 'family_members_visibility') .select_related('owner', 'owner__user') .defer('owner__description', 'owner__email_visibility') ) self.result = geocode(self.query) if self.query and self.result.point: if any([self.result.country and not self.result.country_code, self.result.state, self.result.city]): return (qs .annotate(distance=Distance('location', self.result.point)) .order_by('distance')) elif self.result.country: # We assume it's a country self.paginate_first_by = 50 self.paginate_orphans = 5 self.country_search = True return (qs .filter(country=self.result.country_code.upper()) .order_by('-owner__user__last_login', '-id')) position = geocoder.ip(self.request.META['HTTP_X_REAL_IP'] if settings.ENVIRONMENT != 'DEV' else "188.166.58.162") position.point = Point(position.xy, srid=SRID) if position.xy else None logging.getLogger('PasportaServo.geo').debug( "User's position: %s, %s", position.address if position.ok and position.address else "UNKNOWN", position.xy if position.ok else position.error ) if position.point and not most_recent: # Results are sorted by distance from user's current location, but probably # it is better not to creep users out by unexpectedly using their location. qs = qs.annotate(internal_distance=Distance('location', position.point)).order_by('internal_distance') else: qs = qs.order_by('-owner__user__last_login', '-id') return qs
Example #16
Source File: views.py From micromasters with BSD 3-Clause "New" or "Revised" License | 4 votes |
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": settings.SENTRY_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), "PROGRAM_RECORD_LINK": settings.FEATURES.get('PROGRAM_RECORD_LINK', False), "ENABLE_PROGRAM_LETTER": settings.FEATURES.get('ENABLE_PROGRAM_LETTER', 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": "", } )