Exemple #1
0
def get_theme_base_dirs():
    """
    Return a list of all directories that contain themes.

    Raises:
        ImproperlyConfigured - exception is raised if
            1 - COMPREHENSIVE_THEME_DIRS is not a string
            2 - COMPREHENSIVE_THEME_DIRS is not an absolute path
            3 - path specified by COMPREHENSIVE_THEME_DIRS does not exist

    Example:
        >> get_theme_base_dirs()
        ['/edx/app/ecommerce/ecommerce/themes']

    Returns:
         (list): list of theme base directories
    """
    theme_dirs = settings.COMPREHENSIVE_THEME_DIRS

    if not isinstance(theme_dirs, list):
        raise ImproperlyConfigured("COMPREHENSIVE_THEME_DIRS must be a list.")
    if not all([isinstance(theme_dir, six.string_types) for theme_dir in theme_dirs]):
        raise ImproperlyConfigured("COMPREHENSIVE_THEME_DIRS must contain only strings.")
    if not all([theme_dir.startswith("/") for theme_dir in theme_dirs]):
        raise ImproperlyConfigured("COMPREHENSIVE_THEME_DIRS must contain only absolute paths to themes dirs.")
    if not all([os.path.isdir(theme_dir) for theme_dir in theme_dirs]):
        raise ImproperlyConfigured("COMPREHENSIVE_THEME_DIRS must contain valid paths.")

    return [Path(theme_dir) for theme_dir in theme_dirs]
def get_base_themes_dir():
    """
    Return base directory that contains all the themes.

    Raises:
        ImproperlyConfigured - exception is raised if
            1 - COMPREHENSIVE_THEME_DIR is not a string
            2 - COMPREHENSIVE_THEME_DIR is not an absolute path
            3 - path specified by COMPREHENSIVE_THEME_DIR does not exist

    Example:
        >> get_base_themes_dir()
        '/edx/app/ecommerce/ecommerce/themes'

    Returns:
         (Path): Base theme directory path
    """
    themes_dir = settings.COMPREHENSIVE_THEME_DIR

    if not isinstance(themes_dir, basestring):
        raise ImproperlyConfigured("COMPREHENSIVE_THEME_DIR must be a string.")
    if not themes_dir.startswith("/"):
        raise ImproperlyConfigured(
            "COMPREHENSIVE_THEME_DIR must be an absolute path to themes dir.")
    if not os.path.isdir(themes_dir):
        raise ImproperlyConfigured(
            "COMPREHENSIVE_THEME_DIR must be a valid path.")

    return Path(themes_dir)
def load_settings() -> None:
    try:
        settings = django_settings.{{ cookiecutter.app_name | upper }}
    except AttributeError:
        raise ImproperlyConfigured("{{ cookiecutter.app_name | upper }} settings is missing!")

    if not isinstance(settings, dict):
        raise ImproperlyConfigured("{{ cookiecutter.app_name | upper }} is not a dict!")
def load_settings() -> None:
    try:
        settings = django_settings.DJANGO_GITHUB_WEBHOOKS
    except AttributeError:
        raise ImproperlyConfigured(
            "DJANGO_GITHUB_WEBHOOKS settings is missing!")

    if not isinstance(settings, dict):
        raise ImproperlyConfigured("DJANGO_GITHUB_WEBHOOKS is not a dict!")

    if "ALLOWED_EVENTS" not in settings:
        settings["ALLOWED_EVENTS"] = constants.Events.values()
Exemple #5
0
 def ready(self):
     """Initialisation for django-ddp (setup lookups and signal handlers)."""
     if not settings.DATABASES:
         raise ImproperlyConfigured('No databases configured.')
     for (alias, conf) in settings.DATABASES.items():
         if conf['ENGINE'] != 'django.db.backends.postgresql_psycopg2':
             raise ImproperlyConfigured(
                 '%r uses %r: django-ddp only works with PostgreSQL.' % (
                     alias, conf['backend'],
                 )
             )
     self.api = autodiscover()
     self.api.ready()
def load_settings() -> None:
    try:
        settings = getattr(django_settings, SETTINGS_KEY)
    except AttributeError:
        raise ImproperlyConfigured(
            "{settings_key} settings is missing!".format(
                settings_key=SETTINGS_KEY))

    if not isinstance(settings, dict):
        raise ImproperlyConfigured(
            "{settings_key} is not a dict!".format(settings_key=SETTINGS_KEY))

    if not settings.get("ALLOWED_EVENTS"):
        settings["ALLOWED_EVENTS"] = Events.values()
Exemple #7
0
 def get_instance(cls):
     """
     Checks Django settings for api keys & IPN url and
     returns and initialized instance of `CoinPayments`
     """
     if not getattr(settings, 'COINPAYMENTS_API_KEY', None) or \
        not getattr(settings, 'COINPAYMENTS_API_SECRET', None):
         raise ImproperlyConfigured('COINPAYMENTS_API_KEY and COINPAYMENTS_API_SECRET are required!')
     ipn_url = getattr(settings, 'COINPAYMENTS_IPN_URL', None)
     if ipn_url:
         if not getattr(settings, 'COINPAYMENTS_IPN_SECRET', None) or \
            not getattr(settings, 'COINPAYMENTS_MERCHANT_ID', None):
             raise ImproperlyConfigured('COINPAYMENTS_IPN_SECRET and '
                                        'COINPAYMENTS_MERCHANT_ID are required if IPN is turned on!')
     return CoinPayments(settings.COINPAYMENTS_API_KEY, settings.COINPAYMENTS_API_SECRET, ipn_url=ipn_url)
Exemple #8
0
def _get_ignore_processor_name() -> str:
    """Get ignore processor name."""
    for proc_name, proc_class in SETTINGS.processors.items():
        if issubclass(proc_class, IgnorePaymentProcessor):
            return proc_name

    raise ImproperlyConfigured(
        "IgnorePaymentProcessor is not present in PAIN_PROCESSORS setting.")
Exemple #9
0
 def add_endpoint(
     self,
     url: str,
     endpoint: Endpoint,
     name: str,
 ) -> None:
     if url in self.endpoints:
         raise ImproperlyConfigured('Non-unique URL: ' + url)
     self.endpoints[url] = (endpoint, name)
 def get_secret(self) -> str:
     """
     Returns webhook's secret key.
     """
     secret = settings.DJANGO_GITHUB_WEBHOOKS.get("SECRET")
     if secret is None:
         raise ImproperlyConfigured(
             "SECRET key for DJANGO_GITHUB_WEBHOOKS is not specified!"
         )
     else:
         return secret
Exemple #11
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.url = self.settings.get('URL')
        if not self.url:
            raise ImproperlyConfigured('"URL" is required.')

        self.event_mapping = {
            key: EventType.objects.get(identifier=value)
            for key, value in EVENT_MAPPING.items() if value
        }
Exemple #12
0
def _get_api_obj(api_name):
    '''
    Instantiate and return an SMS API object. The API's settings
    dict is passed as keyword arguments to __init__.
    '''
    try:
        api_class = {
            'Clickatell': Clickatell,
            'BulkSMS': BulkSMS,
        }[api_name]
        api_kwargs = {
            'Clickatell': getattr(settings, 'CLICKATELL', {}),
            'BulkSMS': getattr(settings, 'BULKSMS', {})
        }[api_name]
        return api_class(**api_kwargs)
    except KeyError:
        raise InvalidAPIError(api_name)
    except AttributeError:
        raise ImproperlyConfigured("Settings for %s are missing" % api_name)
    except TypeError:
        raise ImproperlyConfigured("Invalid settings for %s" % api_name)
    def load_processors(self):
        self._processors = []

        for processor_path in _get_setting('PERMISSIONS_AUDITOR_PROCESSORS'):

            try:
                processor = import_string(processor_path)
                self._processors.append(processor())
            except (ImportError, TypeError) as ex:
                raise ImproperlyConfigured(
                    '{} is not a valid permissions processor.'.format(
                        processor_path)) from ex
Exemple #14
0
    def __init__(self):
        if not getattr(settings, 'ALFACOINS_SECRET_KEY', None) or \
                not getattr(settings, 'ALFACOINS_BUSINESS_NAME', None) or \
                not getattr(settings, 'ALFACOINS_PASSWORD', None):
            raise ImproperlyConfigured(
                'ALFACOINS_SECRET_KEY, ALFACOINS_BUSINESS_NAME '
                'and ALFACOINS_PASSWORD are required!')

        self._secret_key = getattr(settings, 'ALFACOINS_SECRET_KEY')
        self._name = getattr(settings, 'ALFACOINS_BUSINESS_NAME')
        self._password = getattr(settings, 'ALFACOINS_PASSWORD')
        self._notification_url = getattr(settings,
                                         'ALFACOINS_NOTIFICATION_URL', None)
        self._redirect_url = getattr(settings, 'ALFACOINS_REDIRECT_URL', None)
Exemple #15
0
def get_base_theme_dir():
    """
    Return base directory that contains all the themes.

    Example:
        >> get_base_theme_dir()
        '/edx/app/edxapp/edx-platform/themes'

    Returns:
         (Path): Base theme directory path
    """
    themes_dir = settings.COMPREHENSIVE_THEME_DIR
    if not isinstance(themes_dir, basestring):
        raise ImproperlyConfigured("COMPREHENSIVE_THEME_DIR must be a string.")
    return Path(themes_dir)
Exemple #16
0
 def ready(self):
     """Initialisation for django-ddp (setup lookups and signal handlers)."""
     if not settings.DATABASES:
         raise ImproperlyConfigured('No databases configured.')
     for (alias, conf) in settings.DATABASES.items():
         engine = conf['ENGINE']
         if engine != 'django.db.backends.postgresql_psycopg2':
             warnings.warn(
                 'Database %r uses unsupported %r engine.' % (
                     alias,
                     engine,
                 ),
                 UserWarning,
             )
     self.api = autodiscover()
     self.api.ready()
    def get_class_filter(self):
        """
        Override this method to override the class_names attribute.
        Must return an iterable.

        :return: a list of strings containing the full paths of mixins to detect.
        :raises ImproperlyConfigured: if the ``class_filter`` atribute is ``None``.
        """
        if self.class_filter is None:
            raise ImproperlyConfigured(
                '{0} is missing the class_filter attribute. Define {0}.class_filter, or override '
                '{0}.get_class_filter().'.format(self.__class__.__name__))
        if isinstance(self.class_filter, str):
            cls_filter = (self.class_filter, )
        else:
            cls_filter = self.class_filter
        return cls_filter
Exemple #18
0
def get_coins_list():
    coins = getattr(settings, 'COINPAYMENTS_ACCEPTED_COINS', None)
    if not coins:
        raise ImproperlyConfigured('COINPAYMENTS_ACCEPTED_COINS setting '
                                   'is required.')
    return coins
Exemple #19
0
"""
import os
import ConfigParser

from django.conf import ImproperlyConfigured

project_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
config_path = os.path.join(project_root, 'towngeek.cfg')
config = ConfigParser.ConfigParser()
try:
    with open(config_path, 'r') as fp:
        config.readfp(fp)
except IOError:
    msg = u"`towngeek.cfg` is missing in git checkouts root folder." \
         + "Please consult README.md."
    raise ImproperlyConfigured(msg)

# some cleanup and sanity checking for what is set in the cfg file
try:
    file_config = {
        'debug':
        config.getboolean("django:debug", "debug"),
        'default_db_engine':
        config.get("django:databases", "default-database-engine"),
        'default_db_name':
        config.get("django:databases", "default-database-name"),
        'default_db_user':
        config.get("django:databases", "default-database-user"),
        'default_db_password':
        config.get("django:databases", "default-database-password"),
        'default_db_host':
Exemple #20
0
import os
import logging

from .base import *

if os.environ.get('PROD'):
    logging.info('Using production settings')
    from .production import *
else:
    from .dev import *

try:
    from .local_settings import *
except ImportError:
    print('No local settings found')

from django.conf import ImproperlyConfigured
if not SECRET_KEY:
    raise ImproperlyConfigured(
        'please generate a SECRET_KEY and add it to your local settings')
Exemple #21
0
def get_theme_base_dirs():
    """
    Return base directory that contains all the themes.

    Raises:
        ImproperlyConfigured - exception is raised if
            1 - COMPREHENSIVE_THEME_DIRS is not a list
            1 - theme dir path is not a string
            2 - theme dir path is not an absolute path
            3 - path specified in COMPREHENSIVE_THEME_DIRS does not exist

    Example:
        >> get_theme_base_dirs()
        ['/edx/app/ecommerce/ecommerce/themes']

    Returns:
         (Path): Base theme directory path
    """
    # Return an empty list if theming is disabled
    if not is_comprehensive_theming_enabled():
        return []

    theme_base_dirs = []

    # Legacy code for COMPREHENSIVE_THEME_DIR backward compatibility
    if hasattr(settings, "COMPREHENSIVE_THEME_DIR"):
        theme_dir = settings.COMPREHENSIVE_THEME_DIR

        if not isinstance(theme_dir, basestring):
            raise ImproperlyConfigured(
                "COMPREHENSIVE_THEME_DIR must be a string.")
        if not theme_dir.startswith("/"):
            raise ImproperlyConfigured(
                "COMPREHENSIVE_THEME_DIR must be an absolute paths to themes dir."
            )
        if not os.path.isdir(theme_dir):
            raise ImproperlyConfigured(
                "COMPREHENSIVE_THEME_DIR must be a valid path.")

        theme_base_dirs.append(Path(theme_dir))

    if hasattr(settings, "COMPREHENSIVE_THEME_DIRS"):
        theme_dirs = settings.COMPREHENSIVE_THEME_DIRS

        if not isinstance(theme_dirs, list):
            raise ImproperlyConfigured(
                "COMPREHENSIVE_THEME_DIRS must be a list.")
        if not all(
            [isinstance(theme_dir, basestring) for theme_dir in theme_dirs]):
            raise ImproperlyConfigured(
                "COMPREHENSIVE_THEME_DIRS must contain only strings.")
        if not all([theme_dir.startswith("/") for theme_dir in theme_dirs]):
            raise ImproperlyConfigured(
                "COMPREHENSIVE_THEME_DIRS must contain only absolute paths to themes dirs."
            )
        if not all([os.path.isdir(theme_dir) for theme_dir in theme_dirs]):
            raise ImproperlyConfigured(
                "COMPREHENSIVE_THEME_DIRS must contain valid paths.")

        theme_base_dirs.extend([Path(theme_dir) for theme_dir in theme_dirs])

    return theme_base_dirs
Exemple #22
0
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/

LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'Europe/Paris'
USE_I18N = True
USE_L10N = True
USE_TZ = True

fr_formats.TIME_FORMAT = "H:i"

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
# print('STATICFILES_DIRS =', STATICFILES_DIRS)

STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')

SESSION_COOKIE_AGE = 60 * 60        # in minutes
# SESSION_EXPIRE_AT_BROWSER_CLOSE = True

try:
    ADMIN_EMAIL = env('PJCMC_ADMIN_EMAIL')
except KeyError as e:
    raise ImproperlyConfigured('Environment variable not set : %s' % e)