Django

Code

Changeset 6334

Show
Ignore:
Timestamp:
09/15/07 16:34:09 (10 months ago)
Author:
adrian
Message:

queryset-refactor: Merged to [6190]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/AUTHORS

    r6332 r6334  
    247247    remco@diji.biz 
    248248    rhettg@gmail.com 
     249    Matt Riggott 
    249250    Henrique Romano <onaiort@gmail.com> 
    250251    Armin Ronacher 
  • django/branches/queryset-refactor/django/conf/locale/te/LC_MESSAGES/django.po

    r5304 r6334  
    1515"Content-Transfer-Encoding: 8bit\n" 
    1616"X-Generator: KBabel 1.11.4\n" 
    17 "Plural-Forms: nplurals=2; nplurals=n>1;" 
     17"Plural-Forms: nplurals=2; plural=n>1;" 
    1818 
    1919#: contrib/comments/models.py:67 contrib/comments/models.py:166 
  • django/branches/queryset-refactor/django/contrib/admin/media/js/core.js

    r4087 r6334  
    11// Core javascript helper functions 
     2 
     3// basic browser identification & version 
     4var isOpera = (navigator.userAgent.indexOf("Opera")>=0) && parseFloat(navigator.appVersion); 
     5var isIE = ((document.all) && (!isOpera)) && parseFloat(navigator.appVersion.split("MSIE ")[1].split(";")[0]); 
    26 
    37// Cross-browser event handlers. 
     
    7276    if (obj.offsetParent) { 
    7377        while (obj.offsetParent) { 
    74             curleft += obj.offsetLeft
     78            curleft += obj.offsetLeft - ((isOpera) ? 0 : obj.scrollLeft)
    7579            obj = obj.offsetParent; 
     80        } 
     81        // IE offsetParent does not include the top-level  
     82        if (isIE && obj.parentElement){ 
     83            curleft += obj.offsetLeft - obj.scrollLeft; 
    7684        } 
    7785    } else if (obj.x) { 
     
    8593    if (obj.offsetParent) { 
    8694        while (obj.offsetParent) { 
    87             curtop += obj.offsetTop
     95            curtop += obj.offsetTop - ((isOpera) ? 0 : obj.scrollTop)
    8896            obj = obj.offsetParent; 
     97        } 
     98        // IE offsetParent does not include the top-level  
     99        if (isIE && obj.parentElement){ 
     100            curtop += obj.offsetTop - obj.scrollTop; 
    89101        } 
    90102    } else if (obj.y) { 
  • django/branches/queryset-refactor/django/contrib/localflavor/br/forms.py

    r5876 r6334  
    77from django.newforms.fields import Field, RegexField, CharField, Select, EMPTY_VALUES 
    88from django.utils.encoding import smart_unicode 
    9 from django.utils.translation import ugettext 
     9from django.utils.translation import ugettext as _ 
    1010import re 
     11 
     12try: 
     13    set 
     14except NameError: 
     15    from sets import Set as set     # For Python 2.3 
    1116 
    1217phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4})[-\.]?(\d{4})$') 
     
    1621        super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$', 
    1722            max_length=None, min_length=None, 
    18             error_message=ugettext('Enter a zip code in the format XXXXX-XXX.'), 
     23            error_message=_('Enter a zip code in the format XXXXX-XXX.'), 
    1924                    *args, **kwargs) 
    2025 
     
    2833        if m: 
    2934            return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3)) 
    30         raise ValidationError(ugettext('Phone numbers must be in XX-XXXX-XXXX format.')) 
     35        raise ValidationError(_('Phone numbers must be in XX-XXXX-XXXX format.')) 
    3136 
    3237class BRStateSelect(Select): 
     
    3944        super(BRStateSelect, self).__init__(attrs, choices=STATE_CHOICES) 
    4045 
     46class BRStateChoiceField(Field): 
     47    """ 
     48    A choice field that uses a list of Brazilian states as its choices. 
     49    """ 
     50    widget = Select 
     51 
     52    def __init__(self, required=True, widget=None, label=None, 
     53                 initial=None, help_text=None): 
     54        super(BRStateChoiceField, self).__init__(required, widget, label, 
     55                                                 initial, help_text) 
     56        from br_states import STATE_CHOICES 
     57        self.widget.choices = STATE_CHOICES 
     58 
     59    def clean(self, value): 
     60        value = super(BRStateChoiceField, self).clean(value) 
     61        if value in EMPTY_VALUES: 
     62            value = u'' 
     63        value = smart_unicode(value) 
     64        if value == u'': 
     65            return value 
     66        valid_values = set([smart_unicode(k) for k, v in self.widget.choices]) 
     67        if value not in valid_values: 
     68            raise ValidationError(_(u'Select a valid brazilian state.' 
     69                                           u' That state is not one' 
     70                                           u' of the available states.')) 
     71        return value 
    4172 
    4273def DV_maker(v): 
     
    70101            int(value) 
    71102        except ValueError: 
    72             raise ValidationError(ugettext("This field requires only numbers.")) 
     103            raise ValidationError(_("This field requires only numbers.")) 
    73104        if len(value) != 11: 
    74             raise ValidationError(ugettext("This field requires at most 11 digits or 14 characters.")) 
     105            raise ValidationError(_("This field requires at most 11 digits or 14 characters.")) 
    75106        orig_dv = value[-2:] 
    76107 
     
    82113        value = value[:-1] + str(new_2dv) 
    83114        if value[-2:] != orig_dv: 
    84             raise ValidationError(ugettext("Invalid CPF number.")) 
     115            raise ValidationError(_("Invalid CPF number.")) 
    85116 
    86117        return orig_value 
     
    104135        if len(value) != 14: 
    105136            raise ValidationError( 
    106                 ugettext("This field requires at least 14 digits")) 
     137                _("This field requires at least 14 digits")) 
    107138        orig_dv = value[-2:] 
    108139 
     
    114145        value = value[:-1] + str(new_2dv) 
    115146        if value[-2:] != orig_dv: 
    116             raise ValidationError(ugettext("Invalid CNPJ number.")) 
     147            raise ValidationError(_("Invalid CNPJ number.")) 
    117148 
    118149        return orig_value 
  • django/branches/queryset-refactor/django/contrib/sites/models.py

    r6330 r6334  
    11from django.db import models 
    22from django.utils.translation import ugettext_lazy as _ 
     3from django.http import get_host 
     4 
     5SITE_CACHE = {} 
    36 
    47class SiteManager(models.Manager): 
    58    def get_current(self): 
     9        """ 
     10        Returns the current ``Site`` based on the SITE_ID in the 
     11        project's settings. The ``Site`` object is cached the first 
     12        time it's retrieved from the database. 
     13        """ 
    614        from django.conf import settings 
    715        try: 
     
    1018            from django.core.exceptions import ImproperlyConfigured 
    1119            raise ImproperlyConfigured("You're using the Django \"sites framework\" without having set the SITE_ID setting. Create a site in your database and set the SITE_ID setting to fix this error.") 
    12         return self.get(pk=sid) 
     20        try: 
     21            current_site = SITE_CACHE[sid] 
     22        except KeyError: 
     23            current_site = self.get(pk=sid) 
     24            SITE_CACHE[sid] = current_site 
     25        return current_site 
     26 
     27    def clear_cache(self): 
     28        """Clears the ``Site`` object cache.""" 
     29        global SITE_CACHE 
     30        SITE_CACHE = {} 
    1331 
    1432class Site(models.Model): 
     
    3755    """ 
    3856    def __init__(self, request): 
    39         self.domain = self.name = request.META['SERVER_NAME'] 
     57        self.domain = self.name = get_host(request) 
    4058 
    4159    def __unicode__(self): 
  • django/branches/queryset-refactor/django/core/handlers/base.py

    r4265 r6334  
    5151    def get_response(self, request): 
    5252        "Returns an HttpResponse object for the given HttpRequest" 
     53        response = self._real_get_response(request) 
     54        return fix_location_header(request, response) 
     55 
     56    def _real_get_response(self, request): 
    5357        from django.core import exceptions, urlresolvers 
    5458        from django.core.mail import mail_admins 
     
    130134        import traceback 
    131135        return '\n'.join(traceback.format_exception(*(exc_info or sys.exc_info()))) 
     136 
     137def fix_location_header(request, response): 
     138    """ 
     139    Ensure that we always use an absolute URI in any location header in the 
     140    response. This is required by RFC 2616, section 14.30. 
     141 
     142    Code constructing response objects is free to insert relative paths and 
     143    this function converts them to absolute paths. 
     144    """ 
     145    if 'Location' in response.headers and http.get_host(request): 
     146        response['Location'] = request.build_absolute_uri(response['Location']) 
     147    return response 
     148 
  • django/branches/queryset-refactor/django/core/validators.py

    r6096 r6334  
    182182        raise ValidationError, _("No file was submitted. Check the encoding type on the form.") 
    183183    try: 
    184         Image.open(StringIO(content)) 
    185     except (IOError, OverflowError): # Python Imaging Library doesn't recognize it as an image 
    186         # OverflowError is due to a bug in PIL with Python 2.4+ which can cause  
    187         # it to gag on OLE files.  
     184        # load() is the only method that can spot a truncated JPEG, 
     185        #  but it cannot be called sanely after verify() 
     186        trial_image = Image.open(StringIO(content)) 
     187        trial_image.load() 
     188        # verify() is the only method that can spot a corrupt PNG, 
     189        #  but it must be called immediately after the constructor 
     190        trial_image = Image.open(StringIO(content)) 
     191        trial_image.verify() 
     192    except Exception: # Python Imaging Library doesn't recognize it as an image 
    188193        raise ValidationError, _("Upload a valid image. The file you uploaded was either not an image or a corrupted image.") 
    189194 
  • django/branches/queryset-refactor/django/db/models/base.py

    r6121 r6334  
    242242            if self._meta.order_with_respect_to: 
    243243                field_names.append(qn('_order')) 
    244                 # TODO: This assumes the database supports subqueries. 
    245                 placeholders.append('(SELECT COUNT(*) FROM %s WHERE %s = %%s)' % \ 
    246                     (qn(self._meta.db_table), qn(self._meta.order_with_respect_to.column))) 
    247                 db_values.append(getattr(self, self._meta.order_with_respect_to.attname)) 
     244                placeholders.append('%s') 
     245                subsel = 'SELECT COUNT(*) FROM %s WHERE %s = %%s' % ( 
     246                    qn(self._meta.db_table), 
     247                    qn(self._meta.order_with_respect_to.column)) 
     248                cursor.execute(subsel, (getattr(self, self._meta.order_with_respect_to.attname),)) 
     249                db_values.append(cursor.fetchone()[0]) 
    248250            if db_values: 
    249251                cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \ 
  • django/branches/queryset-refactor/django/http/__init__.py

    r6098 r6334  
    33from pprint import pformat 
    44from urllib import urlencode 
     5from urlparse import urljoin 
    56from django.utils.datastructures import MultiValueDict, FileDict 
    67from django.utils.encoding import smart_str, iri_to_uri, force_unicode 
     
    4344 
    4445    __contains__ = has_key 
    45          
     46 
    4647    def get_full_path(self): 
    4748        return '' 
     49 
     50    def build_absolute_uri(self, location=None): 
     51        """ 
     52        Builds an absolute URI from the location and the variables available in 
     53        this request. If no location is specified, the absolute URI is built on 
     54        ``request.get_full_path()``. 
     55        """ 
     56        if not location: 
     57            location = self.get_full_path() 
     58        if not ':' in location: 
     59            current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http', 
     60                                         get_host(self), self.path) 
     61            location = urljoin(current_uri, location) 
     62        return location 
    4863 
    4964    def is_secure(self): 
     
    365380def get_host(request): 
    366381    "Gets the HTTP host from the environment or request headers." 
     382    # We try three options, in order of decreasing preference. 
    367383    host = request.META.get('HTTP_X_FORWARDED_HOST', '') 
    368     if not host: 
    369         host = request.META.get('HTTP_HOST', '') 
     384    if 'HTTP_HOST' in request.META: 
     385        host = request.META['HTTP_HOST'] 
     386    else: 
     387        # Reconstruct the host using the algorithm from PEP 333. 
     388        host = request.META['SERVER_NAME'] 
     389        server_port = request.META['SERVER_PORT'] 
     390        if server_port != (request.is_secure() and 443 or 80): 
     391            host = '%s:%s' % (host, server_port) 
    370392    return host 
    371393 
  • django/branches/queryset-refactor/django/newforms/fields.py

    r6332 r6334  
    33""" 
    44 
     5import copy 
    56import datetime 
    67import re 
     
    101102        return {} 
    102103 
     104    def __deepcopy__(self, memo): 
     105        result = copy.copy(self) 
     106        memo[id(self)] = result 
     107        result.widget = copy.deepcopy(self.widget, memo) 
     108        return result 
     109 
    103110class CharField(Field): 
    104111    def __init__(self, max_length=None, min_length=None, *args, **kwargs): 
     
    387394        from cStringIO import StringIO 
    388395        try: 
    389             Image.open(StringIO(f.content)) 
    390         except (IOError, OverflowError): # Python Imaging Library doesn't recognize it as an image 
    391             # OverflowError is due to a bug in PIL with Python 2.4+ which can cause  
    392             # it to gag on OLE files.  
     396            # load() is the only method that can spot a truncated JPEG, 
     397            #  but it cannot be called sanely after verify() 
     398            trial_image = Image.open(StringIO(f.content)) 
     399            trial_image.load() 
     400            # verify() is the only method that can spot a corrupt PNG, 
     401            #  but it must be called immediately after the constructor 
     402            trial_image = Image.open(StringIO(f.content)) 
     403            trial_image.verify() 
     404        except Exception: # Python Imaging Library doesn't recognize it as an image 
    393405            raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image.")) 
    394406        return f 
     
    410422 
    411423    def clean(self, value): 
     424        # If no URL scheme given, assume http:// 
     425        if value and '://' not in value: 
     426            value = u'http://%s' % value 
    412427        value = super(URLField, self).clean(value) 
    413428        if value == u'': 
  • django/branches/queryset-refactor/django/newforms/forms.py

    r6332 r6334  
    3232 
    3333    def copy(self): 
    34         return SortedDictFromList([(k, copy.copy(v)) for k, v in self.items()]) 
     34        return SortedDictFromList([(k, copy.deepcopy(v)) for k, v in self.items()]) 
    3535 
    3636class DeclarativeFieldsMetaclass(type): 
  • django/branches/queryset-refactor/django/test/testcases.py

    r6044 r6334  
    8585            ("Response didn't redirect as expected: Response code was %d" 
    8686             " (expected %d)" % (response.status_code, status_code))) 
    87         scheme, netloc, path, query, fragment = urlsplit(response['Location']) 
    88         url = path 
    89         if query: 
    90             url += '?' + query 
    91         if fragment: 
    92             url += '#' + fragment 
     87        url = response['Location'] 
     88        scheme, netloc, path, query, fragment = urlsplit(url) 
    9389        self.assertEqual(url, expected_url, 
    9490            "Response redirected to '%s', expected '%s'" % (url, expected_url)) 
  • django/branches/queryset-refactor/django/views/generic/date_based.py

    r6058 r6334  
    1111        template_name=None, template_loader=loader, 
    1212        extra_context=None, allow_empty=False, context_processors=None, 
    13         mimetype=None, allow_future=False): 
     13        mimetype=None, allow_future=False, template_object_name='latest'): 
    1414    """ 
    1515    Generic top-level archive of date-based objects. 
     
    4040    c = RequestContext(request, { 
    4141        'date_list' : date_list, 
    42         'latest' : latest, 
     42        template_object_name : latest, 
    4343    }, context_processors) 
    4444    for key, value in extra_context.items(): 
  • django/branches/queryset-refactor/django/views/i18n.py

    r5849 r6334  
    1010    Redirect to a given url while setting the chosen language in the 
    1111    session or cookie. The url and the language code need to be 
    12     specified in the GET parameters. 
     12    specified in the request parameters. 
     13 
     14    Since this view changes how the user will see the rest of the site, it must 
     15    only be accessed as a POST request. If called as a GET request, it will 
     16    redirect to the page in the request (the 'next' parameter) without changing 
     17    any state. 
    1318    """ 
    14     lang_code = request.GET.get('language', None) 
    1519    next = request.GET.get('next', None) 
    1620    if not next: 
     
    1923        next = '/' 
    2024    response = http.HttpResponseRedirect(next) 
    21     if lang_code and check_for_language(lang_code): 
    22         if hasattr(request, 'session'): 
    23             request.session['django_language'] = lang_code 
    24         else: 
    25             response.set_cookie('django_language', lang_code) 
     25    if request.method == 'POST': 
     26        lang_code = request.POST.get('language', None) 
     27        if lang_code and check_for_language(lang_code): 
     28            if hasattr(request, 'session'): 
     29                request.session['django_language'] = lang_code 
     30            else: 
     31                response.set_cookie('django_language', lang_code) 
    2632    return response 
    2733 
  • django/branches/queryset-refactor/docs/db-api.txt

    r6330 r6334  
    800800        Entry.objects.extra(where=['headline=%s'], params=['Lennon']) 
    801801 
     802    The combined number of placeholders in the list of strings for ``select`` 
     803    or ``where`` should equal the number of values in the ``params`` list. 
     804 
    802805QuerySet methods that do not return QuerySets 
    803806--------------------------------------------- 
  • django/branches/queryset-refactor/docs/generic_views.txt

    r6332 r6334  
    202202      default, this is ``False``. 
    203203 
     204    * **New in Django development version:** ``template_object_name``: 
     205      Designates the name of the template variable to use in the template 
     206      context. By default, this is ``'latest'``. 
     207 
    204208**Template name:** 
    205209 
     
    222226      ordered in reverse. This is equivalent to 
    223227      ``queryset.dates(date_field, 'year')[::-1]``. 
     228 
    224229    * ``latest``: The ``num_latest`` objects in the system, ordered descending 
    225230      by ``date_field``. For example, if ``num_latest`` is ``10``, then 
    226231      ``latest`` will be a list of the latest 10 objects in ``queryset``. 
     232 
     233      **New in Django development version:** This variable's name depends on 
     234      the ``template_object_name`` parameter, which is ``'latest'`` by default. 
     235      If ``template_object_name`` is ``'foo'``, this variable's name will be 
     236      ``foo``. 
    227237 
    228238.. _RequestContext docs: ../templates_python/#subclassing-context-requestcontext 
     
    765775      page. 
    766776 
    767     * ``page_range``: A list of the page numbers that are available. This 
    768     is 1-based. 
     777    * **New in Django development version:** ``page_range``: A list of the  
     778    page numbers that are available. This is 1-based. 
    769779 
    770780Notes on pagination 
     
    789799 
    790800These values and lists are is 1-based, not 0-based, so the first page would be 
    791 represented as page ``1``. As a special case, you are also permitted to use  
     801represented as page ``1``.  
     802 
     803**New in Django development version:**  
     804 
     805As a special case, you are also permitted to use  
    792806``last`` as a value for ``page``:: 
    793807 
  • django/branches/queryset-refactor/docs/install.txt

    r5932 r6334  
    128128    1. Download the latest release from our `download page`_. 
    129129 
    130     2. Untar the downloaded file (e.g. ``tar xzvf Django-NNN.tar.gz``). 
    131  
    132     3. Change into the downloaded directory (e.g. ``cd Django-NNN``). 
    133  
    134     4. Run ``sudo python setup.py install``. 
    135  
    136 The command will install Django in your Python installation's ``site-packages`` 
    137 directory. 
     130    2. Untar the downloaded file (e.g. ``tar xzvf Django-NNN.tar.gz``, 
     131       where ``NNN`` is the version number of the latest release). 
     132       If you're using Windows, you can download the command-line tool 
     133       bsdtar_ to do this, or you can use a GUI-based tool such as 7-zip_. 
     134 
     135    3. Change into the directory created in step 2 (e.g. ``cd Django-NNN``). 
     136 
     137    4. If you're using Linux, Mac OS X or some other flavor of Unix, enter 
     138       the command ``sudo python setup.py install`` at the shell prompt. 
     139       If you're using Windows, start up a command shell with administrator 
     140       privileges and run the command ``setup.py install``. 
     141 
     142These commands will install Django in your Python installation's 
     143``site-packages`` directory. 
    138144 
    139145.. _distribution specific notes: ../distributions/ 
     146.. _bsdtar: http://gnuwin32.sourceforge.net/packages/bsdtar.htm 
     147.. _7-zip: http://www.7-zip.org/ 
    140148 
    141149Installing the development version 
     
    145153latest bug fixes and improvements, follow these instructions: 
    146154 
    147 1. Make sure you have Subversion_ installed. 
    148 2. Check out the Django code into your Python ``site-packages`` directory. 
    149  
    150    On Linux / Mac OSX / Unix, do this:: 
    151  
    152        svn co http://code.djangoproject.com/svn/django/trunk/ django_src 
    153        ln -s `pwd`/django_src/django SITE-PACKAGES-DIR/django 
     1551. Make sure that you have Subversion_ installed, and that you can run its 
     156   commands from a shell. (Enter ``svn help`` at a shell prompt to test 
     157   this.) 
     158 
     1592. Check out Django's main development branch (the 'trunk') like so:: 
     160 
     161       svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk 
     162 
     1633. Next, make sure that the Python interpreter can load Django's code. There 
     164   are various ways of accomplishing this.  One of the most convenient, on 
     165   Linux, Mac OSX or other Unix-like systems, is to use a symbolic link:: 
     166 
     167       ln -s `pwd`/django-trunk/django SITE-PACKAGES-DIR/django 
    154168 
    155169   (In the above line, change ``SITE-PACKAGES-DIR`` to match the location of 
     
    157171   "Where are my ``site-packages`` stored?" section above.) 
    158172 
    159    On Windows, do this:: 
    160  
    161        svn co http://code.djangoproject.com/svn/django/trunk/django c:\Python24\lib\site-packages\django 
    162  
    163 3. Copy the file ``django_src/django/bin/django-admin.py`` to somewhere on your 
    164    system path, such as ``/usr/local/bin`` (Unix) or ``C:\Python24\Scripts`` 
     173   Alternatively, you can define your ``PYTHONPATH`` environment variable 
     174   so that it includes the ``django`` subdirectory of ``django-trunk``. 
     175   This is perhaps the most convenient solution on Windows systems, which 
     176   don't support symbolic links. (Environment variables can be defined on 
     177   Windows systems `from the Control Panel`_.) 
     178 
     179   .. admonition:: What about Apache and mod_python? 
     180 
     181      If you take the approach of setting ``PYTHONPATH``, you'll need to 
     182      remember to do the same thing in your Apache configuration once you 
     183      deploy your production site. Do this by setting ``PythonPath`` in your 
     184      Apache configuration file. 
     185 
     186      More information about deployment is available, of course, in our 
     187      `How to use Django with mod_python`_ documentation. 
     188 
     189      .. _How to use Django with mod_python: ../modpython/ 
     190 
     1914. Copy the file ``django-trunk/django/bin/django-admin.py`` to somewhere on 
     192   your system path, such as ``/usr/local/bin`` (Unix) or ``C:\Python24\Scripts`` 
    165193   (Windows). This step simply lets you type ``django-admin.py`` from within 
    166194   any directory, rather than having to qualify the command with the full path 
    167195   to the file. 
    168196 
    169 You *don't* have to run ``python setup.py install``, because that command 
    170 takes care of steps 2 and 3 for you
     197You *don't* have to run ``python setup.py install``, because you've already 
     198carried out the equivalent actions in steps 3 and 4
    171199 
    172200When you want to update your copy of the Django source code, just run the 
    173 command ``svn update`` from within the ``django`` directory. When you do this, 
    174 Subversion will automatically download any changes. 
     201command ``svn update`` from within the ``django-trunk`` directory. When you do 
     202this, Subversion will automatically download any changes. 
    175203 
    176204.. _`download page`: http://www.djangoproject.com/download/ 
    177205.. _Subversion: http://subversion.tigris.org/ 
     206.. _from the Control Panel: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_environmnt_addchange_variable.mspx 
  • django/branches/queryset-refactor/docs/model-api.txt

    r6109 r6334  
    15511551Set ``list_filter`` to activate filters in the right sidebar of the change list 
    15521552page of the admin. This should be a list of field names, and each specified 
    1553 field should be either a ``BooleanField``, ``DateField``, ``DateTimeField`` 
    1554 or ``ForeignKey``. 
     1553field should be either a ``BooleanField``, ``CharField``, ``DateField``,  
     1554``DateTimeField``, ``IntegerField`` or ``ForeignKey``.  
    15551555 
    15561556This example, taken from the ``django.contrib.auth.models.User`` model, shows 
  • django/branches/queryset-refactor/docs/modpython.txt

    r6071 r6334  
    8484work. If you had ``import blogroll`` in your code somewhere and ``blogroll`` 
    8585lived under the ``weblog/`` directory, you would *also* need to add 
    86 ``/var/production/django-apps/weblog/`` to your ``PythonPath``. Remember: the 
     86``/usr/local/django-apps/weblog/`` to your ``PythonPath``. Remember: the 
    8787**parent directories** of anything you import directly must be on the Python 
    8888path. 
  • django/branches/queryset-refactor/docs/request_response.txt

    r6332 r6334  
    162162   Example: ``"/music/bands/the_beatles/?print=true"`` 
    163163 
     164``build_absolute_uri(location)`` 
     165   **New in Django development version** 
     166 
     167   Returns the absolute URI form of ``location``. If no location is provided, 
     168   the location will be set to ``request.get_full_path()``. 
     169 
     170   If the location is already an absolute URI, it will not be altered. 
     171   Otherwise the absolute URI is built using the server variables available in 
     172   this request. 
     173 
     174   Example: ``"http://example.com/music/bands/the_beatles/?print=true"`` 
     175 
    164176``is_secure()`` 
    165177   Returns ``True`` if the request is secure; that is, if it was made with 
     
    185197      has more than one value, ``__getitem__()`` returns the last value. 
    186198      Raises ``django.utils.datastructure.MultiValueDictKeyError`` if the key 
    187       does not exist (fortunately, this is a subclass of Python's standard 
    188       ``KeyError``, so you can stick to catching ``KeyError``). 
     199      does not exist. (This is a subclass of Python's standard ``KeyError``, 
     200      so you can stick to catching ``KeyError``.) 
    189201 
    190202    * ``__setitem__(key, value)`` -- Sets the given key to ``[value]`` 
  • django/branches/queryset-refactor/docs/sites.txt

    r6332 r6334  
    213213    >>> 'http://%s%s' % (Site.objects.get_current().domain, obj.get_absolute_url()) 
    214214    'http://example.com/mymodel/objects/3/' 
     215 
     216Caching the current ``Site`` object 
     217=================================== 
     218 
     219**New in Django development version** 
     220 
     221As the current site is stored in the database, each call to 
     222``Site.objects.get_current()`` could result in a database query. But Django is a 
     223little cleverer than that: on the first request, the current site is cached, and 
     224any subsequent call returns the cached data instead of hitting the database. 
     225 
     226If for any reason you want to force a database query, you can tell Django to 
     227clear the cache using ``Site.objects.clear_cache()``:: 
     228 
     229    # First call; current site fetched from database. 
     230    current_site = Site.objects.get_current() 
     231    # ... 
     232 
     233    # Second call; current site fetched from cache. 
     234    current_site = Site.objects.get_current() 
     235    # ... 
     236 
     237    # Force a database query for the third call. 
     238    Site.objects.clear_cache() 
     239    current_site = Site.objects.get_current() 
    215240 
    216241The ``CurrentSiteManager`` 
  • django/branches/queryset-refactor/docs/templates_python.txt

    r6332 r6334  
    643643        return value.lower() 
    644644 
    645 Template filters which expect strings 
    646 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    647  
    648 If you're writing a template filter which only expects a string as the first 
    649 argument, you should use the included decorator ``stringfilter``. This will 
    650 convert an object to it's string value before being passed to your function:: 
     645Template filters that expect strings 
     646~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     647 
     648If you're writing a template filter that only expects a string as the first 
     649argument, you should use the decorator ``stringfilter``. This will 
     650convert an object to its string value before being passed to your function:: 
    651651 
    652652    from django.template.defaultfilters import stringfilter 
     
    655655    def lower(value): 
    656656        return value.lower() 
     657 
     658This way, you'll be able to pass, say, an integer to this filter, and it 
     659won't cause an ``AttributeError`` (because integers don't have ``lower()`` 
     660methods). 
    657661 
    658662Registering a custom filters 
  • django/branches/queryset-refactor/docs/templates.txt

    r6332 r6334  
    14321432perspective -- how it works and how to extend it. 
    14331433 
    1434 .. _The Django template language: For Python programmers: ../templates_python/ 
     1434.. _The Django template language\: For Python programmers: ../templates_python/ 
  • django/branches/queryset-refactor/tests/modeltests/test_client/models.py

    r6039 r6334  
    8484        "GET a URL that redirects elsewhere" 
    8585        response = self.client.get('/test_client/redirect_view/') 
    86          
    8786        # Check that the response was a 302 (redirect) 
    88         self.assertRedirects(response, '/test_client/get_view/') 
     87        self.assertRedirects(response, 'http://testserver/test_client/get_view/') 
     88         
     89        client_providing_host = Client(HTTP_HOST='django.testserver') 
     90        response = client_providing_host.get('/test_client/redirect_view/') 
     91        # Check that the response was a 302 (redirect) with absolute URI 
     92        self.assertRedirects(response, 'http://django.testserver/test_client/get_view/') 
    8993     
    9094    def test_redirect_with_query(self): 
     
    9397         
    9498        # Check if parameters are intact 
    95         self.assertRedirects(response, '/test_client/get_view/?var=value') 
     99        self.assertRedirects(response, 'http://testserver/test_client/get_view/?var=value') 
    96100 
    97101    def test_permanent_redirect(self): 
    98102        "GET a URL that redirects permanently elsewhere" 
    99103        response = self.client.get('/test_client/permanent_redirect_view/') 
    100          
    101104        # Check that the response was a 301 (permanent redirect) 
    102         self.assertRedirects(response, '/test_client/get_view/', status_code=301) 
     105        self.assertRedirects(response, 'http://testserver/test_client/get_view/', status_code=301) 
     106 
     107        client_providing_host = Client(HTTP_HOST='django.testserver') 
     108        response = client_providing_host.get('/test_client/permanent_redirect_view/') 
     109        # Check that the response was a 301 (permanent redirect) with absolute URI 
     110        self.assertRedirects(response, 'http://django.testserver/test_client/get_view/', status_code=301) 
    103111 
    104112    def test_redirect_to_strange_location(self): 
     
    108116        # Check that the response was a 302, and that 
    109117        # the attempt to get the redirection location returned 301 when retrieved 
    110         self.assertRedirects(response, '/test_client/permanent_redirect_view/', target_status_code=301) 
     118        self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/', target_status_code=301) 
    111119 
    112120    def test_notfound_response(self): 
     
    232240        # Get the page without logging in. Should result in 302. 
    233241        response = self.client.get('/test_client/login_protected_view/') 
    234         self.assertRedirects(response, '/accounts/login/?next=/test_client/login_protected_view/') 
     242        self.assertRedirects(response, 'http://testserver/accounts/login/?next=/test_client/login_protected_view/') 
    235243         
    236244        # Log in 
    237245        login = self.client.login(username='testclient', password='password') 
    238         self.assertTrue(login, 'Could not log in') 
     246        self.failUnless(login, 'Could not log in') 
    239247 
    240248        # Request a page that requires a login 
     
    270278        # Request a page that requires a login 
    271279        response = self.client.get('/test_client/login_protected_view/') 
    272         self.assertRedirects(response, '/accounts/login/?next=/test_client/login_protected_view/') <