<commit_before>"""
Django settings for api project.

Generated by 'django-admin startproject' using Django 1.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

import os
from website import settings as osf_settings

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = osf_settings.SECRET_KEY

AUTHENTICATION_BACKENDS = (
    'api.base.authentication.backends.ODMBackend',
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = osf_settings.DEBUG_MODE

ALLOWED_HOSTS = [
    '.osf.io'
]


# Application definition

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.staticfiles',

    # 3rd party
    'rest_framework',
    'rest_framework_swagger',
)

REST_FRAMEWORK = {
    'PAGE_SIZE': 10,

    # Order is important here because of a bug in rest_framework_swagger. For now,
    # rest_framework.renderers.JSONRenderer needs to be first, at least until
    # https://github.com/marcgibbons/django-rest-swagger/issues/271 is resolved.
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        'api.base.renderers.JSONAPIRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ),
    'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
    'DEFAULT_VERSION': '2.0',
    'DEFAULT_FILTER_BACKENDS': ('api.base.filters.ODMOrderingFilter',),
    'DEFAULT_PAGINATION_CLASS': 'api.base.pagination.JSONAPIPagination',
    'ORDERING_PARAM': 'sort',
    'DEFAULT_AUTHENTICATION_CLASSES': (
        # Custom auth classes
        'api.base.authentication.drf.OSFBasicAuthentication',
        'api.base.authentication.drf.OSFSessionAuthentication',
    ),
}

MIDDLEWARE_CLASSES = (
    # TokuMX transaction support
    # Needs to go before CommonMiddleware, so that transactions are always started,
    # even in the event of a redirect. CommonMiddleware may cause other middlewares'
    # process_request to be skipped, e.g. whne a trailing slash is omitted
    'api.base.middleware.TokuTransactionsMiddleware',

    # 'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    # 'django.contrib.auth.middleware.AuthenticationMiddleware',
    # 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    # 'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',

)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True
    }]


ROOT_URLCONF = 'api.base.urls'
WSGI_APPLICATION = 'api.base.wsgi.application'


LANGUAGE_CODE = 'en-us'

# Disabled to make a test work (TestNodeLog.test_formatted_date)
# TODO Try to understand what's happening to cause the test to break when that line is active.
# TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'static/vendor')
STATIC_URL = '/v2/static/'
STATICFILES_DIRS = (
    ('rest_framework_swagger/css', os.path.join(BASE_DIR, 'static/css')),
    ('rest_framework_swagger/images', os.path.join(BASE_DIR, 'static/images')),
)

SWAGGER_SETTINGS = {
    'info': {
        'description':
        """
        <p>Welcome to the V2 Open Science Framework API. Once this clause disappears from this sentence, the V2 API will be the first supported, public REST API for the Open Science Framework.
        We will define what the expected limits of the support are before this goes live, but for now I expect that this will be functional until we have at least the V3 API in place and
        possibly the V4. There may be additions to the V2 API, but no changes or deletions to the routes and returns. Links to services external to the OSF may change (see below), so following
        our development guidelines will be useful for maintaining compatibility.</p>
        <p>Each endpoint will have its own documentation, but there are some general things that should work pretty much everywhere.</p>
        <h2>Filtering</h2>
        <p>Collections can be filtered by adding a query parameter in the form:</p>
        <pre>filter[&lt;fieldname&gt;]=&lt;matching information&gt;</pre>
        <p>For example, if you were trying to find <a href="http://en.wikipedia.org/wiki/Lise_Meitner">Lise Metiner</a>:</p>
        <pre>/users?filter[fullname]=meitn</pre>
        <p>You can filter on multiple fields, or the same field in different ways, by &-ing the query parameters together.</p>
        <pre>/users?filter[fullname]=lise&filter[family_name]=mei</pre>
        <h2>Links</h2>
        <p>Responses will generally have associated links. These are helpers to keep you from having to construct
        URLs in your code or by hand. If you know the route to a high-level resource, then feel free to just go to that
        route. For example, going to:</p>
        <pre>/nodes/&lt;node_id&gt;</pre>
        <p>is a perfectly good route to create rather than going to /nodes/ and navigating from there by filtering by id
        (which would be ridiculous). However, if you are creating something that crawls the structure of a node
        going to child node or gathering children, contributors, and similar related resources, then grab the link from
        the object you\'re crawling rather than constructing the link yourself.
        In general, links include:</p>
        <ol>
        <li>1. "Related" links, which will give you detail information on individual items or a collection of related resources;</li>
        <li>2. "Self" links, which is what you use for general REST operations (POST, DELETE, and so on);</li>
        <li>3. Pagination links such as "next", "prev", "first", and "last". These are great for navigating long lists of information.</li></ol>
        <p>Some routes may have extra rules for links, especially if those links work with external services. Collections
        may have counts with them to indicate how many items are in that collection.</p>""",
        'title': 'OSF API Documentation',
    }
}<commit_msg>Make swagger docs show list of routes by default<commit_after>"""
Django settings for api project.

Generated by 'django-admin startproject' using Django 1.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

import os
from website import settings as osf_settings

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = osf_settings.SECRET_KEY

AUTHENTICATION_BACKENDS = (
    'api.base.authentication.backends.ODMBackend',
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = osf_settings.DEBUG_MODE

ALLOWED_HOSTS = [
    '.osf.io'
]


# Application definition

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.staticfiles',

    # 3rd party
    'rest_framework',
    'rest_framework_swagger',
)

REST_FRAMEWORK = {
    'PAGE_SIZE': 10,

    # Order is important here because of a bug in rest_framework_swagger. For now,
    # rest_framework.renderers.JSONRenderer needs to be first, at least until
    # https://github.com/marcgibbons/django-rest-swagger/issues/271 is resolved.
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
        'api.base.renderers.JSONAPIRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ),
    'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
    'DEFAULT_VERSION': '2.0',
    'DEFAULT_FILTER_BACKENDS': ('api.base.filters.ODMOrderingFilter',),
    'DEFAULT_PAGINATION_CLASS': 'api.base.pagination.JSONAPIPagination',
    'ORDERING_PARAM': 'sort',
    'DEFAULT_AUTHENTICATION_CLASSES': (
        # Custom auth classes
        'api.base.authentication.drf.OSFBasicAuthentication',
        'api.base.authentication.drf.OSFSessionAuthentication',
    ),
}

MIDDLEWARE_CLASSES = (
    # TokuMX transaction support
    # Needs to go before CommonMiddleware, so that transactions are always started,
    # even in the event of a redirect. CommonMiddleware may cause other middlewares'
    # process_request to be skipped, e.g. whne a trailing slash is omitted
    'api.base.middleware.TokuTransactionsMiddleware',

    # 'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    # 'django.contrib.auth.middleware.AuthenticationMiddleware',
    # 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    # 'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',

)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True
    }]


ROOT_URLCONF = 'api.base.urls'
WSGI_APPLICATION = 'api.base.wsgi.application'


LANGUAGE_CODE = 'en-us'

# Disabled to make a test work (TestNodeLog.test_formatted_date)
# TODO Try to understand what's happening to cause the test to break when that line is active.
# TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'static/vendor')
STATIC_URL = '/v2/static/'
STATICFILES_DIRS = (
    ('rest_framework_swagger/css', os.path.join(BASE_DIR, 'static/css')),
    ('rest_framework_swagger/images', os.path.join(BASE_DIR, 'static/images')),
)

SWAGGER_SETTINGS = {
    'info': {
        'description':
        """
        <p>Welcome to the V2 Open Science Framework API. Once this clause disappears from this sentence, the V2 API will be the first supported, public REST API for the Open Science Framework.
        We will define what the expected limits of the support are before this goes live, but for now I expect that this will be functional until we have at least the V3 API in place and
        possibly the V4. There may be additions to the V2 API, but no changes or deletions to the routes and returns. Links to services external to the OSF may change (see below), so following
        our development guidelines will be useful for maintaining compatibility.</p>
        <p>Each endpoint will have its own documentation, but there are some general things that should work pretty much everywhere.</p>
        <h2>Filtering</h2>
        <p>Collections can be filtered by adding a query parameter in the form:</p>
        <pre>filter[&lt;fieldname&gt;]=&lt;matching information&gt;</pre>
        <p>For example, if you were trying to find <a href="http://en.wikipedia.org/wiki/Lise_Meitner"><NAME></a>:</p>
        <pre>/users?filter[fullname]=meitn</pre>
        <p>You can filter on multiple fields, or the same field in different ways, by &-ing the query parameters together.</p>
        <pre>/users?filter[fullname]=lise&filter[family_name]=mei</pre>
        <h2>Links</h2>
        <p>Responses will generally have associated links. These are helpers to keep you from having to construct
        URLs in your code or by hand. If you know the route to a high-level resource, then feel free to just go to that
        route. For example, going to:</p>
        <pre>/nodes/&lt;node_id&gt;</pre>
        <p>is a perfectly good route to create rather than going to /nodes/ and navigating from there by filtering by id
        (which would be ridiculous). However, if you are creating something that crawls the structure of a node
        going to child node or gathering children, contributors, and similar related resources, then grab the link from
        the object you\'re crawling rather than constructing the link yourself.
        In general, links include:</p>
        <ol>
        <li>1. "Related" links, which will give you detail information on individual items or a collection of related resources;</li>
        <li>2. "Self" links, which is what you use for general REST operations (POST, DELETE, and so on);</li>
        <li>3. Pagination links such as "next", "prev", "first", and "last". These are great for navigating long lists of information.</li></ol>
        <p>Some routes may have extra rules for links, especially if those links work with external services. Collections
        may have counts with them to indicate how many items are in that collection.</p>""",
        'title': 'OSF API Documentation',
    },
    'doc_expansion': 'list',
}
{'fraction_non_alphanumeric': 0.09979846234231544, 'fraction_numerical': 0.0052250503844144215, 'mean_word_length': 3.687893631910427, 'pattern_counts': {'":': 0, '<': 80, '<?xml version=': 0, '>': 80, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7419879', 'n_tokens_mistral': 4043, 'n_tokens_neox': 3934, 'n_words': 1257}