diff --git a/.coveragerc b/.coveragerc index 588164d..000fa1f 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,7 @@ [run] -source = app_namespace -omit = app_namespace/tests/* - app_namespace/demo/* +source = apptemplates +omit = apptemplates/tests/* + apptemplates/demo/* [report] exclude_lines = diff --git a/.travis.yml b/.travis.yml index 6a83e05..f2a9b81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: - 2.7 - 3.3 - 3.4 + - 3.5 env: - DJANGO=1.8 - DJANGO=1.9 @@ -16,7 +17,7 @@ install: - python bootstrap.py - ./bin/buildout versions:django=$DJANGO before_script: - - ./bin/flake8 app_namespace + - ./bin/flake8 apptemplates script: - ./bin/test-and-cover after_success: diff --git a/MANIFEST.in b/MANIFEST.in index 31ee690..b8500d8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,4 +3,4 @@ include README.rst include versions.cfg include buildout.cfg include bootstrap.py -recursive-include app_namespace/demo * +recursive-include apptemplates/demo * diff --git a/README.rst b/README.rst index 6980077..2c7d6e0 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,27 @@ -==================================== -Django App Namespace Template Loader -==================================== +=================== +django-apptemplates +=================== -|travis-develop| |coverage-develop| +|travis-develop| |coverage-develop| |PyPi| + +Name change notification +------------------------ + +This project used to be called ``django-app-namespace-template-loader`` but a +decision has been made to merge with ``django-apptemplates``. The merge does not +actually include any code from ``django-apptemplates`` but rather bumps that +application to 2.0, keeping the code from this project. + +The reason is to avoid having to projects addressing exactly the same issue. + +Please update your PyPi requirements to use ``django-apptemplates``. + +More background of the decision in +`this issue `_. + + +Introduction +------------ Provides a template loader that allows you to load a template from a specific application. This allows you to both **extend** and **override** a @@ -16,10 +35,12 @@ This is the issue that this package tries to resolve. Examples: --------- -You want to change the titles of the admin site, you would originally -created this template: :: +You want to change the titles of the admin site (located in +``my-project/templates/admin/base_site.html``), you would originally create +this template: + +.. code-block:: html+django - $ cat my-project/templates/admin/base_site.html {% extends "admin/base.html" %} {% load i18n %} @@ -31,9 +52,11 @@ created this template: :: {% block nav-global %}{% endblock %} -Extend and override version with a namespace: :: +But instead, you can extend ``my-project/templates/admin/base_site.html`` and +override Django's version with a namespace: + +.. code-block:: html+django - $ cat my-project/templates/admin/base_site.html {% extends "admin:admin/base_site.html" %} {% block title %}{{ title }} - My Project{% endblock %} @@ -45,9 +68,11 @@ Extend and override version with a namespace: :: Note that in this version the block ``nav-global`` does not have to be present because of the inheritance. -Shorter version without namespace: :: +Shorter version of ``my-project/templates/admin/base_site.html`` without +namespace: + +.. code-block:: html+django - $ cat my-project/templates/admin/base_site.html {% extends ":admin/base_site.html" %} {% block title %}{{ title }} - My Project{% endblock %} @@ -60,28 +85,39 @@ If we do not specify the application namespace, the first matching template will be used. This is useful when several applications provide the same templates but with different features. -Example of multiple empty namespaces: :: +Example of multiple empty namespaces: + +``my-project/application/templates/application/template.html`` + +.. code-block:: html+django - $ cat my-project/application/templates/application/template.html {% block content%}

Application

{% endblock content%} - $ cat my-project/application_extension/templates/application/template.html +``my-project/application_extension/templates/application/template.html`` + +.. code-block:: html+django + {% extends ":application/template.html" %} {% block content%} {{ block.super }}

Application extension

{% endblock content%} - $ cat my-project/templates/application/template.html +``my-project/templates/application/template.html`` + +.. code-block:: html+django + {% extends ":application/template.html" %} {% block content%} {{ block.super }}

Application project

{% endblock content%} -Will render: :: +Will render: + +.. code-block:: html+django

Application

Application extension

@@ -90,29 +126,33 @@ Will render: :: Installation ------------ -First of all install ``django-app-namespace-template-loader`` with your -favorite package manager. Example : :: +First of all install ``django-apptemplates`` with your +favorite package manager. Example:: - $ pip install django-app-namespace-template-loader + $ pip install django-apptemplates -Once installed, add ``app_namespace.Loader`` to the ``TEMPLATE_LOADERS`` -setting of your project. :: +Once installed, add ``apptemplates.Loader`` to the ``TEMPLATE_LOADERS`` +setting of your project. + +.. code-block:: python TEMPLATE_LOADERS = [ - 'app_namespace.Loader', + 'apptemplates.Loader', ... # Other template loaders ] -With Django >= 1.8 ``app_namespace.Loader`` should be added to the +With Django >= 1.8 ``apptemplates.Loader`` should be added to the ``'loaders'`` section in the OPTIONS dict of the ``DjangoTemplates`` backend -instead. :: +instead. + +.. code-block:: python TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'OPTIONS': { 'loaders': [ - 'app_namespace.Loader', + 'apptemplates.Loader', 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ], @@ -123,10 +163,24 @@ instead. :: Known limitations ================= -``app_namespace.Loader`` can not work properly if you use it in conjunction +``apptemplates.Loader`` can not work properly if you use it in conjunction with ``django.template.loaders.cached.Loader`` and inheritance based on empty namespaces. + +Authors and Maintainers +----------------------- + +Before version 2.0, django-apptemplates was created and maintained by: + + - Peter Bittner (current maintainer) + - Tomas Zulberti (former maintainer) + - Konrad Wojas (original author) + +Since 2.0+, the project's codebase was replaced by the compatible project django-app-namespace-template-loader by author of django-blog-zinnia: + + - Fantomas42 (author and maintainer) + Notes ----- @@ -134,7 +188,7 @@ Based originally on: http://djangosnippets.org/snippets/1376/ Requires: Django >= 1.8 -Tested with Python 2.7, 3.3, 3.4. +Tested with Python 2.7, 3.3, 3.4, 3.5. If you want to use this application for previous versions of Django, use the version 0.3.1 of the package. @@ -142,9 +196,13 @@ version 0.3.1 of the package. If you want to use this application with Python 2.6, use the version 0.2 of the package. -.. |travis-develop| image:: https://travis-ci.org/Fantomas42/django-app-namespace-template-loader.png?branch=develop +.. |travis-develop| image:: https://travis-ci.org/Fantomas42/django-apptemplates.png?branch=develop :alt: Build Status - develop branch - :target: http://travis-ci.org/Fantomas42/django-app-namespace-template-loader -.. |coverage-develop| image:: https://coveralls.io/repos/Fantomas42/django-app-namespace-template-loader/badge.png?branch=develop + :target: http://travis-ci.org/Fantomas42/django-apptemplates +.. |coverage-develop| image:: https://coveralls.io/repos/Fantomas42/django-apptemplates/badge.png?branch=develop :alt: Coverage of the code - :target: https://coveralls.io/r/Fantomas42/django-app-namespace-template-loader + :target: https://coveralls.io/r/Fantomas42/django-apptemplates +.. |PyPi| image:: https://badge.fury.io/py/django-apptemplates.svg + :target: https://pypi.python.org/pypi/django-apptemplates/ + :alt: PyPi download page + diff --git a/app_namespace/demo/__init__.py b/app_namespace/demo/__init__.py deleted file mode 100644 index 8a2be8c..0000000 --- a/app_namespace/demo/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Demo of the app_namespace app""" diff --git a/app_namespace/tests/__init__.py b/app_namespace/tests/__init__.py deleted file mode 100644 index 9d60401..0000000 --- a/app_namespace/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Tests for app_namespace""" diff --git a/app_namespace/__init__.py b/apptemplates/__init__.py similarity index 61% rename from app_namespace/__init__.py rename to apptemplates/__init__.py index ae17f02..df02a06 100644 --- a/app_namespace/__init__.py +++ b/apptemplates/__init__.py @@ -1,4 +1,4 @@ """App namespace template loader""" -from app_namespace.loader import Loader +from apptemplates.loader import Loader __all__ = [Loader.__name__] diff --git a/apptemplates/__init__.pyc b/apptemplates/__init__.pyc new file mode 100644 index 0000000..61d5463 Binary files /dev/null and b/apptemplates/__init__.pyc differ diff --git a/apptemplates/demo/__init__.py b/apptemplates/demo/__init__.py new file mode 100644 index 0000000..759dc5e --- /dev/null +++ b/apptemplates/demo/__init__.py @@ -0,0 +1 @@ +"""Demo of the apptemplates app""" diff --git a/apptemplates/demo/__init__.pyc b/apptemplates/demo/__init__.pyc new file mode 100644 index 0000000..ee2a542 Binary files /dev/null and b/apptemplates/demo/__init__.pyc differ diff --git a/app_namespace/demo/application/__init__.py b/apptemplates/demo/application/__init__.py similarity index 100% rename from app_namespace/demo/application/__init__.py rename to apptemplates/demo/application/__init__.py diff --git a/apptemplates/demo/application/__init__.pyc b/apptemplates/demo/application/__init__.pyc new file mode 100644 index 0000000..c646c14 Binary files /dev/null and b/apptemplates/demo/application/__init__.pyc differ diff --git a/app_namespace/demo/application/templates/application/template.html b/apptemplates/demo/application/templates/application/template.html similarity index 100% rename from app_namespace/demo/application/templates/application/template.html rename to apptemplates/demo/application/templates/application/template.html diff --git a/app_namespace/demo/application_appconfig/__init__.py b/apptemplates/demo/application_appconfig/__init__.py similarity index 100% rename from app_namespace/demo/application_appconfig/__init__.py rename to apptemplates/demo/application_appconfig/__init__.py diff --git a/apptemplates/demo/application_appconfig/__init__.pyc b/apptemplates/demo/application_appconfig/__init__.pyc new file mode 100644 index 0000000..44a428f Binary files /dev/null and b/apptemplates/demo/application_appconfig/__init__.pyc differ diff --git a/app_namespace/demo/application_appconfig/apps.py b/apptemplates/demo/application_appconfig/apps.py similarity index 100% rename from app_namespace/demo/application_appconfig/apps.py rename to apptemplates/demo/application_appconfig/apps.py diff --git a/app_namespace/demo/application_appconfig/templates/application/template.html b/apptemplates/demo/application_appconfig/templates/application/template.html similarity index 100% rename from app_namespace/demo/application_appconfig/templates/application/template.html rename to apptemplates/demo/application_appconfig/templates/application/template.html diff --git a/app_namespace/demo/application_extension/__init__.py b/apptemplates/demo/application_extension/__init__.py similarity index 100% rename from app_namespace/demo/application_extension/__init__.py rename to apptemplates/demo/application_extension/__init__.py diff --git a/apptemplates/demo/application_extension/__init__.pyc b/apptemplates/demo/application_extension/__init__.pyc new file mode 100644 index 0000000..f8af76a Binary files /dev/null and b/apptemplates/demo/application_extension/__init__.pyc differ diff --git a/app_namespace/demo/application_extension/templates/application/template.html b/apptemplates/demo/application_extension/templates/application/template.html similarity index 100% rename from app_namespace/demo/application_extension/templates/application/template.html rename to apptemplates/demo/application_extension/templates/application/template.html diff --git a/app_namespace/demo/settings.py b/apptemplates/demo/settings.py similarity index 67% rename from app_namespace/demo/settings.py rename to apptemplates/demo/settings.py index 75ca320..ceea0a5 100644 --- a/app_namespace/demo/settings.py +++ b/apptemplates/demo/settings.py @@ -1,4 +1,4 @@ -"""Settings for the app_namespace demo""" +"""Settings for the apptemplates demo""" import os PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) @@ -9,7 +9,7 @@ SECRET_KEY = 'secret-key' -ROOT_URLCONF = 'app_namespace.demo.urls' +ROOT_URLCONF = 'apptemplates.demo.urls' TEMPLATES = [ { @@ -19,7 +19,7 @@ ], 'OPTIONS': { 'debug': DEBUG, - 'loaders': ('app_namespace.Loader', + 'loaders': ('apptemplates.Loader', 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader') } @@ -27,9 +27,9 @@ ] INSTALLED_APPS = ( - 'app_namespace.demo.application_extension', - 'app_namespace.demo.application_appconfig.apps.ApplicationConfig', - 'app_namespace.demo.application', + 'apptemplates.demo.application_extension', + 'apptemplates.demo.application_appconfig.apps.ApplicationConfig', + 'apptemplates.demo.application', ) SILENCED_SYSTEM_CHECKS = ['1_7.W001', '1_8.W001'] diff --git a/app_namespace/demo/templates/application/template.html b/apptemplates/demo/templates/application/template.html similarity index 100% rename from app_namespace/demo/templates/application/template.html rename to apptemplates/demo/templates/application/template.html diff --git a/app_namespace/demo/urls.py b/apptemplates/demo/urls.py similarity index 83% rename from app_namespace/demo/urls.py rename to apptemplates/demo/urls.py index 4060abf..24f6d86 100644 --- a/app_namespace/demo/urls.py +++ b/apptemplates/demo/urls.py @@ -1,4 +1,4 @@ -"""Urls for the app_namespace demo""" +"""Urls for the apptemplates demo""" from django.conf.urls import url from django.views.generic import TemplateView diff --git a/app_namespace/loader.py b/apptemplates/loader.py similarity index 96% rename from app_namespace/loader.py rename to apptemplates/loader.py index a481a96..5517b47 100644 --- a/app_namespace/loader.py +++ b/apptemplates/loader.py @@ -96,7 +96,7 @@ def get_template_sources(self, template_name): if app: yield NamespaceOrigin( app_name=app, - name='app_namespace:%s:%s' % (app, template_name), + name='apptemplates:%s:%s' % (app, template_name), template_name=template_path, loader=self) @@ -107,7 +107,7 @@ def get_template_sources(self, template_name): self._already_used.append(file_path) yield NamespaceOrigin( app_name=app, - name='app_namespace:%s:%s' % (app, template_name), + name='apptemplates:%s:%s' % (app, template_name), template_name=template_path, loader=self) diff --git a/apptemplates/loader.pyc b/apptemplates/loader.pyc new file mode 100644 index 0000000..4cc6885 Binary files /dev/null and b/apptemplates/loader.pyc differ diff --git a/apptemplates/tests/__init__.py b/apptemplates/tests/__init__.py new file mode 100644 index 0000000..c73bce7 --- /dev/null +++ b/apptemplates/tests/__init__.py @@ -0,0 +1 @@ +"""Tests for apptemplates""" diff --git a/apptemplates/tests/__init__.pyc b/apptemplates/tests/__init__.pyc new file mode 100644 index 0000000..fd12d22 Binary files /dev/null and b/apptemplates/tests/__init__.pyc differ diff --git a/app_namespace/tests/settings.py b/apptemplates/tests/settings.py similarity index 71% rename from app_namespace/tests/settings.py rename to apptemplates/tests/settings.py index 36a6a9b..47e8510 100644 --- a/app_namespace/tests/settings.py +++ b/apptemplates/tests/settings.py @@ -1,5 +1,5 @@ -"""Settings for testing app_namespace""" -DATABASES = {'default': {'NAME': 'app_namespace.db', +"""Settings for testing apptemplates""" +DATABASES = {'default': {'NAME': 'apptemplates.db', 'ENGINE': 'django.db.backends.sqlite3'}} SECRET_KEY = 'secret-key' @@ -8,13 +8,13 @@ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'OPTIONS': { - 'loaders': ('app_namespace.Loader', + 'loaders': ('apptemplates.Loader', 'django.template.loaders.app_directories.Loader') } } ] -ROOT_URLCONF = 'app_namespace.tests.urls' +ROOT_URLCONF = 'apptemplates.tests.urls' INSTALLED_APPS = ('django.contrib.auth', 'django.contrib.admin', diff --git a/apptemplates/tests/settings.pyc b/apptemplates/tests/settings.pyc new file mode 100644 index 0000000..86e26d3 Binary files /dev/null and b/apptemplates/tests/settings.pyc differ diff --git a/app_namespace/tests/tests.py b/apptemplates/tests/tests.py similarity index 89% rename from app_namespace/tests/tests.py rename to apptemplates/tests/tests.py index 91a9e32..3eadcf4 100644 --- a/app_namespace/tests/tests.py +++ b/apptemplates/tests/tests.py @@ -1,4 +1,4 @@ -"""Tests for app_namespace""" +"""Tests for apptemplates""" import os import sys import shutil @@ -12,7 +12,7 @@ from django.template.loaders import app_directories from django.test.utils import override_settings -from app_namespace import Loader +from apptemplates import Loader class LoaderTestCase(TestCase): @@ -29,60 +29,60 @@ def build_engine(): except TypeError: return Engine() - app_namespace_loader = Loader(build_engine()) + apptemplates_loader = Loader(build_engine()) app_directory_loader = app_directories.Loader(build_engine()) template_directory = app_directory_loader.load_template( 'admin/base.html')[0] - template_namespace = app_namespace_loader.load_template( + template_namespace = apptemplates_loader.load_template( 'admin:admin/base.html')[0] context = Context({}) self.assertEquals(template_directory.render(context), template_namespace.render(context)) def test_load_template_source(self): - app_namespace_loader = Loader(Engine()) + apptemplates_loader = Loader(Engine()) app_directory_loader = app_directories.Loader(Engine()) template_directory = app_directory_loader.load_template_source( 'admin/base.html') - template_namespace = app_namespace_loader.load_template_source( + template_namespace = apptemplates_loader.load_template_source( 'admin:admin/base.html') self.assertEquals(template_directory[0], template_namespace[0]) - self.assertTrue('app_namespace:admin:' in template_namespace[1]) + self.assertTrue('apptemplates:admin:' in template_namespace[1]) self.assertTrue('admin/base.html' in template_namespace[1]) self.assertRaises(TemplateDoesNotExist, - app_namespace_loader.load_template_source, + apptemplates_loader.load_template_source, 'no-namespace-template') self.assertRaises(TemplateDoesNotExist, - app_namespace_loader.load_template_source, + apptemplates_loader.load_template_source, 'no.app.namespace:template') def test_load_template_source_empty_namespace(self): - app_namespace_loader = Loader(Engine()) + apptemplates_loader = Loader(Engine()) app_directory_loader = app_directories.Loader(Engine()) template_directory = app_directory_loader.load_template_source( 'admin/base.html') - template_namespace = app_namespace_loader.load_template_source( + template_namespace = apptemplates_loader.load_template_source( ':admin/base.html') self.assertEquals(template_directory[0], template_namespace[0]) - self.assertTrue('app_namespace:django.contrib.admin:' in + self.assertTrue('apptemplates:django.contrib.admin:' in template_namespace[1]) self.assertTrue('admin/base.html' in template_namespace[1]) self.assertRaises(TemplateDoesNotExist, - app_namespace_loader.load_template_source, + apptemplates_loader.load_template_source, ':template') def test_load_template_source_dotted_namespace(self): - app_namespace_loader = Loader(Engine()) + apptemplates_loader = Loader(Engine()) - template_short = app_namespace_loader.load_template_source( + template_short = apptemplates_loader.load_template_source( 'admin:admin/base.html') - template_dotted = app_namespace_loader.load_template_source( + template_dotted = apptemplates_loader.load_template_source( 'django.contrib.admin:admin/base.html') self.assertEquals(template_short[0], template_dotted[0]) @@ -93,7 +93,7 @@ def test_load_template_source_dotted_namespace(self): { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'OPTIONS': { - 'loaders': ('app_namespace.Loader', + 'loaders': ('apptemplates.Loader', 'django.template.loaders.app_directories.Loader') } } @@ -108,7 +108,7 @@ def test_extend_and_override(self): named admin/base_site.html on the filesystem overriding the title markup of the template. In this test we can view the advantage of using - the app_namespace template loader. + the apptemplates template loader. """ context = Context({}) mark = 'Django administration' @@ -191,7 +191,7 @@ def test_extend_with_super(self): 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'OPTIONS': { 'loaders': ( - 'app_namespace.Loader', + 'apptemplates.Loader', 'django.template.loaders.app_directories.Loader') } } @@ -287,7 +287,7 @@ def test_app_config_multiple_extend_empty_namespace(self): 'OPTIONS': { 'loaders': [ ('django.template.loaders.cached.Loader', [ - 'app_namespace.Loader', + 'apptemplates.Loader', 'django.template.loaders.app_directories.Loader']), ] } diff --git a/apptemplates/tests/tests.pyc b/apptemplates/tests/tests.pyc new file mode 100644 index 0000000..1cf793c Binary files /dev/null and b/apptemplates/tests/tests.pyc differ diff --git a/app_namespace/tests/urls.py b/apptemplates/tests/urls.py similarity index 83% rename from app_namespace/tests/urls.py rename to apptemplates/tests/urls.py index abbef4c..96a44ef 100644 --- a/app_namespace/tests/urls.py +++ b/apptemplates/tests/urls.py @@ -1,4 +1,4 @@ -"""Urls for testing app_namespace""" +"""Urls for testing apptemplates""" from django.conf.urls import url from django.conf.urls import include from django.contrib import admin diff --git a/apptemplates/tests/urls.pyc b/apptemplates/tests/urls.pyc new file mode 100644 index 0000000..c1533da Binary files /dev/null and b/apptemplates/tests/urls.pyc differ diff --git a/buildout.cfg b/buildout.cfg index 9a2e115..3e39e95 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -9,12 +9,12 @@ parts = demo develop = . eggs = six django - django-app-namespace-template-loader + django-apptemplates show-picked-versions = true [demo] recipe = djangorecipe -project = app_namespace.demo +project = apptemplates.demo settings = settings eggs = ${buildout:eggs} @@ -35,7 +35,7 @@ eggs = nose coverage ${buildout:eggs} defaults = --with-coverage - --cover-package=app_namespace + --cover-package=apptemplates --cover-erase --with-sfd environment = testenv @@ -55,4 +55,4 @@ scripts = check-buildout-updates=evolve arguments = '-w --sorting alpha' [testenv] -DJANGO_SETTINGS_MODULE = app_namespace.tests.settings +DJANGO_SETTINGS_MODULE = apptemplates.tests.settings diff --git a/setup.py b/setup.py index 577e42b..4e28a85 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,20 @@ -"""Setup script for django-app-namespace-template-loader""" +"""Setup script for django-apptemplates""" import os from setuptools import setup from setuptools import find_packages -__version__ = '0.4' +__version__ = '2.0' __license__ = 'BSD License' __author__ = 'Fantomas42' __email__ = 'fantomas42@gmail.com' -__url__ = 'https://github.com/Fantomas42/django-app-namespace-template-loader' +__url__ = 'https://github.com/Fantomas42/django-apptemplates' setup( - name='django-app-namespace-template-loader', + name='django-apptemplates', version=__version__, zip_safe=False,