Commit f29f75bf authored by Michael Fladischer's avatar Michael Fladischer

Import django-classy-tags_0.7.1.orig.tar.gz

parent 3a6ff905
......@@ -17,7 +17,7 @@ sudo: false
install:
- pip install $DJANGO
script:
python runtests.py
- python runtests.py
matrix:
exclude:
- python: 2.6
......
__version__ = '0.7.0'
__version__ = '0.7.1'
from classytags.exceptions import InvalidFlag
from classytags.utils import TemplateConstant, NULL, mixin
from classytags.values import (StringValue, IntegerValue, ListValue, ChoiceValue,
DictValue, StrictStringValue)
from django import template
from django.core.exceptions import ImproperlyConfigured
from classytags.exceptions import InvalidFlag
from classytags.utils import NULL
from classytags.utils import TemplateConstant
from classytags.utils import mixin
from classytags.values import ChoiceValue
from classytags.values import DictValue
from classytags.values import IntegerValue
from classytags.values import ListValue
from classytags.values import StrictStringValue
from classytags.values import StringValue
class Argument(object):
"""
......
# -*- coding: utf-8 -*-
# flake8: noqa
try: # pragma: no cover
compat_basestring = basestring
......
from operator import attrgetter
from django.template import Node
from classytags.blocks import BlockDefinition
from classytags.compat import compat_basestring
from classytags.parser import Parser
from classytags.utils import StructuredOptions, get_default_name
from django.template import Node
from classytags.utils import StructuredOptions
from classytags.utils import get_default_name
class Options(object):
......@@ -55,7 +57,7 @@ class Options(object):
options = ','.join(bits)
if self.blocks:
blocks = ';%s' % ','.join(map(attrgetter('alias'), self.blocks))
else:
else: # pragma: no cover
blocks = ''
return '<Options:%s%s>' % (options, blocks)
......@@ -82,7 +84,12 @@ class Options(object):
"""
Bootstrap this options
"""
return StructuredOptions(self.options, self.breakpoints, self.blocks, self.combined_breakpoints)
return StructuredOptions(
self.options,
self.breakpoints,
self.blocks,
self.combined_breakpoints
)
def parse(self, parser, tokens):
"""
......@@ -119,6 +126,7 @@ class Tag(TagMeta('TagMeta', (Node,), {})):
Main Tag class.
"""
options = Options()
name = None
def __init__(self, parser, tokens):
self.kwargs, self.blocks = self.options.parse(parser, tokens)
......
......@@ -42,7 +42,10 @@ class BreakpointExpected(BaseError):
class TrailingBreakpoint(BaseError):
template = ("Tag %(tagname)s ends in trailing breakpoint '%(breakpoint)s' without an argument following.")
template = (
"Tag %(tagname)s ends in trailing breakpoint '%(breakpoint)s' without "
"an argument following."
)
def __init__(self, tagname, breakpoint):
self.tagname = tagname
......
from classytags.core import Tag
from classytags.utils import flatten_context
from django.core.exceptions import ImproperlyConfigured
from django.template.loader import render_to_string
from classytags.core import Tag
from classytags.utils import flatten_context
class AsTag(Tag):
"""
......@@ -83,7 +84,10 @@ class InclusionTag(Tag):
safe_context.update(**data)
output = render_to_string(template, safe_context)
else:
data = context.new(self.get_context(context, **kwargs))
new_context = context.new(
flatten_context(self.get_context(context, **kwargs))
)
data = flatten_context(new_context)
output = render_to_string(template, data)
return output
......
from classytags.exceptions import (BreakpointExpected, TooManyArguments,
ArgumentRequiredError, TrailingBreakpoint)
from copy import deepcopy
from django import template
from classytags.exceptions import ArgumentRequiredError
from classytags.exceptions import BreakpointExpected
from classytags.exceptions import TooManyArguments
from classytags.exceptions import TrailingBreakpoint
class Parser(object):
"""
......@@ -154,9 +158,6 @@ class Parser(object):
self.arguments = self.options.get_arguments()
# And check this breakpoints arguments for required arguments.
self.check_required()
#if self.current_argument is not None:
# self.arguments = [self.current_argument]
# self.check_required()
def parse_blocks(self):
"""
......
from django.conf import settings # pragma: no cover
try:
from django.test.simple import DjangoTestSuiteRunner # pragma: no cover
except:
from django.test.runner import DiscoverRunner
DjangoTestSuiteRunner = DiscoverRunner
try: # pragma: no cover
from xmlrunner import XMLTestRunner as runner
except: # pragma: no cover
runner = False
class TestSuiteRunner(DjangoTestSuiteRunner): # pragma: no cover
use_runner = runner
def run_suite(self, suite, **kwargs):
if self.use_runner and not self.failfast:
return self.use_runner(
output=getattr(settings, 'JUNIT_OUTPUT_DIR', '.')
).run(suite)
else:
return super(TestSuiteRunner, self).run_suite(suite, **kwargs)
def setup_databases(self, *args, **kwargs):
# no need for a database...
pass
teardown_databases = setup_databases
import sys # pragma: no cover
import os # pragma: no cover
def configure_settings(env_name): # pragma: no cover
from classytags.test import project
import classytags
PROJECT_DIR = os.path.abspath(os.path.dirname(project.__file__))
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates'),
)
dirname = os.path.dirname(classytags.__file__)
JUNIT_OUTPUT_DIR = os.path.join(
os.path.abspath(dirname), '..', 'junit-%s' % env_name
)
ADMINS = tuple()
DEBUG = False
gettext = lambda x: x
from django.conf import settings
settings.configure(
PROJECT_DIR=PROJECT_DIR,
DEBUG=DEBUG,
TEMPLATE_DEBUG=DEBUG,
ADMINS=ADMINS,
CACHE_BACKEND='locmem:///',
MANAGERS=ADMINS,
TIME_ZONE='America/Chicago',
SITE_ID=1,
USE_I18N=True,
MEDIA_ROOT=MEDIA_ROOT,
MEDIA_URL='/media/',
ADMIN_MEDIA_PREFIX='/media_admin/',
EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend',
SECRET_KEY='test-secret-key',
TEMPLATE_LOADERS=(
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
),
INTERNAL_IPS=('127.0.0.1',),
ROOT_URLCONF='classytags.test.project.urls',
TEMPLATE_DIRS=TEMPLATE_DIRS,
INSTALLED_APPS=(
'classytags',
'classytags.test.project',
),
gettext=lambda s: s,
LANGUAGE_CODE="en-us",
APPEND_SLASH=True,
TEST_RUNNER='classytags.test.project.testrunner.TestSuiteRunner',
JUNIT_OUTPUT_DIR=JUNIT_OUTPUT_DIR
)
return settings
def run_tests(*test_args): # pragma: no cover
test_args = list(test_args)
if '--direct' in test_args:
test_args.remove('--direct')
dirname = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(dirname, "..", ".."))
failfast = False
test_labels = []
test_args_enum = dict([(val, idx) for idx, val in enumerate(test_args)])
env_name = ''
if '--env-name' in test_args:
env_name = test_args[test_args_enum['--env-name'] + 1]
test_args.remove('--env-name')
test_args.remove(env_name)
if '--failfast' in test_args:
test_args.remove('--failfast')
failfast = True
for label in test_args:
test_labels.append('classytags.%s' % label)
if not test_labels:
test_labels.append('classytags')
settings = configure_settings(env_name)
from django.test.utils import get_runner
runner_class = get_runner(settings)
runner = runner_class(verbosity=1, interactive=True, failfast=failfast)
failures = runner.run_tests(test_labels)
sys.exit(failures)
if __name__ == '__main__': # pragma: no cover
run_tests(*sys.argv[1:])
from __future__ import with_statement
import operator
import os
import sys
import warnings
from distutils.version import LooseVersion
from classytags import (arguments, core, exceptions, utils, parser, helpers,
values)
from classytags.blocks import BlockDefinition, VariableBlockName
from classytags.compat import compat_next
from classytags.test.context_managers import SettingsOverride, TemplateTags
from unittest import TestCase
import django
from django import template
from django.core.exceptions import ImproperlyConfigured
from unittest import TestCase
import sys
import warnings
from classytags import arguments
from classytags import core
from classytags import exceptions
from classytags import helpers
from classytags import parser
from classytags import utils
from classytags import values
from classytags.blocks import BlockDefinition
from classytags.blocks import VariableBlockName
from classytags.compat import compat_next
from classytags.test.context_managers import SettingsOverride
from classytags.test.context_managers import TemplateTags
from django.template import Context
DJANGO_1_4_OR_HIGHER = (
LooseVersion(django.get_version()) >= LooseVersion('1.4')
)
DJANGO_1_5_OR_HIGHER = (
LooseVersion(django.get_version()) >= LooseVersion('1.5')
)
CLASSY_TAGS_DIR = os.path.abspath(os.path.dirname(__file__))
class DummyTokens(list):
......@@ -53,11 +69,11 @@ def _collect_warnings(observe_warning, f, *args, **kwargs):
# Disable the per-module cache for every module otherwise if the warning
# which the caller is expecting us to collect was already emitted it won't
# be re-emitted by the call to f which happens below.
for v in sys.modules.values():
for v in sys.modules.values(): # pragma: no cover
if v is not None:
try:
v.__warningregistry__ = None
except: # pragma: no cover
except:
# Don't specify a particular exception type to handle in case
# some wacky object raises some wacky exception in response to
# the setattr attempt.
......@@ -756,7 +772,7 @@ class ClassytagsTests(TestCase):
# test warning
context = template.Context({'i': 'one'})
message = values.IntegerValue.errors['clean'] % {
'value': repr('one')
'value': repr('one')
}
self.assertWarns(exceptions.TemplateSyntaxWarning,
message, tpl.render, context)
......@@ -1135,14 +1151,14 @@ class ClassytagsTests(TestCase):
arguments.StringArgument('string', resolve=False),
)
with SettingsOverride(DEBUG=False):
#test ok
# test ok
dummy_tokens = DummyTokens('string')
kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
dummy_context = {}
self.assertEqual(
kwargs['string'].resolve(dummy_context), 'string'
)
#test warning
# test warning
dummy_tokens = DummyTokens(1)
kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
dummy_context = {}
......@@ -1351,3 +1367,27 @@ class MultiBreakpointTests(TestCase):
def test_add_options_to_something_else(self):
options = core.Options()
self.assertRaises(TypeError, operator.add, options, 1)
def test_flatten_context(self):
context = Context({'foo': 'bar'})
context.push()
context.update({'bar': 'baz'})
context.push()
context.update({'foo': 'test'})
flat = utils.flatten_context(context)
expected = {
'foo': 'test',
'bar': 'baz',
}
if DJANGO_1_5_OR_HIGHER:
expected.update({
'None': None,
'True': True,
'False': False,
})
self.assertEqual(flat, expected)
context.flatten = None
flat = utils.flatten_context(context)
self.assertEqual(flat, expected)
flat = utils.flatten_context({'foo': 'test', 'bar': 'baz'})
self.assertEqual(flat, {'foo': 'test', 'bar': 'baz'})
import re
from copy import copy
from classytags.compat import compat_basestring
import re
from django.template.context import BaseContext
class NULL:
......@@ -37,7 +39,9 @@ class StructuredOptions(object):
self.breakpoints = copy(breakpoints)
self.blocks = copy(blocks)
self.combined_breakpoints = dict(combind_breakpoints.items())
self.reversed_combined_breakpoints = dict((v,k) for k,v in combind_breakpoints.items())
self.reversed_combined_breakpoints = dict(
(v, k) for k, v in combind_breakpoints.items()
)
self.current_breakpoint = None
if self.breakpoints:
self.next_breakpoint = self.breakpoints.pop(0)
......@@ -72,7 +76,8 @@ def get_default_name(name):
return _re2.sub(r'\1_\2', _re1.sub(r'\1_\2', name)).lower()
def mixin(parent, child, attrs={}):
def mixin(parent, child, attrs=None):
attrs = attrs or {}
return type(
'%sx%s' % (parent.__name__, child.__name__),
(child, parent),
......@@ -83,8 +88,9 @@ def mixin(parent, child, attrs={}):
def flatten_context(context):
if callable(getattr(context, 'flatten', None)):
return context.flatten()
else:
elif isinstance(context, BaseContext):
flat = {}
for d in context.dicts:
flat.update(d)
return flat
return context
from classytags.compat import compat_basestring
from classytags.exceptions import TemplateSyntaxWarning
import warnings
from django import template
from django.conf import settings
import warnings
from classytags.compat import compat_basestring
from classytags.exceptions import TemplateSyntaxWarning
class StringValue(object):
......@@ -11,9 +13,11 @@ class StringValue(object):
def __init__(self, var):
self.var = var
if hasattr(self.var, 'literal'): # django.template.base.Variable
try:
# django.template.base.Variable
self.literal = self.var.literal
else: # django.template.base.FilterExpression
except AttributeError:
# django.template.base.FilterExpression
self.literal = self.var.token
def resolve(self, context):
......@@ -86,7 +90,7 @@ class DictValue(dict, StringValue):
return self.clean(resolved)
class ChoiceValue(object):
class ChoiceValue(StringValue):
errors = {
"choice": "%(value)s is not a valid choice. Valid choices: "
"%(choices)s.",
......
......@@ -3,6 +3,14 @@ Changelog
#########
*****
0.7.1
*****
* Prepare support for Django 1.10. Please note that Django 1.10 is **not**
supported by this release, as Django 1.10 is not released yet.
*****
0.7.0
*****
......
[bdist_wheel]
universal=1
[flake8]
ignore = W293
......@@ -7,7 +7,7 @@ setup(
version = version,
description = 'Class based template tags for Django',
author = 'Jonas Obrist',
author_email = 'jonas.obrist@divio.ch',
author_email = 'ojiidotch@gmail.com',
url = 'http://github.com/ojii/django-classy-tags',
packages = find_packages(),
zip_safe=False,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment