Python django.conf.settings.py() Examples
The following are 30
code examples of django.conf.settings.py().
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: auth.py From wharf with GNU Affero General Public License v3.0 | 6 votes |
def authenticate(self, request, username=None, password=None): login_valid = (settings.ADMIN_LOGIN == username) if settings.ADMIN_PASSWORD.startswith("pbkdf2_sha256"): pwd_valid = check_password(password, settings.ADMIN_PASSWORD) else: pwd_valid = password == settings.ADMIN_PASSWORD if login_valid and pwd_valid: try: user = User.objects.get(username=username) except User.DoesNotExist: # Create a new user. There's no need to set a password # because only the password from settings.py is checked. user = User(username=username) user.is_staff = True user.is_superuser = True user.save() return user return None
Example #2
Source File: apps.py From openwisp-utils with BSD 3-Clause "New" or "Revised" License | 6 votes |
def configure_rest_framework_defaults(self): # merge the default DRF settings defined in openwisp-utils # and the default DRF settings defined in the app inheriting this class default_settings = DEFAULT_REST_FRAMEWORK_SETTINGS app_settings = getattr(self, 'REST_FRAMEWORK_SETTINGS', {}) merged_default_settings = deep_merge_dicts(default_settings, app_settings) # get the DRF settings defined in settings.py, if any current_settings = getattr(settings, 'REST_FRAMEWORK', {}) # loop over the default settings dict for key, value in merged_default_settings.items(): # if any key is a dictionary, and the same key # is also defined in settings.py # merge the two dicts, giving precedence # to what is defined in settings.py if isinstance(value, dict) and key in current_settings: value.update(current_settings[key]) current_settings[key] = value continue # otherwise just set it as default value current_settings.setdefault(key, value) # explicitly set it in settings.py setattr(settings, 'REST_FRAMEWORK', current_settings)
Example #3
Source File: bootstrapped_goodies_tags.py From celery-monitor with GNU General Public License v3.0 | 6 votes |
def language_selector(context): """ displays a language selector dropdown in the admin, based on Django "LANGUAGES" context. requires: * USE_I18N = True / settings.py * LANGUAGES specified / settings.py (otherwise all Django locales will be displayed) * "set_language" url configured (see https://docs.djangoproject.com/en/dev/topics/i18n/translation/#the-set-language-redirect-view) """ output = "" i18 = getattr(settings, 'USE_I18N', False) if i18: template = "admin/language_selector.html" context['i18n_is_set'] = True try: output = render_to_string(template, context) except: pass return output
Example #4
Source File: deliver_scheduled_messages.py From zulip with Apache License 2.0 | 6 votes |
def handle(self, *args: Any, **options: Any) -> None: if settings.EMAIL_DELIVERER_DISABLED: # Here doing a check and sleeping indefinitely on this setting might # not sound right. Actually we do this check to avoid running this # process on every server that might be in service to a realm. See # the comment in zproject/settings.py file about renaming this setting. sleep_forever() while True: messages_to_deliver = ScheduledMessage.objects.filter( scheduled_timestamp__lte=timezone_now(), delivered=False) if messages_to_deliver: for message in messages_to_deliver: with transaction.atomic(): do_send_messages([self.construct_message(message)]) message.delivered = True message.save(update_fields=['delivered']) cur_time = timezone_now() time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0) sleep_time = (time_next_min - cur_time).total_seconds() time.sleep(sleep_time)
Example #5
Source File: middleware.py From django-traffic with MIT License | 6 votes |
def __init__(self, get_response=None): self.get_response = get_response if hasattr(settings, 'TRAFFIC_INDEX_NAME'): self.index_name = getattr(settings, 'TRAFFIC_INDEX_NAME') else: self.index_name = "django-traffic" # if settings.ES_CLIENT: if hasattr(settings, 'ES_CLIENT'): self.es = settings.ES_CLIENT else: assert settings.ES_HOST, 'ES_HOST definition in settings.py is required' self.es = Elasticsearch( hosts=[settings.ES_HOST] ) super(ESTrafficInfoMiddleware, self).__init__(get_response=get_response)
Example #6
Source File: models.py From govready-q with GNU General Public License v3.0 | 6 votes |
def get_profile_picture_absolute_url(self): # Because of invitations, profile photos are not protected by # authorization. But to prevent user enumeration and to bust # caches when photos change, we include in the URL some # information about the internal data of the profile photo, # which is checked in views_landing.py's user_profile_photo(). # Get the current profile photo. try: pic = self._get_setting("picture") if pic is None: return except: return None # We've got the content. Make a fingerprint. import xxhash, base64 payload = pic['content_dataurl'] fingerprint = base64.urlsafe_b64encode( xxhash.xxh64(payload).digest() ).decode('ascii').rstrip("=") return settings.SITE_ROOT_URL + "/media/users/%d/photo/%s" % ( self.id, fingerprint )
Example #7
Source File: models.py From govready-q with GNU General Public License v3.0 | 6 votes |
def create(admin_user=None, **kargs): # admin_user is a required kwarg # See admin.py::OrganizationAdmin also. assert admin_user # Create instance by passing field values to the ORM. org = Organization.objects.create(**kargs) # And initialize the root Task of the Organization with this user as its editor. org.get_organization_project().set_system_task("organization", admin_user) # And make that user an admin of the Organization. pm, isnew = ProjectMembership.objects.get_or_create(user=admin_user, project=org.get_organization_project()) pm.is_admin = True pm.save() return org
Example #8
Source File: harvester.py From tom_base with GNU General Public License v3.0 | 6 votes |
def get_service_classes(): """ Gets the harvester classes available to this TOM as specified by ``TOM_HARVESTER_CLASSES`` in ``settings.py``. If none are specified, returns the default set. :returns: dict of harvester classes, with keys being the name of the catalog and values being the harvester class :rtype: dict """ try: TOM_HARVESTER_CLASSES = settings.TOM_HARVESTER_CLASSES except AttributeError: TOM_HARVESTER_CLASSES = DEFAULT_HARVESTER_CLASSES service_choices = {} for service in TOM_HARVESTER_CLASSES: mod_name, class_name = service.rsplit('.', 1) try: mod = import_module(mod_name) clazz = getattr(mod, class_name) except (ImportError, AttributeError): raise ImportError('Could not import {}. Did you provide the correct path?'.format(service)) service_choices[clazz.name] = clazz return service_choices
Example #9
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def run_manage(self, args, settings_file=None): def safe_remove(path): try: os.remove(path) except OSError: pass conf_dir = os.path.dirname(conf.__file__) template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py-tpl') test_manage_py = os.path.join(self.test_dir, 'manage.py') shutil.copyfile(template_manage_py, test_manage_py) with open(test_manage_py, 'r') as fp: manage_py_contents = fp.read() manage_py_contents = manage_py_contents.replace( "{{ project_name }}", "test_project") with open(test_manage_py, 'w') as fp: fp.write(manage_py_contents) self.addCleanup(safe_remove, test_manage_py) return self.run_test('./manage.py', args, settings_file)
Example #10
Source File: tom_setup.py From tom_base with GNU General Public License v3.0 | 6 votes |
def get_hint_preference(self): help_message_info = ( 'Help messages can be configured to appear to give suggestions on commonly customized functions. If ' 'enabled now, they can be turned off by changing HINTS_ENABLED to False in settings.py.\n' ) prompt = 'Would you like to enable hints? {}'.format(self.style.WARNING('[y/N] ')) self.stdout.write(help_message_info) while True: response = input(prompt).lower() if not response or response == 'n': self.context['HINTS_ENABLED'] = False elif response == 'y': self.context['HINTS_ENABLED'] = True else: self.stdout.write('Invalid response. Please try again.') continue break
Example #11
Source File: alerts.py From tom_base with GNU General Public License v3.0 | 6 votes |
def get_service_classes(): """ Gets the broker classes available to this TOM as specified by ``TOM_ALERT_CLASSES`` in ``settings.py``. If none are specified, returns the default set. :returns: dict of broker classes, with keys being the name of the broker and values being the broker class :rtype: dict """ try: TOM_ALERT_CLASSES = settings.TOM_ALERT_CLASSES except AttributeError: TOM_ALERT_CLASSES = DEFAULT_ALERT_CLASSES service_choices = {} for service in TOM_ALERT_CLASSES: mod_name, class_name = service.rsplit('.', 1) try: mod = import_module(mod_name) clazz = getattr(mod, class_name) except (ImportError, AttributeError): raise ImportError(f'Could not import {service}. Did you provide the correct path?') service_choices[clazz.name] = clazz return service_choices
Example #12
Source File: facility.py From tom_base with GNU General Public License v3.0 | 6 votes |
def get_facility_status(self): """ Returns a dictionary describing the current availability of the Facility telescopes. This is intended to be useful in observation planning. The top-level (Facility) dictionary has a list of sites. Each site is represented by a site dictionary which has a list of telescopes. Each telescope has an identifier (code) and an status string. The dictionary hierarchy is of the form: `facility_dict = {'code': 'XYZ', 'sites': [ site_dict, ... ]}` where `site_dict = {'code': 'XYZ', 'telescopes': [ telescope_dict, ... ]}` where `telescope_dict = {'code': 'XYZ', 'status': 'AVAILABILITY'}` See lco.py for a concrete implementation example. """ return {}
Example #13
Source File: auth.py From django-qiniu-storage with MIT License | 6 votes |
def authenticate(self, username=None, password=None): login_valid = (settings.ADMIN_LOGIN == username) pwd_valid = (settings.ADMIN_PASSWORD == password) if login_valid and pwd_valid: try: user = User.objects.get(username=username) except User.DoesNotExist: # Create a new user. Note that we can set password # to anything, because it won't be checked; the password # from settings.py will. user = User(username=username, password=password) user.is_staff = True user.is_superuser = True user.save() return user return None
Example #14
Source File: auth.py From django-oss-storage with MIT License | 6 votes |
def authenticate(self, username=None, password=None): """ Username and password authentication """ login_valid = (settings.ADMIN_LOGIN == username) pwd_valid = (settings.ADMIN_PASSWORD == password) if login_valid and pwd_valid: try: user = User.objects.get(username=username) except User.DoesNotExist: # Create a new user. Note that we can set password # to anything, because it won't be checked; the password # from settings.py will. user = User(username=username, password=password) user.is_staff = True user.is_superuser = True user.save() return user return None
Example #15
Source File: importer.py From texta with GNU General Public License v3.0 | 6 votes |
def __init__(self, es_url, configuration, data_access_object, file_system_storer): """ :param es_url: Elasticsearch instance's URL. :param configuration: DATASET_IMPORTER dict from texta/settings.py, which includes necessary parameters for importer. :param data_access_object: An attempt to separate Django's DatasetImport model object from import to reduce coupling and enhance testing. :param file_system_storer: Same as above. Django's built-in FileSystemStorage for storing data from requests to disk. :type es_url: string :type configuration: dict """ self._es_url = es_url self._root_directory = configuration['directory'] self._n_processes = configuration['import_processes'] self._process_batch_size = configuration['process_batch_size'] self._index_sqlite_path = configuration['sync']['index_sqlite_path'] self._dao = data_access_object self._file_system_storer = file_system_storer self._active_import_jobs = {}
Example #16
Source File: create_datadump.py From urbanfootprint with GNU General Public License v3.0 | 6 votes |
def handle(self, *args, **options): rsync = spawn.find_executable('rsync') if rsync is None: raise CommandError('rsync not found') pg_dump = spawn.find_executable('pg_dump') if pg_dump is None: raise CommandError('pg_dump not found') if options['destination_folder'] == '': raise CommandError('--destination-folder not specified in command line nor settings.py') # make sure destination folder exists if not os.path.exists(options['destination_folder']): try: os.makedirs(options['destination_folder']) except Exception, e: raise Exception("Cannot create directory with user %s. Exception %s" % ( pwd.getpwuid(os.getuid())[0], e.message))
Example #17
Source File: services.py From django-phone-verify with GNU General Public License v3.0 | 6 votes |
def _check_required_settings(self): required_settings = { "BACKEND", "OPTIONS", "TOKEN_LENGTH", "MESSAGE", "APP_NAME", "SECURITY_CODE_EXPIRATION_TIME", "VERIFY_SECURITY_CODE_ONLY_ONCE", } user_settings = set(settings.PHONE_VERIFICATION.keys()) if not required_settings.issubset(user_settings): raise ImproperlyConfigured( "Please specify following settings in settings.py: {}".format( ", ".join(required_settings - user_settings) ) )
Example #18
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_custom_command(self): "default: manage.py can execute user commands when default settings are appropriate" args = ['noargs_command'] out, err = self.run_manage(args) self.assertNoOutput(err) self.assertOutput(out, "EXECUTE: noargs_command")
Example #19
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def tearDown(self): self.remove_settings('settings.py') self.remove_settings('alternate_settings.py')
Example #20
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): self.write_settings('settings.py', apps=['django.contrib.auth', 'django.contrib.contenttypes']) self.write_settings('alternate_settings.py')
Example #21
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def tearDown(self): self.remove_settings('alternate_settings.py')
Example #22
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): self.write_settings('alternate_settings.py')
Example #23
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def remove_settings(self, filename, is_dir=False): full_name = os.path.join(self.test_dir, filename) if is_dir: shutil.rmtree(full_name) else: os.remove(full_name) # Also remove a __pycache__ directory, if it exists; it could # mess up later tests that depend upon the .py file not existing cache_name = os.path.join(self.test_dir, '__pycache__') if os.path.isdir(cache_name): shutil.rmtree(cache_name)
Example #24
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): self.write_settings('settings.py', apps=['django.contrib.auth', 'django.contrib.contenttypes'])
Example #25
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def tearDown(self): self.remove_settings('settings.py')
Example #26
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): self.write_settings('settings.py', ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts', 'admin_scripts.complex_app'])
Example #27
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def tearDown(self): self.remove_settings('settings.py')
Example #28
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): self.write_settings('settings.py')
Example #29
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def run_django_admin(self, args, settings_file=None): script_dir = os.path.abspath(os.path.join(os.path.dirname(django.__file__), 'bin')) return self.run_test(os.path.join(script_dir, 'django-admin.py'), args, settings_file)
Example #30
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_builtin_with_bad_environment(self): "fulldefault: manage.py builtin commands fail if settings file (from environment) doesn't exist" args = ['check', 'admin_scripts'] out, err = self.run_manage(args, 'bad_settings') self.assertNoOutput(out) self.assertOutput(err, "No module named '?bad_settings'?", regex=True)