diff --git a/MANIFEST.in b/MANIFEST.in index c377988a..11708fc4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,7 @@ include Makefile include requirements.txt include requirements-swh.txt include version.txt include swh/web/db.sqlite3 recursive-include swh/web/static * -recursive-include swh/web/api/templates * +recursive-include swh/web/templates * diff --git a/setup.py b/setup.py index 6ba641b2..b300d5e1 100755 --- a/setup.py +++ b/setup.py @@ -1,34 +1,34 @@ #!/usr/bin/env python3 from setuptools import setup def parse_requirements(): requirements = [] for reqf in ('requirements.txt', 'requirements-swh.txt'): with open(reqf) as f: for line in f.readlines(): line = line.strip() if not line or line.startswith('#'): continue requirements.append(line) return requirements setup( name='swh.web', description='Software Heritage Web UI', author='Software Heritage developers', author_email='swh-devel@inria.fr', url='https://forge.softwareheritage.org/diffusion/DWUI/', - packages=['swh.web', 'swh.web.common', + packages=['swh.web', 'swh.web.common', 'swh.web.settings', 'swh.web.api', 'swh.web.api.views', - 'swh.web.api.templatetags', 'swh.web.settings', 'swh.web.tests', - 'swh.web.tests.api', 'swh.web.tests.api.views', + 'swh.web.tests', 'swh.web.tests.api', + 'swh.web.tests.api.views', 'swh.web.tests.common'], scripts=[], install_requires=parse_requirements(), setup_requires=['vcversioner'], vcversioner={}, include_package_data=True, ) diff --git a/swh/web/api/templatetags/__init__.py b/swh/web/api/templatetags/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/swh/web/api/templatetags/api_extras.py b/swh/web/common/swh_templatetags.py similarity index 100% rename from swh/web/api/templatetags/api_extras.py rename to swh/web/common/swh_templatetags.py diff --git a/swh/web/settings/common.py b/swh/web/settings/common.py index 13e24b52..f054f611 100644 --- a/swh/web/settings/common.py +++ b/swh/web/settings/common.py @@ -1,186 +1,189 @@ # 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': [], + 'DIRS': [os.path.join(PROJECT_DIR, "../templates")], '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', ], + 'libraries': { + 'swh_templatetags': 'swh.web.common.swh_templatetags', + }, }, }, ] 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 = {} throttling = swh_web_config['throttling'] for limiter_scope, limiter_conf in throttling['scopes'].items(): throttle_rates[limiter_scope] = limiter_conf['limiter_rate'] 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'] diff --git a/swh/web/api/templates/about.html b/swh/web/templates/about.html similarity index 100% rename from swh/web/api/templates/about.html rename to swh/web/templates/about.html diff --git a/swh/web/api/templates/api-endpoints.html b/swh/web/templates/api-endpoints.html similarity index 98% rename from swh/web/api/templates/api-endpoints.html rename to swh/web/templates/api-endpoints.html index 62dcca97..09d1648a 100644 --- a/swh/web/api/templates/api-endpoints.html +++ b/swh/web/templates/api-endpoints.html @@ -1,69 +1,69 @@ {% extends "layout.html" %} -{% load api_extras %} +{% load swh_templatetags %} {% block title %} Endpoints – Software Heritage API {% endblock %} {% block content %}

Below you can find a list of the available endpoints for version 1 of the Software Heritage API. For a more general introduction please refer to the API overview.

Endpoints marked "available" are considered stable for the current version of the API; endpoints marked "upcoming" are work in progress that will be stabilized in the near future.

{% for route, doc in doc_routes %} {% if doc.tags|length > 0 %} {% else %} {% endif %} {% endfor %}
Endpoint Status Description
{% url doc.route_view_name %} {{ doc.tags|join:', ' }}{% url doc.route_view_name %} available{{ doc.doc_intro | safe_docstring_display | safe }}
{% endblock %} diff --git a/swh/web/api/templates/api.html b/swh/web/templates/api.html similarity index 100% rename from swh/web/api/templates/api.html rename to swh/web/templates/api.html diff --git a/swh/web/api/templates/apidoc.html b/swh/web/templates/apidoc.html similarity index 99% rename from swh/web/api/templates/apidoc.html rename to swh/web/templates/apidoc.html index 7aaf0a09..07cd69e6 100644 --- a/swh/web/api/templates/apidoc.html +++ b/swh/web/templates/apidoc.html @@ -1,139 +1,139 @@ {% extends "layout.html" %} -{% load api_extras %} +{% load swh_templatetags %} {% block title %}{{ heading }} – Software Heritage API {% endblock %} {% block content %} {% if docstring %}

Description

{{ docstring | safe_docstring_display | safe }}
{% endif %} {% if response_data %}

Request

{{ request.method }} {{ request.build_absolute_uri }}

Response

{% if status_code != 200 %}

Status Code

{{ status_code }}
{% endif %} {% 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 %}
{% for url in urls %} {% endfor %}
URL Allowed Methods
{{ url.rule }} {{ url.methods | dictsort:0 | join:', ' }}

{% 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 and headers|length > 0 %}

Headers

{% for header in headers %}
{{ header.name }}: string
{{ header.doc | safe_docstring_display | safe }}
{% endfor %}

{% endif %} {% if returns and returns|length > 0 %}

Returns

{% for return in returns %}
{{ return.type }}
{{ return.doc | safe_docstring_display | safe }}
{% endfor %}

{% endif %} {% if excs and excs|length > 0 %}

Errors

{% for exc in excs %}
{{ exc.exc }}
{{ exc.doc | safe_docstring_display | safe }}
{% endfor %}

{% endif %} {% if examples and examples|length > 0 %}

Examples

{% for example in examples %}
{{ example }}
{% endfor %}
{% endif %} {% endblock %} diff --git a/swh/web/api/templates/browse.html b/swh/web/templates/browse.html similarity index 100% rename from swh/web/api/templates/browse.html rename to swh/web/templates/browse.html diff --git a/swh/web/api/templates/content-with-origin.html b/swh/web/templates/content-with-origin.html similarity index 100% rename from swh/web/api/templates/content-with-origin.html rename to swh/web/templates/content-with-origin.html diff --git a/swh/web/api/templates/content.html b/swh/web/templates/content.html similarity index 100% rename from swh/web/api/templates/content.html rename to swh/web/templates/content.html diff --git a/swh/web/api/templates/directory.html b/swh/web/templates/directory.html similarity index 100% rename from swh/web/api/templates/directory.html rename to swh/web/templates/directory.html diff --git a/swh/web/api/templates/entity.html b/swh/web/templates/entity.html similarity index 100% rename from swh/web/api/templates/entity.html rename to swh/web/templates/entity.html diff --git a/swh/web/api/templates/includes/apidoc-header-toc.html b/swh/web/templates/includes/apidoc-header-toc.html similarity index 100% rename from swh/web/api/templates/includes/apidoc-header-toc.html rename to swh/web/templates/includes/apidoc-header-toc.html diff --git a/swh/web/api/templates/includes/apidoc-header.html b/swh/web/templates/includes/apidoc-header.html similarity index 100% rename from swh/web/api/templates/includes/apidoc-header.html rename to swh/web/templates/includes/apidoc-header.html diff --git a/swh/web/api/templates/includes/apidoc-header.md b/swh/web/templates/includes/apidoc-header.md similarity index 100% rename from swh/web/api/templates/includes/apidoc-header.md rename to swh/web/templates/includes/apidoc-header.md diff --git a/swh/web/api/templates/includes/home-content.html b/swh/web/templates/includes/home-content.html similarity index 100% rename from swh/web/api/templates/includes/home-content.html rename to swh/web/templates/includes/home-content.html diff --git a/swh/web/api/templates/includes/home-directory.html b/swh/web/templates/includes/home-directory.html similarity index 100% rename from swh/web/api/templates/includes/home-directory.html rename to swh/web/templates/includes/home-directory.html diff --git a/swh/web/api/templates/includes/home-origin.html b/swh/web/templates/includes/home-origin.html similarity index 100% rename from swh/web/api/templates/includes/home-origin.html rename to swh/web/templates/includes/home-origin.html diff --git a/swh/web/api/templates/includes/home-revision.html b/swh/web/templates/includes/home-revision.html similarity index 100% rename from swh/web/api/templates/includes/home-revision.html rename to swh/web/templates/includes/home-revision.html diff --git a/swh/web/api/templates/includes/home-search-symbol.html b/swh/web/templates/includes/home-search-symbol.html similarity index 100% rename from swh/web/api/templates/includes/home-search-symbol.html rename to swh/web/templates/includes/home-search-symbol.html diff --git a/swh/web/api/templates/includes/search-form.html b/swh/web/templates/includes/search-form.html similarity index 100% rename from swh/web/api/templates/includes/search-form.html rename to swh/web/templates/includes/search-form.html diff --git a/swh/web/api/templates/layout.html b/swh/web/templates/layout.html similarity index 100% rename from swh/web/api/templates/layout.html rename to swh/web/templates/layout.html diff --git a/swh/web/api/templates/origin.html b/swh/web/templates/origin.html similarity index 100% rename from swh/web/api/templates/origin.html rename to swh/web/templates/origin.html diff --git a/swh/web/api/templates/person.html b/swh/web/templates/person.html similarity index 100% rename from swh/web/api/templates/person.html rename to swh/web/templates/person.html diff --git a/swh/web/api/templates/release.html b/swh/web/templates/release.html similarity index 100% rename from swh/web/api/templates/release.html rename to swh/web/templates/release.html diff --git a/swh/web/api/templates/revision-directory.html b/swh/web/templates/revision-directory.html similarity index 100% rename from swh/web/api/templates/revision-directory.html rename to swh/web/templates/revision-directory.html diff --git a/swh/web/api/templates/revision-log.html b/swh/web/templates/revision-log.html similarity index 100% rename from swh/web/api/templates/revision-log.html rename to swh/web/templates/revision-log.html diff --git a/swh/web/api/templates/revision.html b/swh/web/templates/revision.html similarity index 100% rename from swh/web/api/templates/revision.html rename to swh/web/templates/revision.html diff --git a/swh/web/api/templates/search.html b/swh/web/templates/search.html similarity index 100% rename from swh/web/api/templates/search.html rename to swh/web/templates/search.html diff --git a/swh/web/api/templates/symbols.html b/swh/web/templates/symbols.html similarity index 100% rename from swh/web/api/templates/symbols.html rename to swh/web/templates/symbols.html diff --git a/swh/web/tests/api/test_templatetags.py b/swh/web/tests/common/test_templatetags.py similarity index 85% rename from swh/web/tests/api/test_templatetags.py rename to swh/web/tests/common/test_templatetags.py index 8773d6ef..e466f121 100644 --- a/swh/web/tests/api/test_templatetags.py +++ b/swh/web/tests/common/test_templatetags.py @@ -1,66 +1,66 @@ # Copyright (C) 2015-2017 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 unittest from nose.tools import istest -from swh.web.api.templatetags import api_extras +from swh.web.common import swh_templatetags class SWHApiTemplateTagsTest(unittest.TestCase): @istest def urlize_api_links_api(self): # update api link with html links content with links content = '{"url": "/api/1/abc/"}' expected_content = ('{"url": "/api/1/abc/"}') - self.assertEquals(api_extras.urlize_api_links(content), + self.assertEquals(swh_templatetags.urlize_api_links(content), expected_content) @istest def urlize_api_links_browse(self): # update /browse link with html links content with links content = '{"url": "/browse/def/"}' expected_content = ('{"url": "' '/browse/def/"}') - self.assertEquals(api_extras.urlize_api_links(content), + self.assertEquals(swh_templatetags.urlize_api_links(content), expected_content) @istest def urlize_header_links(self): # update api link with html links content with links content = """; rel="next" ; rel="prev" """ expected_content = """</api/1/abc/>; rel="next" </api/1/def/>; rel="prev" """ - self.assertEquals(api_extras.urlize_header_links(content), + self.assertEquals(swh_templatetags.urlize_header_links(content), expected_content) @istest def safe_docstring_display(self): # update api link with html links content with links docstring = """This is my list header: - Here is item 1, with a continuation line right here - Here is item 2 Here is something that is not part of the list""" expected_docstring = """

This is my list header:

Here is something that is not part of the list

""" - self.assertEquals(api_extras.safe_docstring_display(docstring), + self.assertEquals(swh_templatetags.safe_docstring_display(docstring), expected_docstring)