Changeset 6332
- Timestamp:
- 09/15/07 16:21:37 (10 months ago)
- Files:
-
- django/branches/queryset-refactor/AUTHORS (modified) (2 diffs)
- django/branches/queryset-refactor/django/contrib/admin/media/js/urlify.js (modified) (2 diffs)
- django/branches/queryset-refactor/django/contrib/admin/templates/admin/change_list_results.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_day.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_homepage.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_main.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_month.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_year.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/choice_detail.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/choice_list.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_detail.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_homepage.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_list.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/homepage.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/model_detail.html (modified) (1 diff)
- django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/object_detail.html (modified) (2 diffs)
- django/branches/queryset-refactor/django/contrib/localflavor/ar (copied) (copied from django/trunk/django/contrib/localflavor/ar)
- django/branches/queryset-refactor/django/contrib/localflavor/ar/ar_provinces.py (copied) (copied from django/trunk/django/contrib/localflavor/ar/ar_provinces.py)
- django/branches/queryset-refactor/django/contrib/localflavor/ar/forms.py (copied) (copied from django/trunk/django/contrib/localflavor/ar/forms.py)
- django/branches/queryset-refactor/django/contrib/localflavor/ar/__init__.py (copied) (copied from django/trunk/django/contrib/localflavor/ar/__init__.py)
- django/branches/queryset-refactor/django/core/paginator.py (modified) (2 diffs)
- django/branches/queryset-refactor/django/db/models/fields/__init__.py (modified) (1 diff)
- django/branches/queryset-refactor/django/newforms/fields.py (modified) (2 diffs)
- django/branches/queryset-refactor/django/newforms/forms.py (modified) (5 diffs)
- django/branches/queryset-refactor/django/template/defaulttags.py (modified) (4 diffs)
- django/branches/queryset-refactor/django/views/generic/list_detail.py (modified) (3 diffs)
- django/branches/queryset-refactor/docs/generic_views.txt (modified) (3 diffs)
- django/branches/queryset-refactor/docs/newforms.txt (modified) (2 diffs)
- django/branches/queryset-refactor/docs/request_response.txt (modified) (1 diff)
- 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/docs/testing.txt (modified) (3 diffs)
- django/branches/queryset-refactor/tests/modeltests/pagination/models.py (modified) (1 diff)
- django/branches/queryset-refactor/tests/regressiontests/forms/localflavor.py (modified) (1 diff)
- django/branches/queryset-refactor/tests/regressiontests/forms/tests.py (modified) (5 diffs)
- django/branches/queryset-refactor/tests/regressiontests/forms/util.py (copied) (copied from django/trunk/tests/regressiontests/forms/util.py)
- django/branches/queryset-refactor/tests/regressiontests/templates/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/AUTHORS
r6331 r6332 128 128 glin@seznam.cz 129 129 martin.glueck@gmail.com 130 Artyom Gnilov <boobsd@gmail.com> 130 131 GomoX <gomo@datafull.com> 131 132 Mario Gonzalez <gonzalemario@gmail.com> … … 241 242 Michael Radziej <mir@noris.de> 242 243 Amit Ramon <amit.ramon@gmail.com> 244 Philippe Raoult <philippe.raoult@n2nsoft.com> 243 245 Massimiliano Ravelli <massimiliano.ravelli@gmail.com> 244 246 Brian Ray <http://brianray.chipy.org/> django/branches/queryset-refactor/django/contrib/admin/media/js/urlify.js
r5853 r6332 44 44 'Я':'Ya' 45 45 } 46 var UKRAINIAN_MAP = { 47 'Ð':'Ye', 'Ð':'I', 'Ð':'Yi', 'Ò':'G', 'Ñ':'ye', 'Ñ':'i', 'Ñ':'yi', 'Ò':'g' 48 } 46 49 var CZECH_MAP = { 47 50 'Ä':'c', 'Ä':'d', 'Ä':'e', 'Å': 'n', 'Å':'r', 'Å¡':'s', 'Å¥':'t', 'ů':'u', … … 55 58 ALL_DOWNCODE_MAPS[3]=TURKISH_MAP 56 59 ALL_DOWNCODE_MAPS[4]=RUSSIAN_MAP 57 ALL_DOWNCODE_MAPS[5]=CZECH_MAP 60 ALL_DOWNCODE_MAPS[5]=UKRAINIAN_MAP 61 ALL_DOWNCODE_MAPS[6]=CZECH_MAP 58 62 59 63 var Downcoder = new Object(); django/branches/queryset-refactor/django/contrib/admin/templates/admin/change_list_results.html
r1791 r6332 11 11 <tbody> 12 12 {% for result in results %} 13 <tr class="{% cycle row1,row2%}">{% for item in result %}{{ item }}{% endfor %}</tr>13 <tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr> 14 14 {% endfor %} 15 15 </tbody> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_day.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_homepage.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for field in field_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ field.name }}/">{{ model.verbose_name_plural|capfirst }} by {{ field.verbose_name }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ field.name }}/">{{ model.verbose_name_plural|capfirst }} by {{ field.verbose_name }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_main.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for year in date_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ year.year }}/">{{ year.year }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ year.year }}/">{{ year.year }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_month.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_year.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for month in date_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ month|date:"M"|lower }}/">{{ month|date:"F" }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ month|date:"M"|lower }}/">{{ month|date:"F" }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/choice_detail.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/choice_list.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for choice in field.choices %} 13 <li class="{% cycle odd,even%}"><a href="{{ choice.url }}">{{ choice.label|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ choice.url }}">{{ choice.label|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_detail.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_homepage.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for field in field_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ field.name }}/">{{ model.verbose_name_plural|capfirst }} by {{ field.verbose_name }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ field.name }}/">{{ model.verbose_name_plural|capfirst }} by {{ field.verbose_name }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_list.html
r5947 r6332 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object|iriencode }}/">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object|iriencode }}/">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/homepage.html
r5947 r6332 8 8 9 9 {% for model in model_list %} 10 <div class="modelgroup {% cycle even,odd%}">10 <div class="modelgroup {% cycle 'even' 'odd' %}"> 11 11 <h2><a href="{{ model.url }}">{{ model.verbose_name_plural|capfirst }}</a></h2> 12 12 <p> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/model_detail.html
r5947 r6332 13 13 <ul class="objectlist"> 14 14 {% for object in model.objects %} 15 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>15 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 16 16 {% endfor %} 17 17 </ul> django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/object_detail.html
r5947 r6332 11 11 <table class="objectinfo"> 12 12 {% for field in object.fields %} 13 <tr class="{% cycle odd,even%}">13 <tr class="{% cycle 'odd' 'even' %}"> 14 14 <th>{{ field.field.verbose_name|capfirst }}</th> 15 15 <td> … … 30 30 <ul class="objectlist"> 31 31 {% for object in related_object.object_list %} 32 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>32 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 33 33 {% endfor %} 34 34 </ul> django/branches/queryset-refactor/django/core/paginator.py
r4041 r6332 21 21 self.orphans = orphans 22 22 self._hits = self._pages = None 23 self._page_range = None 23 24 24 25 def validate_page_number(self, page_number): … … 84 85 self._pages = hits // self.num_per_page + 1 85 86 return self._pages 87 88 def _get_page_range(self): 89 """ 90 Returns a 1-based range of pages for iterating through within 91 a template for loop. 92 """ 93 if self._page_range is None: 94 self._page_range = range(1, self._pages + 1) 95 return self._page_range 86 96 87 97 hits = property(_get_hits) 88 98 pages = property(_get_pages) 99 page_range = property(_get_page_range) django/branches/queryset-refactor/django/db/models/fields/__init__.py
r6116 r6332 856 856 def formfield(self, **kwargs): 857 857 defaults = {'form_class': forms.ImageField} 858 defaults.update(kwargs) 858 859 return super(ImageField, self).formfield(**defaults) 859 860 django/branches/queryset-refactor/django/newforms/fields.py
r6096 r6332 336 336 ugettext(u'Enter a valid e-mail address.'), *args, **kwargs) 337 337 338 url_re = re.compile(339 r'^https?://' # http:// or https://340 r'(?:[A-Z0-9-]+\.)+[A-Z]{2,6}' # domain341 r'(?::\d+)?' # optional port342 r'(?:/?|/\S+)$', re.IGNORECASE)343 344 338 try: 345 339 from django.conf import settings … … 399 393 raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image.")) 400 394 return f 395 396 url_re = re.compile( 397 r'^https?://' # http:// or https:// 398 r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain... 399 r'localhost|' #localhost... 400 r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip 401 r'(?::\d+)?' # optional port 402 r'(?:/?|/\S+)$', re.IGNORECASE) 401 403 402 404 class URLField(RegexField): django/branches/queryset-refactor/django/newforms/forms.py
r5819 r6332 58 58 # information. Any improvements to the form API should be made to *this* 59 59 # class, not to the Form class. 60 def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None): 60 def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, 61 initial=None, error_class=ErrorList): 61 62 self.is_bound = data is not None or files is not None 62 63 self.data = data or {} … … 65 66 self.prefix = prefix 66 67 self.initial = initial or {} 68 self.error_class = error_class 67 69 self._errors = None # Stores the errors after clean() has been called. 68 70 … … 118 120 for name, field in self.fields.items(): 119 121 bf = BoundField(self, field, name) 120 bf_errors = ErrorList([escape(error) for error in bf.errors]) # Escape and cache in local variable.122 bf_errors = self.error_class([escape(error) for error in bf.errors]) # Escape and cache in local variable. 121 123 if bf.is_hidden: 122 124 if bf_errors: … … 169 171 are none. 170 172 """ 171 return self.errors.get(NON_FIELD_ERRORS, ErrorList())173 return self.errors.get(NON_FIELD_ERRORS, self.error_class()) 172 174 173 175 def full_clean(self): … … 242 244 if there are none. 243 245 """ 244 return self.form.errors.get(self.name, ErrorList())246 return self.form.errors.get(self.name, self.form.error_class()) 245 247 errors = property(_errors) 246 248 django/branches/queryset-refactor/django/template/defaulttags.py
r5927 r6332 31 31 self.counter += 1 32 32 value = self.cyclevars[self.counter % self.cyclevars_len] 33 value = resolve_variable(value, context) 33 34 if self.variable_name: 34 35 context[self.variable_name] = value … … 404 405 405 406 {% for o in some_list %} 406 <tr class="{% cycle row1,row2%}">407 <tr class="{% cycle 'row1' 'row2' %}"> 407 408 ... 408 409 </tr> … … 412 413 it, then use that name each sucessive time through:: 413 414 414 <tr class="{% cycle row1,row2,row3as rowcolors %}">...</tr>415 <tr class="{% cycle 'row1' 'row2' 'row3' as rowcolors %}">...</tr> 415 416 <tr class="{% cycle rowcolors %}">...</tr> 416 417 <tr class="{% cycle rowcolors %}">...</tr> 417 418 418 You can use any number of values, seperated by commas. Make sure not to 419 put spaces between the values -- only commas. 419 You can use any number of values, seperated by spaces. Commas can also 420 be used to separate values; if a comma is used, the cycle values are 421 interpreted as literal strings. 420 422 """ 421 423 422 424 # Note: This returns the exact same node on each {% cycle name %} call; that 423 # is, the node object returned from {% cycle a ,b,c as name %} and the one425 # is, the node object returned from {% cycle a b c as name %} and the one 424 426 # returned from {% cycle name %} are the exact same object. This shouldn't 425 427 # cause problems (heh), but if it does, now you know. … … 430 432 # *all* templates. 431 433 432 args = token.contents.split() 434 args = token.split_contents() 435 433 436 if len(args) < 2: 434 raise TemplateSyntaxError("' Cycle' statementrequires at least two arguments")435 436 elif len(args) == 2 and ","in args[1]:437 # {% cycle a,b,c%}438 cyclevars = [v for v in args[1].split(",") if v] # split and kill blanks439 return CycleNode(cyclevars)440 # {% cycle name %} 441 442 elif len(args) == 2:437 raise TemplateSyntaxError("'cycle' tag requires at least two arguments") 438 439 if ',' in args[1]: 440 # Backwards compatibility: {% cycle a,b %} or {% cycle a,b as foo %} 441 # case. 442 args[1:2] = ['"%s"' % arg for arg in args[1].split(",")] 443 444 if len(args) == 2: 445 # {% cycle foo %} case 443 446 name = args[1] 444 447 if not hasattr(parser, '_namedCycleNodes'): 445 448 raise TemplateSyntaxError("No named cycles in template: '%s' is not defined" % name) 446 if n ame notin parser._namedCycleNodes:449 if not name in parser._namedCycleNodes: 447 450 raise TemplateSyntaxError("Named cycle '%s' does not exist" % name) 448 451 return parser._namedCycleNodes[name] 449 452 450 elif len(args) == 4: 451 # {% cycle a,b,c as name %} 452 if args[2] != 'as': 453 raise TemplateSyntaxError("Second 'cycle' argument must be 'as'") 454 cyclevars = [v for v in args[1].split(",") if v] # split and kill blanks 455 name = args[3] 456 node = CycleNode(cyclevars, name) 457 453 if len(args) > 4 and args[-2] == 'as': 454 name = args[-1] 455 node = CycleNode(args[1:-2], name) 458 456 if not hasattr(parser, '_namedCycleNodes'): 459 457 parser._namedCycleNodes = {} 460 461 458 parser._namedCycleNodes[name] = node 462 return node463 464 459 else: 465 raise TemplateSyntaxError("Invalid arguments to 'cycle': %s" % args) 460 node = CycleNode(args[1:]) 461 return node 466 462 cycle = register.tag(cycle) 467 463 django/branches/queryset-refactor/django/views/generic/list_detail.py
r5877 r6332 40 40 the result number of the first object in the 41 41 object_list (1-indexed) 42 page_range: 43 A list of the page numbers (1-indexed). 42 44 """ 43 45 if extra_context is None: extra_context = {} … … 48 50 page = request.GET.get('page', 1) 49 51 try: 50 page = int(page) 51 object_list = paginator.get_page(page - 1) 52 except (InvalidPage, ValueError): 53 if page == 1 and allow_empty: 52 page_number = int(page) 53 except ValueError: 54 if page == 'last': 55 page_number = paginator.pages 56 else: 57 # Page is not 'last', nor can it be converted to an int 58 raise Http404 59 try: 60 object_list = paginator.get_page(page_number - 1) 61 except InvalidPage: 62 if page_number == 1 and allow_empty: 54 63 object_list = [] 55 64 else: … … 59 68 'is_paginated': paginator.pages > 1, 60 69 'results_per_page': paginate_by, 61 'has_next': paginator.has_next_page(page - 1),62 'has_previous': paginator.has_previous_page(page - 1),63 'page': page ,64 'next': page + 1,65 'previous': page - 1,66 'last_on_page': paginator.last_on_page(page - 1),67 'first_on_page': paginator.first_on_page(page - 1),70 'has_next': paginator.has_next_page(page_number - 1), 71 'has_previous': paginator.has_previous_page(page_number - 1), 72 'page': page_number, 73 'next': page_number + 1, 74 'previous': page_number - 1, 75 'last_on_page': paginator.last_on_page(page_number - 1), 76 'first_on_page': paginator.first_on_page(page_number - 1), 68 77 'pages': paginator.pages, 69 78 'hits' : paginator.hits, 79 'page_range' : paginator.page_range 70 80 }, context_processors) 71 81 else: django/branches/queryset-refactor/docs/generic_views.txt
r5877 r6332 689 689 displayed per page. If this is given, the view will paginate objects with 690 690 ``paginate_by`` objects per page. The view will expect either a ``page`` 691 query string parameter (via ``GET``) containing a 1-based page 692 number, or a ``page`` variable specified in the URLconf. See 693 "Notes on pagination" below. 691 query string parameter (via ``GET``) or a ``page`` variable specified in 692 the URLconf. See "Notes on pagination" below. 694 693 695 694 * ``template_name``: The full name of a template to use in rendering the … … 766 765 page. 767 766 767 * ``page_range``: A list of the page numbers that are available. This 768 is 1-based. 769 768 770 Notes on pagination 769 771 ~~~~~~~~~~~~~~~~~~~ … … 778 780 779 781 * Pass the page number via the ``page`` query-string parameter. For 780 example, a URL would look like this: 782 example, a URL would look like this:: 781 783 782 784 /objects/?page=3 783 785 784 In both cases, ``page`` is 1-based, not 0-based, so the first page would be 785 represented as page ``1``. 786 * To loop over all the available page numbers, use the ``page_range`` 787 variable. You can iterate over the list provided by ``page_range`` 788 to create a link to every page of results. 789 790 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 792 ``last`` as a value for ``page``:: 793 794 /objects/?page=last 795 796 This allows you to access the final page of results without first having to 797 determine how many pages there are. 798 799 Note that ``page`` *must* be either a valid page number or the value ``last``; 800 any other value for ``page`` will result in a 404 error. 786 801 787 802 ``django.views.generic.list_detail.object_detail`` django/branches/queryset-refactor/docs/newforms.txt
r6330 r6332 552 552 <p>Message: <input type="text" name="message" value="Hi there" /></p> 553 553 <p><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul></p> 554 <p>Sender: <input type="text" name="sender" value="invalid e-mail address" /></p> 555 <p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p> 556 557 Customizing the error list format 558 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 559 560 By default, forms use ``django.newforms.util.ErrorList`` to format validation 561 errors. If you'd like to use an alternate class for displaying errors, you can 562 pass that in at construction time:: 563 564 >>> from django.newforms.util import ErrorList 565 >>> class DivErrorList(ErrorList): 566 ... def __unicode__(self): 567 ... return self.as_divs() 568 ... def as_divs(self): 569 ... if not self: return u'' 570 ... return u'<div class="errorlist">%s</div>' % ''.join([u'<div class="error">%s</div>' % e for e in self]) 571 >>> f = ContactForm(data, auto_id=False, error_class=DivErrorList) 572 >>> f.as_p() 573 <div class="errorlist"><div class="error">This field is required.</div></div> 574 <p>Subject: <input type="text" name="subject" maxlength="100" /></p> 575 <p>Message: <input type="text" name="message" value="Hi there" /></p> 576 <div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div> 554 577 <p>Sender: <input type="text" name="sender" value="invalid e-mail address" /></p> 555 578 <p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p> … … 1894 1917 this example has an ``else`` clause that implements the default behavior. 1895 1918 1919 .. warning:: 1920 The field that is passed into the ``formfield_callback`` function in 1921 ``form_for_model()`` and ``form_for_instance`` is the field instance from 1922 your model's class. You **must not** alter that object at all; treat it 1923 as read-only! 1924 1925 If you make any alterations to that object, it will affect any future 1926 users of the model class, because you will have changed the field object 1927 used to construct the class. This is almost certainly what you don't want 1928 to have happen. 1929 1896 1930 Finding the model associated with a form 1897 1931 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ django/branches/queryset-refactor/docs/request_response.txt
r5846 r6332 184 184 * ``__getitem__(key)`` -- Returns the value for the given key. If the key 185 185 has more than one value, ``__getitem__()`` returns the last value. 186 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``). 186 189 187 190 * ``__setitem__(key, value)`` -- Sets the given key to ``[value]`` django/branches/queryset-refactor/docs/sites.txt
r5803 r6332 317 317 the current ``Site`` object when calculating an object's URL. 318 318 319 * In the admin framework, the ''view on site'' link uses the current 320 ``Site`` to work out the domain for the site that it will redirect to. 321 319 322 .. _redirects framework: ../redirects/ 320 323 .. _flatpages framework: ../flatpages/ django/branches/queryset-refactor/docs/templates_python.txt
r5927 r6332 643 643 return value.lower() 644 644 645 When you've written your filter definition, you need to register it with 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:: 651 652 from django.template.defaultfilters import stringfilter 653 654 @stringfilter 655 def lower(value): 656 return value.lower() 657 658 Registering a custom filters 659 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 660 661 Once you've written your filter definition, you need to register it with 646 662 your ``Library`` instance, to make it available to Django's template language:: 647 663 … … 659 675 660 676 @register.filter(name='cut') 677 @stringfilter 661 678 def cut(value, arg): 662 679 return value.replace(arg, '') 663 680 664 681 @register.filter 665 def lower(value):666 return value.lower()667 668 If you leave off the ``name`` argument, as in the second example above, Django669 will use the function's name as the filter name.670 671 Template filters which expect strings672 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~673 If you are writing a template filter which only expects a string as the first674 argument, you should use the included decorator ``stringfilter`` which will convert675 an object to it's string value before being passed to your function::676 677 from django.template.defaultfilters import stringfilter678 679 682 @stringfilter 680 683 def lower(value): 681 684 return value.lower() 685 686 If you leave off the ``name`` argument, as in the second example above, Django 687 will use the function's name as the filter name. 682 688 683 689 Writing custom template tags django/branches/queryset-refactor/docs/templates.txt
r6070 r6332 367 367 ~~~~~ 368 368 369 Cycle among the given strings each time this tag is encountered. 370 371 Within a loop, cycles among the given strings each time through the loop:: 369 **Changed in Django development version** 370 Cycle among the given strings or variables each time this tag is encountered. 371 372 Within a loop, cycles among the given strings/variables each time through the 373 loop:: 372 374 373 375 {% for o in some_list %} 374 <tr class="{% cycle row1,row2%}">376 <tr class="{% cycle 'row1' 'row2' rowvar %}"> 375 377 ... 376 378 </tr> 377 379 {% endfor %} 378 380 379 381 Outside of a loop, give the values a unique name the first time you call it, 380 382 then use that name each successive time through:: 381 383 382 <tr class="{% cycle row1,row2,row3as rowcolors %}">...</tr>384 <tr class="{% cycle 'row1' 'row2' rowvar as rowcolors %}">...</tr> 383 385 <tr class="{% cycle rowcolors %}">...</tr> 384 386 <tr class="{% cycle rowcolors %}">...</tr> 385 387 386 You can use any number of values, separated by commas. Make sure not to put 387 spaces between the values -- only commas. 388 You can use any number of values, separated by spaces. Values enclosed in 389 single (') or double quotes (") are treated as string literals, while values 390 without quotes are assumed to refer to context variables. 391 392 You can also separate values with commas:: 393 394 {% cycle row1,row2,row3 %} 395 396 In this syntax, each value will be interpreted as literal text. The 397 comma-based syntax exists for backwards-compatibility, and should not be 398 used for new projects. 388 399 389 400 debug django/branches/queryset-refactor/docs/testing.txt
r6039 r6332 570 570 The ``get()`` and ``post()`` methods both return a ``Response`` object. This 571 571 ``Response`` object is *not* the same as the ``HttpResponse`` object returned 572 Django views; th is object is simpler andhas some additional data useful for573 test s.572 Django views; the test response object has some additional data useful for 573 test code to verify. 574 574 575 575 Specifically, a ``Response`` object has the following attributes: … … 583 583 ``content`` The body of the response, as a string. This is the final 584 584 page content as rendered by the view, or any error 585 message (such as the URL for a 302 redirect).585 message. 586 586 587 587 ``context`` The template ``Context`` instance that was used to render … … 591 591 ``context`` will be a list of ``Context`` 592 592 objects, in the order in which they were rendered. 593 594 ``headers`` The HTTP headers of the response. This is a dictionary. 593 595 594 596 ``request`` The request data that stimulated the response. django/branches/queryset-refactor/tests/modeltests/pagination/models.py
r5876 r6332 78 78 >>> paginator.pages 79 79 2 80 81 # The paginator can provide a list of all available pages 82 >>> paginator.page_range 83 [1, 2] 80 84 """} django/branches/queryset-refactor/tests/regressiontests/forms/localflavor.py
r6331 r6332 1515 1515 >>> s.render('provinces', 'OV') 1516 1516 u'<select name="provinces">\n<option value="DR">Drente</option>\n<option value="FL">Flevoland</option>\n<option value="FR">Friesland</option>\n<option value="GL">Gelderland</option>\n<option value="GR">Groningen</option>\n<option value="LB">Limburg</option>\n<option value="NB">Noord-Brabant</option>\n<option value="NH">Noord-Holland</option>\n<option value="OV" selected="selected">Overijssel</option>\n<option value="UT">Utrecht</option>\n<option value="ZE">Zeeland</option>\n<option value="ZH">Zuid-Holland</option>\n</select>' 1517 1518 # ARProvinceField ############################################################# 1519 1520 >>> from django.contrib.localflavor.ar.forms import ARProvinceSelect 1521 >>> f = ARProvinceSelect() 1522 >>> f.render('provincias', 'A') 1523 u'<select name="provincias">\n<option va
