Changeset 6334
- Timestamp:
- 09/15/07 16:34:09 (10 months ago)
- Files:
-
- django/branches/queryset-refactor/AUTHORS (modified) (1 diff)
- django/branches/queryset-refactor/django/conf/locale/te/LC_MESSAGES/django.mo (modified) (previous)
- django/branches/queryset-refactor/django/conf/locale/te/LC_MESSAGES/django.po (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/admin/media/js/core.js (modified) (3 diffs)
- django/branches/queryset-refactor/django/contrib/localflavor/br/forms.py (modified) (8 diffs)
- django/branches/queryset-refactor/django/contrib/sites/models.py (modified) (3 diffs)
- django/branches/queryset-refactor/django/core/handler.py (deleted)
- django/branches/queryset-refactor/django/core/handlers/base.py (modified) (2 diffs)
- django/branches/queryset-refactor/django/core/validators.py (modified) (1 diff)
- django/branches/queryset-refactor/django/db/models/base.py (modified) (1 diff)
- django/branches/queryset-refactor/django/http/__init__.py (modified) (3 diffs)
- django/branches/queryset-refactor/django/newforms/fields.py (modified) (4 diffs)
- django/branches/queryset-refactor/django/newforms/forms.py (modified) (1 diff)
- django/branches/queryset-refactor/django/test/testcases.py (modified) (1 diff)
- django/branches/queryset-refactor/django/views/generic/date_based.py (modified) (2 diffs)
- django/branches/queryset-refactor/django/views/i18n.py (modified) (2 diffs)
- django/branches/queryset-refactor/docs/db-api.txt (modified) (1 diff)
- django/branches/queryset-refactor/docs/generic_views.txt (modified) (4 diffs)
- django/branches/queryset-refactor/docs/install.txt (modified) (3 diffs)
- django/branches/queryset-refactor/docs/model-api.txt (modified) (1 diff)
- django/branches/queryset-refactor/docs/modpython.txt (modified) (1 diff)
- django/branches/queryset-refactor/docs/request_response.txt (modified) (2 diffs)
- django/branches/queryset-refactor/docs/sites.txt (modified) (1 diff)
- django/branches/queryset-refactor/docs/templates_python.txt (modified) (2 diffs)
- django/branches/queryset-refactor/docs/templates.txt (modified) (1 diff)
- django/branches/queryset-refactor/tests/modeltests/test_client/models.py (modified) (5 diffs)
- django/branches/queryset-refactor/tests/regressiontests/forms/localflavor.py (modified) (1 diff)
- django/branches/queryset-refactor/tests/regressiontests/forms/tests.py (modified) (4 diffs)
- django/branches/queryset-refactor/tests/regressiontests/test_client_regress/models.py (modified) (4 diffs)
- django/branches/queryset-refactor/tests/runtests.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/AUTHORS
r6332 r6334 247 247 remco@diji.biz 248 248 rhettg@gmail.com 249 Matt Riggott 249 250 Henrique Romano <onaiort@gmail.com> 250 251 Armin Ronacher django/branches/queryset-refactor/django/conf/locale/te/LC_MESSAGES/django.po
r5304 r6334 15 15 "Content-Transfer-Encoding: 8bit\n" 16 16 "X-Generator: KBabel 1.11.4\n" 17 "Plural-Forms: nplurals=2; nplurals=n>1;"17 "Plural-Forms: nplurals=2; plural=n>1;" 18 18 19 19 #: contrib/comments/models.py:67 contrib/comments/models.py:166 django/branches/queryset-refactor/django/contrib/admin/media/js/core.js
r4087 r6334 1 1 // Core javascript helper functions 2 3 // basic browser identification & version 4 var isOpera = (navigator.userAgent.indexOf("Opera")>=0) && parseFloat(navigator.appVersion); 5 var isIE = ((document.all) && (!isOpera)) && parseFloat(navigator.appVersion.split("MSIE ")[1].split(";")[0]); 2 6 3 7 // Cross-browser event handlers. … … 72 76 if (obj.offsetParent) { 73 77 while (obj.offsetParent) { 74 curleft += obj.offsetLeft ;78 curleft += obj.offsetLeft - ((isOpera) ? 0 : obj.scrollLeft); 75 79 obj = obj.offsetParent; 80 } 81 // IE offsetParent does not include the top-level 82 if (isIE && obj.parentElement){ 83 curleft += obj.offsetLeft - obj.scrollLeft; 76 84 } 77 85 } else if (obj.x) { … … 85 93 if (obj.offsetParent) { 86 94 while (obj.offsetParent) { 87 curtop += obj.offsetTop ;95 curtop += obj.offsetTop - ((isOpera) ? 0 : obj.scrollTop); 88 96 obj = obj.offsetParent; 97 } 98 // IE offsetParent does not include the top-level 99 if (isIE && obj.parentElement){ 100 curtop += obj.offsetTop - obj.scrollTop; 89 101 } 90 102 } else if (obj.y) { django/branches/queryset-refactor/django/contrib/localflavor/br/forms.py
r5876 r6334 7 7 from django.newforms.fields import Field, RegexField, CharField, Select, EMPTY_VALUES 8 8 from django.utils.encoding import smart_unicode 9 from django.utils.translation import ugettext 9 from django.utils.translation import ugettext as _ 10 10 import re 11 12 try: 13 set 14 except NameError: 15 from sets import Set as set # For Python 2.3 11 16 12 17 phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4})[-\.]?(\d{4})$') … … 16 21 super(BRZipCodeField, self).__init__(r'^\d{5}-\d{3}$', 17 22 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.'), 19 24 *args, **kwargs) 20 25 … … 28 33 if m: 29 34 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.')) 31 36 32 37 class BRStateSelect(Select): … … 39 44 super(BRStateSelect, self).__init__(attrs, choices=STATE_CHOICES) 40 45 46 class 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 41 72 42 73 def DV_maker(v): … … 70 101 int(value) 71 102 except ValueError: 72 raise ValidationError( ugettext("This field requires only numbers."))103 raise ValidationError(_("This field requires only numbers.")) 73 104 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.")) 75 106 orig_dv = value[-2:] 76 107 … … 82 113 value = value[:-1] + str(new_2dv) 83 114 if value[-2:] != orig_dv: 84 raise ValidationError( ugettext("Invalid CPF number."))115 raise ValidationError(_("Invalid CPF number.")) 85 116 86 117 return orig_value … … 104 135 if len(value) != 14: 105 136 raise ValidationError( 106 ugettext("This field requires at least 14 digits"))137 _("This field requires at least 14 digits")) 107 138 orig_dv = value[-2:] 108 139 … … 114 145 value = value[:-1] + str(new_2dv) 115 146 if value[-2:] != orig_dv: 116 raise ValidationError( ugettext("Invalid CNPJ number."))147 raise ValidationError(_("Invalid CNPJ number.")) 117 148 118 149 return orig_value django/branches/queryset-refactor/django/contrib/sites/models.py
r6330 r6334 1 1 from django.db import models 2 2 from django.utils.translation import ugettext_lazy as _ 3 from django.http import get_host 4 5 SITE_CACHE = {} 3 6 4 7 class SiteManager(models.Manager): 5 8 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 """ 6 14 from django.conf import settings 7 15 try: … … 10 18 from django.core.exceptions import ImproperlyConfigured 11 19 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 = {} 13 31 14 32 class Site(models.Model): … … 37 55 """ 38 56 def __init__(self, request): 39 self.domain = self.name = request.META['SERVER_NAME']57 self.domain = self.name = get_host(request) 40 58 41 59 def __unicode__(self): django/branches/queryset-refactor/django/core/handlers/base.py
r4265 r6334 51 51 def get_response(self, request): 52 52 "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): 53 57 from django.core import exceptions, urlresolvers 54 58 from django.core.mail import mail_admins … … 130 134 import traceback 131 135 return '\n'.join(traceback.format_exception(*(exc_info or sys.exc_info()))) 136 137 def 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 182 182 raise ValidationError, _("No file was submitted. Check the encoding type on the form.") 183 183 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 188 193 raise ValidationError, _("Upload a valid image. The file you uploaded was either not an image or a corrupted image.") 189 194 django/branches/queryset-refactor/django/db/models/base.py
r6121 r6334 242 242 if self._meta.order_with_respect_to: 243 243 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]) 248 250 if db_values: 249 251 cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \ django/branches/queryset-refactor/django/http/__init__.py
r6098 r6334 3 3 from pprint import pformat 4 4 from urllib import urlencode 5 from urlparse import urljoin 5 6 from django.utils.datastructures import MultiValueDict, FileDict 6 7 from django.utils.encoding import smart_str, iri_to_uri, force_unicode … … 43 44 44 45 __contains__ = has_key 45 46 46 47 def get_full_path(self): 47 48 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 48 63 49 64 def is_secure(self): … … 365 380 def get_host(request): 366 381 "Gets the HTTP host from the environment or request headers." 382 # We try three options, in order of decreasing preference. 367 383 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) 370 392 return host 371 393 django/branches/queryset-refactor/django/newforms/fields.py
r6332 r6334 3 3 """ 4 4 5 import copy 5 6 import datetime 6 7 import re … … 101 102 return {} 102 103 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 103 110 class CharField(Field): 104 111 def __init__(self, max_length=None, min_length=None, *args, **kwargs): … … 387 394 from cStringIO import StringIO 388 395 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 393 405 raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image.")) 394 406 return f … … 410 422 411 423 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 412 427 value = super(URLField, self).clean(value) 413 428 if value == u'': django/branches/queryset-refactor/django/newforms/forms.py
r6332 r6334 32 32 33 33 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()]) 35 35 36 36 class DeclarativeFieldsMetaclass(type): django/branches/queryset-refactor/django/test/testcases.py
r6044 r6334 85 85 ("Response didn't redirect as expected: Response code was %d" 86 86 " (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) 93 89 self.assertEqual(url, expected_url, 94 90 "Response redirected to '%s', expected '%s'" % (url, expected_url)) django/branches/queryset-refactor/django/views/generic/date_based.py
r6058 r6334 11 11 template_name=None, template_loader=loader, 12 12 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'): 14 14 """ 15 15 Generic top-level archive of date-based objects. … … 40 40 c = RequestContext(request, { 41 41 'date_list' : date_list, 42 'latest': latest,42 template_object_name : latest, 43 43 }, context_processors) 44 44 for key, value in extra_context.items(): django/branches/queryset-refactor/django/views/i18n.py
r5849 r6334 10 10 Redirect to a given url while setting the chosen language in the 11 11 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. 13 18 """ 14 lang_code = request.GET.get('language', None)15 19 next = request.GET.get('next', None) 16 20 if not next: … … 19 23 next = '/' 20 24 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) 26 32 return response 27 33 django/branches/queryset-refactor/docs/db-api.txt
r6330 r6334 800 800 Entry.objects.extra(where=['headline=%s'], params=['Lennon']) 801 801 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 802 805 QuerySet methods that do not return QuerySets 803 806 --------------------------------------------- django/branches/queryset-refactor/docs/generic_views.txt
r6332 r6334 202 202 default, this is ``False``. 203 203 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 204 208 **Template name:** 205 209 … … 222 226 ordered in reverse. This is equivalent to 223 227 ``queryset.dates(date_field, 'year')[::-1]``. 228 224 229 * ``latest``: The ``num_latest`` objects in the system, ordered descending 225 230 by ``date_field``. For example, if ``num_latest`` is ``10``, then 226 231 ``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``. 227 237 228 238 .. _RequestContext docs: ../templates_python/#subclassing-context-requestcontext … … 765 775 page. 766 776 767 * ``page_range``: A list of the page numbers that are available. This768 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. 769 779 770 780 Notes on pagination … … 789 799 790 800 These 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 801 represented as page ``1``. 802 803 **New in Django development version:** 804 805 As a special case, you are also permitted to use 792 806 ``last`` as a value for ``page``:: 793 807 django/branches/queryset-refactor/docs/install.txt
r5932 r6334 128 128 1. Download the latest release from our `download page`_. 129 129 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 142 These commands will install Django in your Python installation's 143 ``site-packages`` directory. 138 144 139 145 .. _distribution specific notes: ../distributions/ 146 .. _bsdtar: http://gnuwin32.sourceforge.net/packages/bsdtar.htm 147 .. _7-zip: http://www.7-zip.org/ 140 148 141 149 Installing the development version … … 145 153 latest bug fixes and improvements, follow these instructions: 146 154 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 155 1. 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 159 2. 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 163 3. 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 154 168 155 169 (In the above line, change ``SITE-PACKAGES-DIR`` to match the location of … … 157 171 "Where are my ``site-packages`` stored?" section above.) 158 172 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 191 4. 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`` 165 193 (Windows). This step simply lets you type ``django-admin.py`` from within 166 194 any directory, rather than having to qualify the command with the full path 167 195 to the file. 168 196 169 You *don't* have to run ``python setup.py install``, because that command170 takes care of steps 2 and 3 for you.197 You *don't* have to run ``python setup.py install``, because you've already 198 carried out the equivalent actions in steps 3 and 4. 171 199 172 200 When 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.201 command ``svn update`` from within the ``django-trunk`` directory. When you do 202 this, Subversion will automatically download any changes. 175 203 176 204 .. _`download page`: http://www.djangoproject.com/download/ 177 205 .. _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 1551 1551 Set ``list_filter`` to activate filters in the right sidebar of the change list 1552 1552 page 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``. 1553 field should be either a ``BooleanField``, ``CharField``, ``DateField``, 1554 ``DateTimeField``, ``IntegerField`` or ``ForeignKey``. 1555 1555 1556 1556 This example, taken from the ``django.contrib.auth.models.User`` model, shows django/branches/queryset-refactor/docs/modpython.txt
r6071 r6334 84 84 work. If you had ``import blogroll`` in your code somewhere and ``blogroll`` 85 85 lived under the ``weblog/`` directory, you would *also* need to add 86 ``/ var/production/django-apps/weblog/`` to your ``PythonPath``. Remember: the86 ``/usr/local/django-apps/weblog/`` to your ``PythonPath``. Remember: the 87 87 **parent directories** of anything you import directly must be on the Python 88 88 path. django/branches/queryset-refactor/docs/request_response.txt
r6332 r6334 162 162 Example: ``"/music/bands/the_beatles/?print=true"`` 163 163 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 164 176 ``is_secure()`` 165 177 Returns ``True`` if the request is secure; that is, if it was made with … … 185 197 has more than one value, ``__getitem__()`` returns the last value. 186 198 Raises ``django.utils.datastructure.MultiValueDictKeyError`` if the key 187 does not exist (fortunately, this is a subclass of Python's standard188 ``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``.) 189 201 190 202 * ``__setitem__(key, value)`` -- Sets the given key to ``[value]`` django/branches/queryset-refactor/docs/sites.txt
r6332 r6334 213 213 >>> 'http://%s%s' % (Site.objects.get_current().domain, obj.get_absolute_url()) 214 214 'http://example.com/mymodel/objects/3/' 215 216 Caching the current ``Site`` object 217 =================================== 218 219 **New in Django development version** 220 221 As 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 223 little cleverer than that: on the first request, the current site is cached, and 224 any subsequent call returns the cached data instead of hitting the database. 225 226 If for any reason you want to force a database query, you can tell Django to 227 clear 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() 215 240 216 241 The ``CurrentSiteManager`` django/branches/queryset-refactor/docs/templates_python.txt
r6332 r6334 643 643 return value.lower() 644 644 645 Template filters whichexpect strings646 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~647 648 If you're writing a template filter whichonly expects a string as the first649 argument, you should use the includeddecorator ``stringfilter``. This will650 convert an object to it 's string value before being passed to your function::645 Template filters that expect strings 646 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 647 648 If you're writing a template filter that only expects a string as the first 649 argument, you should use the decorator ``stringfilter``. This will 650 convert an object to its string value before being passed to your function:: 651 651 652 652 from django.template.defaultfilters import stringfilter … … 655 655 def lower(value): 656 656 return value.lower() 657 658 This way, you'll be able to pass, say, an integer to this filter, and it 659 won't cause an ``AttributeError`` (because integers don't have ``lower()`` 660 methods). 657 661 658 662 Registering a custom filters django/branches/queryset-refactor/docs/templates.txt
r6332 r6334 1432 1432 perspective -- how it works and how to extend it. 1433 1433 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 84 84 "GET a URL that redirects elsewhere" 85 85 response = self.client.get('/test_client/redirect_view/') 86 87 86 # 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/') 89 93 90 94 def test_redirect_with_query(self): … … 93 97 94 98 # 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') 96 100 97 101 def test_permanent_redirect(self): 98 102 "GET a URL that redirects permanently elsewhere" 99 103 response = self.client.get('/test_client/permanent_redirect_view/') 100 101 104 # 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) 103 111 104 112 def test_redirect_to_strange_location(self): … … 108 116 # Check that the response was a 302, and that 109 117 # 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) 111 119 112 120 def test_notfound_response(self): … … 232 240 # Get the page without logging in. Should result in 302. 233 241 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/') 235 243 236 244 # Log in 237 245 login = self.client.login(username='testclient', password='password') 238 self. assertTrue(login, 'Could not log in')246 self.failUnless(login, 'Could not log in') 239 247 240 248 # Request a page that requires a login … … 270 278 # Request a page that requires a login 271 279 response = self.client.get('/test_client/login_protected_view/') 272 self.assertRedirects(response, ' /accounts/login/?next=/test_client/login_protected_view/') <
