diff --git a/bin/swh-web-dev b/bin/swh-web-dev
index 0a6bfe07..15c30c8a 100755
--- a/bin/swh-web-dev
+++ b/bin/swh-web-dev
@@ -1,45 +1,48 @@
#!/usr/bin/env python3
# Copyright (C) 2015 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
import argparse
import django
import os
-from django.core import management
+# need to setup django settings before importing django modules
+# with django 1.7 (debian jessie)
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swh.web.settings") # noqa
-from django.core.management.commands.runserver import (
+from django.core import management # noqa
+
+from django.core.management.commands.runserver import ( # noqa
Command as runserver
)
-from swh.web import config
+from swh.web import config # noqa
# Default configuration file
DEFAULT_CONF_FILE = '~/.config/swh/webapp.yml'
def parse_args():
"""Parse the configuration for the cli.
"""
cli = argparse.ArgumentParser(description="SWH's web ui.")
cli.add_argument('--config', '-c', help='configuration file path')
args = cli.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
config_path = args.config or DEFAULT_CONF_FILE
swh_web_config = config.get_config(config_path)
runserver.default_port = swh_web_config['port']
runserver.default_addr = swh_web_config['host']
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swh.web.settings")
django.setup()
management.call_command('runserver')
diff --git a/swh/web/api/templates/apidoc.html b/swh/web/api/templates/apidoc.html
index cf519977..ed207309 100644
--- a/swh/web/api/templates/apidoc.html
+++ b/swh/web/api/templates/apidoc.html
@@ -1,137 +1,137 @@
{% extends "layout.html" %}
{% load api_extras %}
{% block title %}{{ heading }} – Software Heritage API {% endblock %}
{% block content %}
{% if docstring %}
Description
{{ docstring | safe_docstring_display | safe }}
{% endif %}
-{% if response_data and response_data is not none %}
+{% if response_data %}
Request
{{ request.method }} {{ request.build_absolute_uri }}
Response
{% if status_code != 200 %}
Status Code
{{ status_code }}
{% endif %}
- {% if headers_data and headers_data is not none %}
+ {% if headers_data %}
Headers
{% for header_name, header_value in headers_data.items %}
{{ header_name }} {{ header_value | urlize_header_links | safe }}
{% endfor %}
{% endif %}
Body
{{ response_data | highlight_json | urlize_api_links | safe }}
{% endif %}
{% if urls and urls|length > 0 %}
URL |
Allowed Methods |
{% for url in urls %}
{{ url.rule }}
|
{{ url.methods | dictsort:0 | join:', ' }}
|
{% endfor %}
{% endif %}
{% if args and args|length > 0 %}
Arguments
{% for arg in args %}
- {{ arg.name }}: {{ arg.type }}
- {{ arg.doc | safe_docstring_display | safe }}
{% endfor %}
{% endif %}
{% if params and params|length > 0 %}
Parameters
{% for param in params %}
- {{ param.name }}: {{ param.type }}
- {{ param.doc | safe_docstring_display | safe }}
{% endfor %}
{% endif %}
{% if headers %}
{% endif %}
{% if return %}
Returns
- {{ return.type }}
- {{ return.doc | safe_docstring_display | safe }}
{% endif %}
{% if excs and excs|length > 0 %}
Errors
{% for exc in excs %}
- {{ exc.exc }}
- {{ exc.doc | safe_docstring_display | safe }}
{% endfor %}
{% endif %}
{% if examples %}
Examples
{% for example in examples %}
-
{{ example }}
{% endfor %}
{% endif %}
{% endblock %}
diff --git a/swh/web/settings.py b/swh/web/settings.py
index 19144893..ec0df993 100644
--- a/swh/web/settings.py
+++ b/swh/web/settings.py
@@ -1,183 +1,185 @@
# Copyright (C) 2017 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
"""
Django settings for swhweb project.
Generated by 'django-admin startproject' using Django 1.11.3.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
from swh.web.config import get_config
swh_web_config = get_config()
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = swh_web_config['secret_key']
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = swh_web_config['debug']
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'testserver']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'swh.web.api'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'swh.web.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'swh.web.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', # noqa
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', # noqa
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', # noqa
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(PROJECT_DIR, "static")
]
INTERNAL_IPS = ['127.0.0.1']
throttle_rates = {}
for limiter_scope, limiter_conf in swh_web_config['limiters'].items():
throttle_rates[limiter_scope] = None if DEBUG else limiter_conf['limiter_rate'] # noqa
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'swh.web.api.renderers.YAMLRenderer',
'rest_framework.renderers.TemplateHTMLRenderer'
),
'DEFAULT_THROTTLE_CLASSES': (
'swh.web.common.throttling.SwhWebRateThrottle',
),
'DEFAULT_THROTTLE_RATES': throttle_rates
}
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
},
},
'handlers': {
'console': {
'level': 'INFO',
'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
},
'file': {
'level': 'DEBUG',
'filters': ['require_debug_false'],
'class': 'logging.FileHandler',
'filename': os.path.join(swh_web_config['log_dir'], 'swh-web.log'),
},
},
'loggers': {
'django': {
'handlers': ['console', 'file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
+
+SILENCED_SYSTEM_CHECKS = ['1_7.W001']