Commit 7b66fa0a authored by Michael Fladischer's avatar Michael Fladischer

merge patched into master

parents 0eee1dcf ffe9f417
...@@ -17,7 +17,7 @@ sudo: false ...@@ -17,7 +17,7 @@ sudo: false
install: install:
- pip install $DJANGO - pip install $DJANGO
script: script:
python runtests.py - python runtests.py
matrix: matrix:
exclude: exclude:
- python: 2.6 - 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 import template
from django.core.exceptions import ImproperlyConfigured 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): class Argument(object):
""" """
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# flake8: noqa
try: # pragma: no cover try: # pragma: no cover
compat_basestring = basestring compat_basestring = basestring
......
from operator import attrgetter from operator import attrgetter
from django.template import Node
from classytags.blocks import BlockDefinition from classytags.blocks import BlockDefinition
from classytags.compat import compat_basestring from classytags.compat import compat_basestring
from classytags.parser import Parser from classytags.parser import Parser
from classytags.utils import StructuredOptions, get_default_name from classytags.utils import StructuredOptions
from django.template import Node from classytags.utils import get_default_name
class Options(object): class Options(object):
...@@ -55,7 +57,7 @@ class Options(object): ...@@ -55,7 +57,7 @@ class Options(object):
options = ','.join(bits) options = ','.join(bits)
if self.blocks: if self.blocks:
blocks = ';%s' % ','.join(map(attrgetter('alias'), self.blocks)) blocks = ';%s' % ','.join(map(attrgetter('alias'), self.blocks))
else: else: # pragma: no cover
blocks = '' blocks = ''
return '<Options:%s%s>' % (options, blocks) return '<Options:%s%s>' % (options, blocks)
...@@ -82,7 +84,12 @@ class Options(object): ...@@ -82,7 +84,12 @@ class Options(object):
""" """
Bootstrap this options 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): def parse(self, parser, tokens):
""" """
...@@ -119,6 +126,7 @@ class Tag(TagMeta('TagMeta', (Node,), {})): ...@@ -119,6 +126,7 @@ class Tag(TagMeta('TagMeta', (Node,), {})):
Main Tag class. Main Tag class.
""" """
options = Options() options = Options()
name = None
def __init__(self, parser, tokens): def __init__(self, parser, tokens):
self.kwargs, self.blocks = self.options.parse(parser, tokens) self.kwargs, self.blocks = self.options.parse(parser, tokens)
......
...@@ -42,7 +42,10 @@ class BreakpointExpected(BaseError): ...@@ -42,7 +42,10 @@ class BreakpointExpected(BaseError):
class TrailingBreakpoint(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): def __init__(self, tagname, breakpoint):
self.tagname = tagname self.tagname = tagname
......
from classytags.core import Tag
from classytags.utils import flatten_context
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.template.loader import render_to_string from django.template.loader import render_to_string
from classytags.core import Tag
from classytags.utils import flatten_context
class AsTag(Tag): class AsTag(Tag):
""" """
...@@ -83,7 +84,10 @@ class InclusionTag(Tag): ...@@ -83,7 +84,10 @@ class InclusionTag(Tag):
safe_context.update(**data) safe_context.update(**data)
output = render_to_string(template, safe_context) output = render_to_string(template, safe_context)
else: 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) output = render_to_string(template, data)
return output return output
......
from classytags.exceptions import (BreakpointExpected, TooManyArguments,
ArgumentRequiredError, TrailingBreakpoint)
from copy import deepcopy from copy import deepcopy
from django import template 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): class Parser(object):
""" """
...@@ -154,9 +158,6 @@ class Parser(object): ...@@ -154,9 +158,6 @@ class Parser(object):
self.arguments = self.options.get_arguments() self.arguments = self.options.get_arguments()
# And check this breakpoints arguments for required arguments. # And check this breakpoints arguments for required arguments.
self.check_required() self.check_required()
#if self.current_argument is not None:
# self.arguments = [self.current_argument]
# self.check_required()
def parse_blocks(self): 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 from __future__ import with_statement
import operator import operator
import os
import sys
import warnings
from distutils.version import LooseVersion from distutils.version import LooseVersion
from classytags import (arguments, core, exceptions, utils, parser, helpers, from unittest import TestCase
values)
from classytags.blocks import BlockDefinition, VariableBlockName
from classytags.compat import compat_next
from classytags.test.context_managers import SettingsOverride, TemplateTags
import django import django
from django import template from django import template
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from unittest import TestCase
import sys from classytags import arguments
import warnings 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 = ( DJANGO_1_4_OR_HIGHER = (
LooseVersion(django.get_version()) >= LooseVersion('1.4') 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): class DummyTokens(list):
...@@ -53,11 +69,11 @@ def _collect_warnings(observe_warning, f, *args, **kwargs): ...@@ -53,11 +69,11 @@ def _collect_warnings(observe_warning, f, *args, **kwargs):
# Disable the per-module cache for every module otherwise if the warning # 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 # 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. # 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: if v is not None:
try: try:
v.__warningregistry__ = None v.__warningregistry__ = None
except: # pragma: no cover except:
# Don't specify a particular exception type to handle in case # Don't specify a particular exception type to handle in case
# some wacky object raises some wacky exception in response to # some wacky object raises some wacky exception in response to
# the setattr attempt. # the setattr attempt.
...@@ -756,7 +772,7 @@ class ClassytagsTests(TestCase): ...@@ -756,7 +772,7 @@ class ClassytagsTests(TestCase):
# test warning # test warning
context = template.Context({'i': 'one'}) context = template.Context({'i': 'one'})
message = values.IntegerValue.errors['clean'] % { message = values.IntegerValue.errors['clean'] % {
'value': repr('one') 'value': repr('one')
} }
self.assertWarns(exceptions.TemplateSyntaxWarning, self.assertWarns(exceptions.TemplateSyntaxWarning,
message, tpl.render, context) message, tpl.render, context)
...@@ -1135,14 +1151,14 @@ class ClassytagsTests(TestCase): ...@@ -1135,14 +1151,14 @@ class ClassytagsTests(TestCase):
arguments.StringArgument('string', resolve=False), arguments.StringArgument('string', resolve=False),
) )
with SettingsOverride(DEBUG=False): with SettingsOverride(DEBUG=False):
#test ok # test ok
dummy_tokens = DummyTokens('string') dummy_tokens = DummyTokens('string')
kwargs, blocks = options.parse(dummy_parser, dummy_tokens) kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
dummy_context = {} dummy_context = {}
self.assertEqual( self.assertEqual(
kwargs['string'].resolve(dummy_context), 'string' kwargs['string'].resolve(dummy_context), 'string'
) )
#test warning # test warning
dummy_tokens = DummyTokens(1) dummy_tokens = DummyTokens(1)
kwargs, blocks = options.parse(dummy_parser, dummy_tokens) kwargs, blocks = options.parse(dummy_parser, dummy_tokens)
dummy_context = {} dummy_context = {}
...@@ -1351,3 +1367,27 @@ class MultiBreakpointTests(TestCase): ...@@ -1351,3 +1367,27 @@ class MultiBreakpointTests(TestCase):
def test_add_options_to_something_else(self): def test_add_options_to_something_else(self):
options = core.Options() options = core.Options()
self.assertRaises(TypeError, operator.add, options, 1) 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 copy import copy
from classytags.compat import compat_basestring from classytags.compat import compat_basestring
import re from django.template.context import BaseContext
class NULL: class NULL:
...@@ -37,7 +39,9 @@ class StructuredOptions(object): ...@@ -37,7 +39,9 @@ class StructuredOptions(object):
self.breakpoints = copy(breakpoints) self.breakpoints = copy(breakpoints)
self.blocks = copy(blocks) self.blocks = copy(blocks)
self.combined_breakpoints = dict(combind_breakpoints.items()) 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 self.current_breakpoint = None
if self.breakpoints: if self.breakpoints:
self.next_breakpoint = self.breakpoints.pop(0) self.next_breakpoint = self.breakpoints.pop(0)
...@@ -72,7 +76,8 @@ def get_default_name(name): ...@@ -72,7 +76,8 @@ def get_default_name(name):
return _re2.sub(r'\1_\2', _re1.sub(r'\1_\2', name)).lower() 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( return type(
'%sx%s' % (parent.__name__, child.__name__), '%sx%s' % (parent.__name__, child.__name__),
(child, parent), (child, parent),
...@@ -83,8 +88,9 @@ def mixin(parent, child, attrs={}): ...@@ -83,8 +88,9 @@ def mixin(parent, child, attrs={}):
def flatten_context(context): def flatten_context(context):
if callable(getattr(context, 'flatten', None)): if callable(getattr(context, 'flatten', None)):
return context.flatten() return context.flatten()
else: elif isinstance(context, BaseContext):
flat = {} flat = {}
for d in context.dicts: for d in context.dicts:
flat.update(d) flat.update(d)
return flat return flat
return context
from classytags.compat import compat_basestring import warnings
from classytags.exceptions import TemplateSyntaxWarning
from django import template from django import template
from django.conf import settings from django.conf import settings
import warnings
from classytags.compat import compat_basestring
from classytags.exceptions import TemplateSyntaxWarning
class StringValue(object): class StringValue(object):
...@@ -11,9 +13,11 @@ class StringValue(object): ...@@ -11,9 +13,11 @@ class StringValue(object):
def __init__(self, var): def __init__(self, var):
self.var = var self.var = var
if hasattr(self.var, 'literal'): # django.template.base.Variable try:
# django.template.base.Variable
self.literal = self.var.literal self.literal = self.var.literal
else: # django.template.base.FilterExpression except AttributeError:
# django.template.base.FilterExpression
self.literal = self.var.token self.literal = self.var.token
def resolve(self, context): def resolve(self, context):
...@@ -86,7 +90,7 @@ class DictValue(dict, StringValue): ...@@ -86,7 +90,7 @@ class DictValue(dict, StringValue):
return self.clean(resolved) return self.clean(resolved)
class ChoiceValue(object): class ChoiceValue(StringValue):
errors = { errors = {
"choice": "%(value)s is not a valid choice. Valid choices: " "choice": "%(value)s is not a valid choice. Valid choices: "
"%(choices)s.", "%(choices)s.",
......
# see git-dpm(1) from git-dpm package # see git-dpm(1) from git-dpm package
f753bec2281dfd05cb7be9c300b57ce1917cd449 ffe9f417414e95095444f3061ac51caf19fd6df7
f753bec2281dfd05cb7be9c300b57ce1917cd449 ffe9f417414e95095444f3061ac51caf19fd6df7
3a6ff905c7958f804d9925b02a04b3eb40cd93a6 f29f75bfba4f22635a67acbea2e5ebe669c26e19
f29f75bfba4f22635a67acbea2e5ebe669c26e19 f29f75bfba4f22635a67acbea2e5ebe669c26e19
django-classy-tags_0.7.1.orig.tar.gz django-classy-tags_0.7.1.orig.tar.gz
10ef8d14d70cfce9d0f05f15659d3112f4fdda78 10ef8d14d70cfce9d0f05f15659d3112f4fdda78
......
From f753bec2281dfd05cb7be9c300b57ce1917cd449 Mon Sep 17 00:00:00 2001 From ffe9f417414e95095444f3061ac51caf19fd6df7 Mon Sep 17 00:00:00 2001
From: Michael Fladischer <fladi@debian.org> From: Michael Fladischer <fladi@debian.org>
Date: Thu, 8 Oct 2015 08:50:54 -0700 Date: Thu, 8 Oct 2015 08:50:54 -0700
Subject: Disable objects.inv download for sphinx. Subject: Disable objects.inv download for sphinx.
......
...@@ -3,6 +3,14 @@ Changelog ...@@ -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 0.7.0
***** *****
......
[bdist_wheel] [bdist_wheel]
universal=1 universal=1
[flake8]
ignore = W293
...@@ -7,7 +7,7 @@ setup( ...@@ -7,7 +7,7 @@ setup(
version = version, version = version,
description = 'Class based template tags for Django', description = 'Class based template tags for Django',
author = 'Jonas Obrist', author = 'Jonas Obrist',
author_email = 'jonas.obrist@divio.ch', author_email = 'ojiidotch@gmail.com',
url = 'http://github.com/ojii/django-classy-tags', url = 'http://github.com/ojii/django-classy-tags',
packages = find_packages(), packages = find_packages(),
zip_safe=False, 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