Skip to content

Commit

Permalink
Merge 38fc7f7 into 6553065
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaoming committed May 16, 2016
2 parents 6553065 + 38fc7f7 commit f0a8f48
Show file tree
Hide file tree
Showing 35 changed files with 140 additions and 81 deletions.
6 changes: 3 additions & 3 deletions .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 =
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -4,6 +4,7 @@ python:
- 2.7
- 3.3
- 3.4
- 3.5
env:
- DJANGO=1.8
- DJANGO=1.9
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Expand Up @@ -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 *
120 changes: 89 additions & 31 deletions 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 <https://github.com/Fantomas42/django-apptemplates/issues/14>`_.


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
Expand All @@ -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 %}

Expand All @@ -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 %}
Expand All @@ -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 %}
Expand All @@ -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%}
<p>Application</p>
{% 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 }}
<p>Application extension</p>
{% 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 }}
<p>Application project</p>
{% endblock content%}

Will render: ::
Will render:

.. code-block:: html+django

<p>Application</p>
<p>Application extension</p>
Expand All @@ -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',
],
Expand All @@ -123,28 +163,46 @@ 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
-----

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.

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

1 change: 0 additions & 1 deletion app_namespace/demo/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion app_namespace/tests/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion app_namespace/__init__.py → 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__]
Binary file added apptemplates/__init__.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions apptemplates/demo/__init__.py
@@ -0,0 +1 @@
"""Demo of the apptemplates app"""
Binary file added apptemplates/demo/__init__.pyc
Binary file not shown.
File renamed without changes.
Binary file added apptemplates/demo/application/__init__.pyc
Binary file not shown.
Binary file added apptemplates/demo/application_appconfig/__init__.pyc
Binary file not shown.
Binary file added apptemplates/demo/application_extension/__init__.pyc
Binary file not shown.
12 changes: 6 additions & 6 deletions app_namespace/demo/settings.py → 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__))
Expand All @@ -9,7 +9,7 @@

SECRET_KEY = 'secret-key'

ROOT_URLCONF = 'app_namespace.demo.urls'
ROOT_URLCONF = 'apptemplates.demo.urls'

TEMPLATES = [
{
Expand All @@ -19,17 +19,17 @@
],
'OPTIONS': {
'debug': DEBUG,
'loaders': ('app_namespace.Loader',
'loaders': ('apptemplates.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader')
}
}
]

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']
2 changes: 1 addition & 1 deletion app_namespace/demo/urls.py → 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

Expand Down
4 changes: 2 additions & 2 deletions app_namespace/loader.py → apptemplates/loader.py
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
Binary file added apptemplates/loader.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions apptemplates/tests/__init__.py
@@ -0,0 +1 @@
"""Tests for apptemplates"""
Binary file added apptemplates/tests/__init__.pyc
Binary file not shown.
@@ -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'
Expand All @@ -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',
Expand Down
Binary file added apptemplates/tests/settings.pyc
Binary file not shown.

0 comments on commit f0a8f48

Please sign in to comment.