Ticket #7158: patch.diff

File patch.diff, 7.8 KB (added by alainD, 16 years ago)

patch against rev. 7512

  • django/test/simple.py

     
    7373                pass
    7474    return suite
    7575
     76def _get_all_tests_from_suite(suite):
     77    """Explore suite recursively to get _all_ tests in it
     78    """
     79    if isinstance(suite,unittest.TestCase):
     80        return [suite]
     81    else:
     82        all_tests = []
     83        [all_tests.extend(_get_all_tests_from_suite(sub_suite)) for sub_suite in getattr(suite,'_tests',[])]
     84        return all_tests
     85   
    7686def build_test(label):
    7787    """Construct a test case a test with the specified label. Label should
    7888    be of the form model.TestClass or model.TestClass.test_method. Returns
     
    92102        if test_module:
    93103            TestClass = getattr(test_module, parts[1], None)
    94104
     105    # Couldn't find the test class; look in test suite
     106    if TestClass is None:
     107        suite = build_suite(app_module)
     108        all_tests = _get_all_tests_from_suite(suite)
     109        for test_in_suite in all_tests:
     110            if test_in_suite.__class__.__name__ == parts[1]:
     111                TestClass = test_in_suite.__class__
     112                break
     113
    95114    if len(parts) == 2: # label is app.TestClass
    96115        try:
    97116            return unittest.TestLoader().loadTestsFromTestCase(TestClass)
  • django/core/management/commands/syncdb.py

     
    3434            try:
    3535                __import__(app_name + '.management', {}, {}, [''])
    3636            except ImportError, exc:
    37                 if not exc.args[0].startswith('No module named management'):
    38                     raise
     37                # RBA : strange uno error : we need to be more permissive with errors
     38                #if not exc.args[0].startswith('No module named management'):
     39                #    raise
     40                pass
    3941
    4042        cursor = connection.cursor()
    4143
  • django/core/management/__init__.py

     
    249249    settings_name = os.path.splitext(settings_filename)[0]
    250250    sys.path.append(os.path.join(project_directory, os.pardir))
    251251    project_module = __import__(project_name, {}, {}, [''])
    252     sys.path.pop()
     252    #sys.path.pop()
    253253
    254254    # Set DJANGO_SETTINGS_MODULE appropriately.
    255255    os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
  • django/templatetags/i18n.py

     
    11import re
    22
    33from django.template import Node, Variable, VariableNode
    4 from django.template import TemplateSyntaxError, TokenParser, Library
    5 from django.template import TOKEN_TEXT, TOKEN_VAR
     4from django.template import TemplateSyntaxError, TokenParser, Library, Token
     5from django.template import TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
    66from django.utils import translation
    77from django.utils.encoding import force_unicode
    88
     
    235235        token = parser.next_token()
    236236        if token.token_type in (TOKEN_VAR, TOKEN_TEXT):
    237237            singular.append(token)
     238        elif token.token_type == TOKEN_BLOCK and token.contents.strip().startswith('as '):
     239            cont = token.split_contents()
     240            if len(cont) != 2:
     241                raise TemplateSyntaxError, "Error in 'as' block inside blocktrans"
     242            as_tag,name = token.split_contents()
     243            t_block = parser.parse(('endas',))
     244            singular.append(token)
     245            parser.delete_first_token()
     246            extra_context[name] = t_block
     247            singular.append(Token(TOKEN_VAR,name))
    238248        else:
    239249            break
    240250    if countervar and counter:
    241251        if token.contents.strip() != 'plural':
    242             raise TemplateSyntaxError, "'blocktrans' doesn't allow other block tags inside it"
     252            raise TemplateSyntaxError, "'blocktrans' can only include 'as' block tags"
    243253        while parser.tokens:
    244254            token = parser.next_token()
    245255            if token.token_type in (TOKEN_VAR, TOKEN_TEXT):
    246256                plural.append(token)
     257            elif token.token_type == TOKEN_BLOCK and token.contents.strip().startswith('as '):
     258                cont = token.split_contents()
     259                if len(cont) != 2:
     260                    raise TemplateSyntaxError, "Error in 'as' block inside blocktrans"
     261                as_tag,name = cont
     262                t_block = parser.parse(('endas',))
     263                plural.append(token)
     264                parser.delete_first_token()
     265                extra_context[name] = t_block
     266                plural.append(Token(TOKEN_VAR,name))
    247267            else:
    248268                break
    249269    if token.contents.strip() != 'endblocktrans':
    250         raise TemplateSyntaxError, "'blocktrans' doesn't allow other block tags (seen %r) inside it" % token.contents
     270        raise TemplateSyntaxError, "'blocktrans' can only include 'as' block tags (seen %r) inside it" % token.contents
    251271
    252272    return BlockTranslateNode(extra_context, singular, plural, countervar,
    253273            counter)
  • django/utils/translation/trans_real.py

     
    452452    inplural = False
    453453    singular = []
    454454    plural = []
     455    inas = False
    455456    for t in Lexer(src, None).tokenize():
    456457        if intrans:
    457458            if t.token_type == TOKEN_BLOCK:
    458459                endbmatch = endblock_re.match(t.contents)
    459                 pluralmatch = plural_re.match(t.contents)
     460                pluralmatch = plural_re.match(t.contents)               
    460461                if endbmatch:
    461462                    if inplural:
    462463                        out.write(' ngettext(%r,%r,count) ' % (''.join(singular), ''.join(plural)))
     
    475476                elif pluralmatch:
    476477                    inplural = True
    477478                else:
    478                     raise SyntaxError("Translation blocks must not include other block tags: %s" % t.contents)
     479                    if t.contents.startswith('as '):
     480                        cont = t.split_contents()
     481                        if len(cont) != 2:
     482                            raise TemplateSyntaxError, "Error in 'as' block inside blocktrans"
     483                        as_tag,name = cont
     484                        inas = True
     485                        if inplural:
     486                            plural.append('%%(%s)s' % name)
     487                        else:
     488                            singular.append('%%(%s)s' % name)
     489                    elif t.contents == "endas":
     490                        inas = False
     491                    else:
     492                        raise SyntaxError("Translation blocks can only include 'as' block tags: %s" % t.contents)
    479493            elif t.token_type == TOKEN_VAR:
    480494                if inplural:
    481495                    plural.append('%%(%s)s' % t.contents)
    482496                else:
    483497                    singular.append('%%(%s)s' % t.contents)
    484498            elif t.token_type == TOKEN_TEXT:
    485                 if inplural:
    486                     plural.append(t.contents)
    487                 else:
    488                     singular.append(t.contents)
     499                if not inas:
     500                    if inplural:
     501                        plural.append(t.contents)
     502                    else:
     503                        singular.append(t.contents)
    489504        else:
    490505            if t.token_type == TOKEN_BLOCK:
    491506                imatch = inline_re.match(t.contents)
Back to Top