Skip to content

Commit

Permalink
Merge pull request #28 from ojii/feature/new_django
Browse files Browse the repository at this point in the history
Drop Django <1.8, add Django 1.10, 1.11
  • Loading branch information
yakky committed Dec 23, 2018
2 parents 6201aac + 958c94f commit 73a541b
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 102 deletions.
27 changes: 3 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
language: python
sudo: false
python:
- 3.6
- 3.5
- 3.4
- 3.3
- 2.7
- 2.6
env:
matrix:
- DJANGO='django<1.7'
- DJANGO='django<1.8'
- DJANGO='django<1.9'
- DJANGO='django<1.10'
- DJANGO='django<1.11'
- DJANGO='django<2.0'
install:
- pip install $DJANGO coverage coveralls flake8 isort
before_script:
Expand All @@ -24,25 +23,5 @@ notifications:
- i.spalletti@nephila.it
on_success: never
on_failure: always
matrix:
exclude:
- python: 3.5
env: DJANGO='django<1.5'
- python: 3.5
env: DJANGO='django<1.7'
- python: 3.5
env: DJANGO='django<1.8'
- python: 3.4
env: DJANGO='django<1.5'
- python: 3.3
env: DJANGO='django<1.5'
- python: 3.3
env: DJANGO='django<1.10'
- python: 2.6
env: DJANGO='django<1.8'
- python: 2.6
env: DJANGO='django<1.9'
- python: 2.6
env: DJANGO='django<1.10'

fast_finish: true
4 changes: 2 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
3.0 (unreleased)
================

* Django 1.8, 1.9 support
* Drop support for Django < 1.6
* Django 1.8, 1.9, 1.10, 1.11 support
* Drop support for Django < 1.8
* Add language option to the command line

2.0.1 (2014-07-02)
Expand Down
15 changes: 9 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ whatsoever in it.
Note that this means that every time you change your error pages, you need to
re-run this script. Ideally this is part of your deploy process.

**Supported Django versions: 1.6, 1.7, 1.8, 1.9**
**Supported Django versions: 1.8, 1.9, 1.10, 1.11**

For older versions use ``django-statictemplate==2.0.1``

Expand Down Expand Up @@ -91,17 +91,20 @@ Arguments
=========

* ``template``: standard django template name to render
* ``language``: sets the client django_language cookie to render page in the
given language
* ``extra_request``: extra parameters injected in the request. Parameters must
be serialized in querystring format (e.g.: ``'variable=value&variable=value'``;
please note the single quote **'** to protect ampersand **&**).


=======
Options
=======

* ``-f``, ``--file``: file destionation for command output
* ``-l``, ``--language-code``: sets the client django_language cookie to render
page in the given language
* ``-f``, ``--file``: file destionation for command output
* ``-e``, ``--extra_request``: extra parameters injected in the request.
Parameters must be serialized in querystring format (e.g.:
``'variable=value&variable=value'``; please note the single quote **'** to
protect ampersand **&**).

*******
License
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
django>=1.6
django>=1.8,<2.0
flake8
coverage
isort
50 changes: 19 additions & 31 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-

import sys
from distutils.version import LooseVersion

urlpatterns = []
urlpatterns = [
]

DEFAULT_SETTINGS = dict(
INSTALLED_APPS=[
Expand All @@ -18,7 +18,7 @@
'ENGINE': 'django.db.backends.sqlite3'
}
},
LANGUAGES = (
LANGUAGES=(
('en-us', 'English'),
('it', 'Italian'),
),
Expand All @@ -40,34 +40,22 @@ def runtests():
import django
from django.conf import settings

if LooseVersion(django.get_version()) < LooseVersion('1.8'):
DEFAULT_SETTINGS['TEMPLATE_CONTEXT_PROCESSORS'] = [
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.debug',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
]
else:
DEFAULT_SETTINGS['TEMPLATES'] = [{
'NAME': 'django',
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
}
}]
DEFAULT_SETTINGS['TEMPLATES'] = [{
'NAME': 'django',
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
}
}]

# Compatibility with Django 1.7's stricter initialization
if not settings.configured:
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Framework :: Django',
'Framework :: Django :: 1.6',
'Framework :: Django :: 1.7',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development',
]

Expand Down
2 changes: 1 addition & 1 deletion statictemplate/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.1'
__version__ = '3.0.0.dev1'
28 changes: 14 additions & 14 deletions statictemplate/management/commands/statictemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@
from contextlib import contextmanager

from django.conf import settings
from django.conf.urls import include, url
from django.core.management.base import BaseCommand
from django.shortcuts import render
from django.test.client import Client
from django.utils.encoding import force_text
from django.utils.six.moves.urllib_parse import parse_qs
from django.utils.translation import get_language

try:
import urlparse
except ImportError: # NOQA
from urllib import parse as urlparse

try:
from django.conf.urls.defaults import url, include
except ImportError: # NOQA
from django.conf.urls import url, include

try:
from django.utils.encoding import force_text
except ImportError: # NOQA
from django.utils.encoding import force_unicode as force_text
from django.urls import clear_url_caches
except ImportError:
from django.core.urlresolvers import clear_url_caches


class InvalidResponseError(Exception):
Expand All @@ -33,6 +26,7 @@ def override_urlconf():
has_old = hasattr(settings, 'ROOT_URLCONF')
old = getattr(settings, 'ROOT_URLCONF', None)
settings.ROOT_URLCONF = 'statictemplate.management.commands.statictemplate'
clear_url_caches()
yield
if has_old:
setattr(settings, 'ROOT_URLCONF', old)
Expand Down Expand Up @@ -85,6 +79,10 @@ def add_arguments(self, parser):
action='store',
dest='output',
help='Output file'),
parser.add_argument('--extra_request', '-e',
action='store',
dest='extra_request',
help='Extra request parameters in urlencoded format')
parser.add_argument('--language-code', '-l',
action='store',
dest='language_code',
Expand All @@ -95,8 +93,10 @@ def handle(self, template, language=None, extra_request=None, **options):
request = {}
language_code = options.get('language_code', language)
language = language_code or language or get_language()
if not extra_request:
extra_request = options.get('extra_request', [])
if extra_request:
request.update(urlparse.parse_qs(extra_request, strict_parsing=True))
request.update(parse_qs(extra_request, strict_parsing=True))
output = make_static(template, language, request)
if options.get('output', False):
with codecs.open(options.get('output'), 'w', 'utf-8') as output_file:
Expand Down
5 changes: 3 additions & 2 deletions statictemplate/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from django.conf import settings

OVERRIDE_MIDDLEWARE = getattr(settings,
'STATICTEMPLATE_OVERRIDE_MIDDLEWARE', True)
OVERRIDE_MIDDLEWARE = getattr(
settings, 'STATICTEMPLATE_OVERRIDE_MIDDLEWARE', True
)
25 changes: 8 additions & 17 deletions statictemplate/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
from distutils.version import LooseVersion
from tempfile import mkstemp

import django
from django.conf import settings
from django.core.management import call_command
from django.http import HttpResponseRedirect
from django.template import TemplateDoesNotExist
from django.template.loaders.base import Loader
from django.test import SimpleTestCase
from django.utils.six import StringIO

from statictemplate.management.commands.statictemplate import (
InvalidResponseError, make_static,
Expand All @@ -15,17 +16,10 @@
from . import settings as statictemplate_settings

try:
from StringIO import StringIO
except:
from io import StringIO
try:
from django.template import TemplateDoesNotExist
except:
from django.template.base import TemplateDoesNotExist
try:
from django.template.loaders.base import Loader
from django.utils.deprecation import MiddlewareMixin
except ImportError:
from django.template.loader import BaseLoader as Loader
class MiddlewareMixin(object):
pass


class TestLoader(Loader):
Expand All @@ -44,18 +38,15 @@ def load_template_source(self, template_name, template_dirs=None):
return found, template_name


class MeddlingMiddleware(object):
class MeddlingMiddleware(MiddlewareMixin):
def process_request(self, request):
return HttpResponseRedirect('/foobarbaz')


class StaticTemplateTests(SimpleTestCase):
def setUp(self):
super(StaticTemplateTests, self).setUp()
if LooseVersion(django.get_version()) < LooseVersion('1.8'):
settings.TEMPLATE_LOADERS = ['statictemplate.tests.TestLoader']
else:
settings.TEMPLATES[0]['OPTIONS']['loaders'] = ['statictemplate.tests.TestLoader']
settings.TEMPLATES[0]['OPTIONS']['loaders'] = ['statictemplate.tests.TestLoader']

def test_python_api(self):
output = make_static('simple')
Expand Down

0 comments on commit 73a541b

Please sign in to comment.