Django

Code

Changeset 5399

Show
Ignore:
Timestamp:
06/01/07 01:19:01 (1 year ago)
Author:
mtredinnick
Message:

unicode: Merged from trunk up to [5398].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode

    • Property svnmerge-integrated changed from /django/trunk:1-5380 to /django/trunk:1-5398
  • django/branches/unicode/django/db/models/query.py

    r5203 r5399  
    556556    def __init__(self, *args, **kwargs): 
    557557        super(ValuesQuerySet, self).__init__(*args, **kwargs) 
    558         # select_related and select aren't supported in values(). 
     558        # select_related isn't supported in values(). 
    559559        self._select_related = False 
    560         self._select = {} 
    561560 
    562561    def iterator(self): 
     
    568567        # self._fields is a list of field names to fetch. 
    569568        if self._fields: 
    570             columns = [self.model._meta.get_field(f, many_to_many=False).column for f in self._fields] 
     569            #columns = [self.model._meta.get_field(f, many_to_many=False).column for f in self._fields] 
     570            if not self._select: 
     571                columns = [self.model._meta.get_field(f, many_to_many=False).column for f in self._fields] 
     572            else: 
     573                columns = [] 
     574                for f in self._fields: 
     575                    if f in [field.name for field in self.model._meta.fields]: 
     576                        columns.append( self.model._meta.get_field(f, many_to_many=False).column ) 
     577                    elif not self._select.has_key( f ): 
     578                        raise FieldDoesNotExist, '%s has no field named %r' % ( self.model._meta.object_name, f ) 
     579 
    571580            field_names = self._fields 
    572581        else: # Default to all fields. 
     
    575584 
    576585        select = ['%s.%s' % (backend.quote_name(self.model._meta.db_table), backend.quote_name(c)) for c in columns] 
     586 
     587        # Add any additional SELECTs. 
     588        if self._select: 
     589            select.extend(['(%s) AS %s' % (quote_only_if_word(s[1]), backend.quote_name(s[0])) for s in self._select.items()]) 
     590 
    577591        cursor = connection.cursor() 
    578592        cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params) 
  • django/branches/unicode/django/oldforms/__init__.py

    r5310 r5399  
    793793            import decimal  
    794794        except ImportError: 
    795             from django.utils import decimal 
     795            from django.utils import _decimal as decimal 
    796796        try:  
    797797            return decimal.Decimal(data)  
  • django/branches/unicode/django/template/defaulttags.py

    r5126 r5399  
    239239        output = [] # list of dictionaries in the format {'grouper': 'key', 'list': [list of contents]} 
    240240        for obj in obj_list: 
    241             grouper = self.expression.resolve(Context({'var': obj}), True) 
     241            grouper = self.expression.resolve(obj, True) 
    242242            # TODO: Is this a sensible way to determine equality? 
    243243            if output and repr(output[-1]['grouper']) == repr(grouper): 
     
    849849        raise TemplateSyntaxError, "next-to-last argument to 'regroup' tag must be 'as'" 
    850850 
    851     expression = parser.compile_filter('var.%s' % lastbits_reversed[2][::-1]) 
     851    expression = parser.compile_filter(lastbits_reversed[2][::-1]) 
    852852 
    853853    var_name = lastbits_reversed[0][::-1] 
  • django/branches/unicode/django/test/simple.py

    r5185 r5399  
    1 import unittest, doctest 
     1import unittest 
    22from django.conf import settings 
     3from django.test import _doctest as doctest 
    34from django.test.utils import setup_test_environment, teardown_test_environment 
    45from django.test.utils import create_test_db, destroy_test_db 
  • django/branches/unicode/django/test/testcases.py

    r5241 r5399  
    1 import re, doctest, unittest 
     1import re, unittest 
    22from urlparse import urlparse 
    33from django.db import transaction 
    44from django.core import management, mail 
    55from django.db.models import get_apps 
     6from django.test import _doctest as doctest 
    67from django.test.client import Client 
    78 
  • django/branches/unicode/docs/testing.txt

    r5381 r5399  
    148148"pythonic". It's designed to make writing tests as easy as possible, so 
    149149there's no overhead of writing classes or methods; you simply put tests in 
    150 docstrings. This gives the added advantage of given your modules automatic 
     150docstrings. This gives the added advantage of giving your modules automatic 
    151151documentation -- well-written doctests can kill both the documentation and the 
    152152testing bird with a single stone. 
     
    580580details of these advanced settings. 
    581581 
    582 .. _settings: ../settings.txt 
     582.. _settings: ../settings/ 
    583583 
    584584The test database is created by the user in the ``DATABASE_USER`` setting. 
  • django/branches/unicode/tests/modeltests/lookup/models.py

    r5386 r5399  
    132132[('headline', u'Article 1'), ('id', 1)] 
    133133 
     134 
     135# you can use values() even on extra fields 
     136>>> for d in Article.objects.extra( select={'id_plus_one' : 'id + 1'} ).values('id', 'id_plus_one'): 
     137...     i = d.items() 
     138...     i.sort() 
     139...     i 
     140[('id', 5), ('id_plus_one', 6)] 
     141[('id', 6), ('id_plus_one', 7)] 
     142[('id', 4), ('id_plus_one', 5)] 
     143[('id', 2), ('id_plus_one', 3)] 
     144[('id', 3), ('id_plus_one', 4)] 
     145[('id', 7), ('id_plus_one', 8)] 
     146[('id', 1), ('id_plus_one', 2)] 
     147 
     148# however, an exception FieldDoesNotExist will still be thrown  
     149# if you try to access non-existent field (field that is neither on the model nor extra) 
     150>>> Article.objects.extra( select={'id_plus_one' : 'id + 1'} ).values('id', 'id_plus_two') 
     151Traceback (most recent call last): 
     152    ... 
     153FieldDoesNotExist: Article has no field named 'id_plus_two' 
     154 
    134155# if you don't specify which fields, all are returned 
    135156>>> list(Article.objects.filter(id=5).values()) == [{'id': 5, 'headline': 'Article 5', 'pub_date': datetime(2005, 8, 1, 9, 0)}]