Skip to content

Commit

Permalink
Merge cbebd68 into ffbc60d
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Jan 24, 2016
2 parents ffbc60d + cbebd68 commit 615e5fb
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 45 deletions.
35 changes: 35 additions & 0 deletions .editorconfig
@@ -0,0 +1,35 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80

[*.md]
trim_trailing_whitespace = false

[*.rst]
max_line_length = 80

[*.py]
max_line_length = 100

[*.{scss,html}]
indent_size = 4
indent_style = space
max_line_length = 120

[*.js]
indent_size = 2
max_line_length = 120

[*.yml]
indent_size = 2

[Makefile]
indent_style = tab
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@
coverage_html
*.egg-info
*.py[co]
build
dist
10 changes: 6 additions & 4 deletions Makefile
Expand Up @@ -13,6 +13,7 @@ help:
clean: clean-build clean-pyc

clean-build:
python setup.py clean --all
rm -fr build/
rm -fr dist/
rm -fr *.egg-info
Expand All @@ -24,18 +25,19 @@ clean-pyc:

lint:
flake8 statictemplate
isort -rc -c -df statictemplate

test:
python runtests.py

coverage:
coverage run runtests.py
coverage erase
coverage run setup.py test
coverage report -m
coverage html

release: clean
python setup.py sdist upload
python setup.py bdist_wheel upload
python setup.py sdist bdist_wheel
twine upload dist/*

sdist: clean
python setup.py sdist
Expand Down
8 changes: 4 additions & 4 deletions runtests.py
@@ -1,5 +1,5 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/env python

import sys
from distutils.version import LooseVersion
Expand Down Expand Up @@ -52,7 +52,7 @@ def runtests():
'NAME': 'django',
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'context_processors': [
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.debug',
Expand All @@ -61,7 +61,7 @@ def runtests():
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
],
}
}]

Expand All @@ -74,7 +74,7 @@ def runtests():
from django.test.runner import DiscoverRunner
test_args = ['statictemplate']
failures = DiscoverRunner(
verbosity=1, interactive=True, failfast=False
verbosity=1, interactive=True, failfast=False
).run_tests(test_args)
sys.exit(failures)

Expand Down
17 changes: 14 additions & 3 deletions setup.cfg
@@ -1,6 +1,17 @@
[flake8]
max-line-length = 99

[metadata]
license-file = LICENSE

[wheel]
universal = 1

[flake8]
ignore = E128
exclude = statictemplate/tests.py
[isort]
line_length = 79
combine_as_imports = true
default_section = THIRDPARTY
include_trailing_comma = true
known_first_party = statictemplate
multi_line_output = 5
not_skip = __init__.py
6 changes: 4 additions & 2 deletions setup.py
Expand Up @@ -32,9 +32,11 @@
setup(
name='django-statictemplate',
version=__version__,
description=('This project aims at providing a compromise between dynamic '
description=(
'This project aims at providing a compromise between dynamic '
'error pages for Django (that use template tags etc and therefore '
'potentially error too) and having to write static error pages by hand.'),
'potentially error too) and having to write static error pages by hand.'
),
author='Jonas Obrist',
author_email='ojiidotch@gmail.com',
url='https://github.com/ojii/django-statictemplate',
Expand Down
42 changes: 22 additions & 20 deletions statictemplate/management/commands/statictemplate.py
@@ -1,25 +1,27 @@
# -*- coding: utf-8 -*-
from contextlib import contextmanager
import codecs
from optparse import make_option
from contextlib import contextmanager

from django.conf import settings
from django.core.management.base import BaseCommand
from django.shortcuts import render
from django.test.client import Client
from django.utils.translation import get_language

try:
import urlparse
except ImportError: # NOQA
from urllib import parse as urlparse
from django.conf import settings

try:
from django.conf.urls.defaults import patterns, url, include
from django.conf.urls.defaults import url, include
except ImportError: # NOQA
from django.conf.urls import patterns, url, include
from django.core.management.base import BaseCommand
from django.shortcuts import render_to_response, render
from django.template.context import RequestContext
from django.test.client import Client
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.utils.translation import get_language


class InvalidResponseError(Exception):
Expand Down Expand Up @@ -77,16 +79,16 @@ def make_static(template, language=None, request=None):


class Command(BaseCommand):
def add_arguments(self,parser):
parser.add_argument('--file','-f',
action='store',
dest='output',
help='Output file'),
parser.add_argument('--language-code','-l',
action='store',
dest='language_code',
help='Language Code')
parser.add_argument('template', nargs='+', type=str)
def add_arguments(self, parser):
parser.add_argument('--file', '-f',
action='store',
dest='output',
help='Output file'),
parser.add_argument('--language-code', '-l',
action='store',
dest='language_code',
help='Language Code')
parser.add_argument('template', nargs='+', type=str)

def handle(self, template, language=None, extra_request=None, **options):
request = {}
Expand Down
27 changes: 15 additions & 12 deletions statictemplate/tests.py
@@ -1,15 +1,23 @@
# -*- 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.test import SimpleTestCase

from statictemplate.management.commands.statictemplate import (
InvalidResponseError, make_static,
)

from . import settings as statictemplate_settings

try:
from StringIO import StringIO
except:
from io import StringIO
from django.conf import settings
from django.http import HttpResponseRedirect
from django.core.management import call_command
try:
from django.template import TemplateDoesNotExist
except:
Expand All @@ -18,18 +26,13 @@
from django.template.loaders.base import Loader
except ImportError:
from django.template.loader import BaseLoader as Loader
from django.test import SimpleTestCase
from tempfile import mkstemp
from statictemplate.management.commands.statictemplate import make_static, \
InvalidResponseError

from . import settings as statictemplate_settings


class TestLoader(Loader):
is_usable = True
templates = {
'request': '{% extends "base" %}{% block content %}request {{ request.GET.extra }}{% endblock %}',
'request': '{% extends "base" %}{% block content %}request '
'{{ request.GET.extra }}{% endblock %}',
'simple': '{% extends "base" %}{% block content %}simple{% endblock %}',
'base': '{% block head %}head{% endblock %}{% block content %}content{% endblock %}',
}
Expand Down Expand Up @@ -92,5 +95,5 @@ def test_no_ovveride_middleware(self):
settings.MIDDLEWARE_CLASSES = middleware
statictemplate_settings.OVERRIDE_MIDDLEWARE = False
with self.assertRaises(InvalidResponseError):
output = make_static('simple')
statictemplate_settings.OVERRIDE_MIDDLEWARE = True
make_static('simple')
statictemplate_settings.OVERRIDE_MIDDLEWARE = True

0 comments on commit 615e5fb

Please sign in to comment.