Django

Code

Changeset 6332

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

queryset-refactor: Merged to [6155]

Files:

Legend:

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

    r6331 r6332  
    128128    glin@seznam.cz 
    129129    martin.glueck@gmail.com 
     130    Artyom Gnilov <boobsd@gmail.com> 
    130131    GomoX <gomo@datafull.com> 
    131132    Mario Gonzalez <gonzalemario@gmail.com> 
     
    241242    Michael Radziej <mir@noris.de> 
    242243    Amit Ramon <amit.ramon@gmail.com> 
     244    Philippe Raoult <philippe.raoult@n2nsoft.com> 
    243245    Massimiliano Ravelli <massimiliano.ravelli@gmail.com> 
    244246    Brian Ray <http://brianray.chipy.org/> 
  • django/branches/queryset-refactor/django/contrib/admin/media/js/urlify.js

    r5853 r6332  
    4444    'Я':'Ya' 
    4545} 
     46var UKRAINIAN_MAP = { 
     47    'Є':'Ye', 'І':'I', 'Ї':'Yi', 'Ґ':'G', 'є':'ye', 'і':'i', 'ї':'yi', 'ґ':'g' 
     48} 
    4649var CZECH_MAP = { 
    4750    'č':'c', 'ď':'d', 'ě':'e', 'ň': 'n', 'ř':'r', 'Å¡':'s', 'Å¥':'t', 'ů':'u', 
     
    5558ALL_DOWNCODE_MAPS[3]=TURKISH_MAP 
    5659ALL_DOWNCODE_MAPS[4]=RUSSIAN_MAP 
    57 ALL_DOWNCODE_MAPS[5]=CZECH_MAP 
     60ALL_DOWNCODE_MAPS[5]=UKRAINIAN_MAP 
     61ALL_DOWNCODE_MAPS[6]=CZECH_MAP 
    5862 
    5963var Downcoder = new Object(); 
  • django/branches/queryset-refactor/django/contrib/admin/templates/admin/change_list_results.html

    r1791 r6332  
    1111<tbody> 
    1212{% 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> 
    1414{% endfor %} 
    1515</tbody> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_day.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_homepage.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_main.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_month.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/calendar_year.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/choice_detail.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/choice_list.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_detail.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_homepage.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/fieldchoice_list.html

    r5947 r6332  
    1111<ul class="objectlist"> 
    1212{% 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> 
    1414{% endfor %} 
    1515</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/homepage.html

    r5947 r6332  
    88 
    99{% for model in model_list %} 
    10   <div class="modelgroup {% cycle even,odd %}"> 
     10  <div class="modelgroup {% cycle 'even' 'odd' %}"> 
    1111          <h2><a href="{{ model.url }}">{{ model.verbose_name_plural|capfirst }}</a></h2> 
    1212                <p> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/model_detail.html

    r5947 r6332  
    1313<ul class="objectlist"> 
    1414{% 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> 
    1616{% endfor %} 
    1717</ul> 
  • django/branches/queryset-refactor/django/contrib/databrowse/templates/databrowse/object_detail.html

    r5947 r6332  
    1111<table class="objectinfo"> 
    1212{% for field in object.fields %} 
    13 <tr class="{% cycle odd,even %}"> 
     13<tr class="{% cycle 'odd' 'even' %}"> 
    1414<th>{{ field.field.verbose_name|capfirst }}</th> 
    1515<td> 
     
    3030  <ul class="objectlist"> 
    3131    {% 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> 
    3333    {% endfor %} 
    3434  </ul> 
  • django/branches/queryset-refactor/django/core/paginator.py

    r4041 r6332  
    2121        self.orphans = orphans 
    2222        self._hits = self._pages = None 
     23        self._page_range = None 
    2324 
    2425    def validate_page_number(self, page_number): 
     
    8485            self._pages = hits // self.num_per_page + 1 
    8586        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 
    8696 
    8797    hits = property(_get_hits) 
    8898    pages = property(_get_pages) 
     99    page_range = property(_get_page_range) 
  • django/branches/queryset-refactor/django/db/models/fields/__init__.py

    r6116 r6332  
    856856    def formfield(self, **kwargs): 
    857857        defaults = {'form_class': forms.ImageField} 
     858        defaults.update(kwargs) 
    858859        return super(ImageField, self).formfield(**defaults) 
    859860 
  • django/branches/queryset-refactor/django/newforms/fields.py

    r6096 r6332  
    336336            ugettext(u'Enter a valid e-mail address.'), *args, **kwargs) 
    337337 
    338 url_re = re.compile( 
    339     r'^https?://' # http:// or https:// 
    340     r'(?:[A-Z0-9-]+\.)+[A-Z]{2,6}' # domain 
    341     r'(?::\d+)?' # optional port 
    342     r'(?:/?|/\S+)$', re.IGNORECASE) 
    343  
    344338try: 
    345339    from django.conf import settings 
     
    399393            raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image.")) 
    400394        return f 
     395 
     396url_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) 
    401403 
    402404class URLField(RegexField): 
  • django/branches/queryset-refactor/django/newforms/forms.py

    r5819 r6332  
    5858    # information. Any improvements to the form API should be made to *this* 
    5959    # 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): 
    6162        self.is_bound = data is not None or files is not None 
    6263        self.data = data or {} 
     
    6566        self.prefix = prefix 
    6667        self.initial = initial or {} 
     68        self.error_class = error_class 
    6769        self._errors = None # Stores the errors after clean() has been called. 
    6870 
     
    118120        for name, field in self.fields.items(): 
    119121            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. 
    121123            if bf.is_hidden: 
    122124                if bf_errors: 
     
    169171        are none. 
    170172        """ 
    171         return self.errors.get(NON_FIELD_ERRORS, ErrorList()) 
     173        return self.errors.get(NON_FIELD_ERRORS, self.error_class()) 
    172174 
    173175    def full_clean(self): 
     
    242244        if there are none. 
    243245        """ 
    244         return self.form.errors.get(self.name, ErrorList()) 
     246        return self.form.errors.get(self.name, self.form.error_class()) 
    245247    errors = property(_errors) 
    246248 
  • django/branches/queryset-refactor/django/template/defaulttags.py

    r5927 r6332  
    3131        self.counter += 1 
    3232        value = self.cyclevars[self.counter % self.cyclevars_len] 
     33        value = resolve_variable(value, context) 
    3334        if self.variable_name: 
    3435            context[self.variable_name] = value 
     
    404405 
    405406        {% for o in some_list %} 
    406             <tr class="{% cycle row1,row2 %}"> 
     407            <tr class="{% cycle 'row1' 'row2' %}"> 
    407408                ... 
    408409            </tr> 
     
    412413    it, then use that name each sucessive time through:: 
    413414 
    414             <tr class="{% cycle row1,row2,row3 as rowcolors %}">...</tr> 
     415            <tr class="{% cycle 'row1' 'row2' 'row3' as rowcolors %}">...</tr> 
    415416            <tr class="{% cycle rowcolors %}">...</tr> 
    416417            <tr class="{% cycle rowcolors %}">...</tr> 
    417418 
    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. 
    420422    """ 
    421423 
    422424    # 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 one 
     425    # is, the node object returned from {% cycle a b c as name %} and the one 
    424426    # returned from {% cycle name %} are the exact same object.  This shouldn't 
    425427    # cause problems (heh), but if it does, now you know. 
     
    430432    # *all* templates. 
    431433 
    432     args = token.contents.split() 
     434    args = token.split_contents() 
     435 
    433436    if len(args) < 2: 
    434         raise TemplateSyntaxError("'Cycle' statement requires 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 blanks 
    439         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 
    443446        name = args[1] 
    444447        if not hasattr(parser, '_namedCycleNodes'): 
    445448            raise TemplateSyntaxError("No named cycles in template: '%s' is not defined" % name) 
    446         if name not in parser._namedCycleNodes: 
     449        if not name in parser._namedCycleNodes: 
    447450            raise TemplateSyntaxError("Named cycle '%s' does not exist" % name) 
    448451        return parser._namedCycleNodes[name] 
    449452 
    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) 
    458456        if not hasattr(parser, '_namedCycleNodes'): 
    459457            parser._namedCycleNodes = {} 
    460  
    461458        parser._namedCycleNodes[name] = node 
    462         return node 
    463  
    464459    else: 
    465         raise TemplateSyntaxError("Invalid arguments to 'cycle': %s" % args) 
     460        node = CycleNode(args[1:]) 
     461    return node 
    466462cycle = register.tag(cycle) 
    467463 
  • django/branches/queryset-refactor/django/views/generic/list_detail.py

    r5877 r6332  
    4040            the result number of the first object in the 
    4141            object_list (1-indexed) 
     42        page_range: 
     43            A list of the page numbers (1-indexed). 
    4244    """ 
    4345    if extra_context is None: extra_context = {} 
     
    4850            page = request.GET.get('page', 1) 
    4951        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: 
    5463                object_list = [] 
    5564            else: 
     
    5968            'is_paginated': paginator.pages > 1, 
    6069            '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), 
    6877            'pages': paginator.pages, 
    6978            'hits' : paginator.hits, 
     79            'page_range' : paginator.page_range 
    7080        }, context_processors) 
    7181    else: 
  • django/branches/queryset-refactor/docs/generic_views.txt

    r5877 r6332  
    689689      displayed per page. If this is given, the view will paginate objects with 
    690690      ``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. 
    694693 
    695694    * ``template_name``: The full name of a template to use in rendering the 
     
    766765      page. 
    767766 
     767    * ``page_range``: A list of the page numbers that are available. This 
     768      is 1-based. 
     769 
    768770Notes on pagination 
    769771~~~~~~~~~~~~~~~~~~~ 
     
    778780 
    779781    * 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:: 
    781783 
    782784        /objects/?page=3 
    783785 
    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 
     790These values and lists are is 1-based, not 0-based, so the first page would be 
     791represented 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 
     796This allows you to access the final page of results without first having to  
     797determine how many pages there are. 
     798 
     799Note that ``page`` *must* be either a valid page number or the value ``last``; 
     800any other value for ``page`` will result in a 404 error. 
    786801 
    787802``django.views.generic.list_detail.object_detail`` 
  • django/branches/queryset-refactor/docs/newforms.txt

    r6330 r6332  
    552552    <p>Message: <input type="text" name="message" value="Hi there" /></p> 
    553553    <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 
     557Customizing the error list format 
     558~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     559 
     560By default, forms use ``django.newforms.util.ErrorList`` to format validation 
     561errors. If you'd like to use an alternate class for displaying errors, you can 
     562pass 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> 
    554577    <p>Sender: <input type="text" name="sender" value="invalid e-mail address" /></p> 
    555578    <p>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></p> 
     
    18941917this example has an ``else`` clause that implements the default behavior. 
    18951918 
     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 
    18961930Finding the model associated with a form 
    18971931~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • django/branches/queryset-refactor/docs/request_response.txt

    r5846 r6332  
    184184    * ``__getitem__(key)`` -- Returns the value for the given key. If the key 
    185185      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``). 
    186189 
    187190    * ``__setitem__(key, value)`` -- Sets the given key to ``[value]`` 
  • django/branches/queryset-refactor/docs/sites.txt

    r5803 r6332  
    317317      the current ``Site`` object when calculating an object's URL. 
    318318 
     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 
    319322.. _redirects framework: ../redirects/ 
    320323.. _flatpages framework: ../flatpages/ 
  • django/branches/queryset-refactor/docs/templates_python.txt

    r5927 r6332  
    643643        return value.lower() 
    644644 
    645 When you've written your filter definition, you need to register it with 
     645Template filters which expect strings 
     646~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     647 
     648If you're writing a template filter which only expects a string as the first 
     649argument, you should use the included decorator ``stringfilter``. This will 
     650convert 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 
     658Registering a custom filters 
     659~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     660 
     661Once you've written your filter definition, you need to register it with 
    646662your ``Library`` instance, to make it available to Django's template language:: 
    647663 
     
    659675 
    660676    @register.filter(name='cut') 
     677    @stringfilter 
    661678    def cut(value, arg): 
    662679        return value.replace(arg, '') 
    663680 
    664681    @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, Django 
    669 will use the function's name as the filter name. 
    670  
    671 Template filters which expect strings 
    672 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    673 If you are writing a template filter which only expects a string as the first 
    674 argument, you should use the included decorator ``stringfilter`` which will convert 
    675 an object to it's string value before being passed to your function:: 
    676  
    677     from django.template.defaultfilters import stringfilter 
    678  
    679682    @stringfilter 
    680683    def lower(value): 
    681684        return value.lower() 
     685 
     686If you leave off the ``name`` argument, as in the second example above, Django 
     687will use the function's name as the filter name. 
    682688 
    683689Writing custom template tags 
  • django/branches/queryset-refactor/docs/templates.txt

    r6070 r6332  
    367367~~~~~ 
    368368 
    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** 
     370Cycle among the given strings or variables each time this tag is encountered. 
     371 
     372Within a loop, cycles among the given strings/variables each time through the 
     373loop:: 
    372374 
    373375    {% for o in some_list %} 
    374         <tr class="{% cycle row1,row2 %}"> 
     376        <tr class="{% cycle 'row1' 'row2' rowvar %}"> 
    375377            ... 
    376378        </tr> 
    377379    {% endfor %} 
    378  
     380  
    379381Outside of a loop, give the values a unique name the first time you call it, 
    380382then use that name each successive time through:: 
    381383 
    382         <tr class="{% cycle row1,row2,row3 as rowcolors %}">...</tr> 
     384        <tr class="{% cycle 'row1' 'row2' rowvar as rowcolors %}">...</tr> 
    383385        <tr class="{% cycle rowcolors %}">...</tr> 
    384386        <tr class="{% cycle rowcolors %}">...</tr> 
    385387 
    386 You can use any number of values, separated by commas. Make sure not to put 
    387 spaces between the values -- only commas. 
     388You can use any number of values, separated by spaces. Values enclosed in  
     389single (') or double quotes (") are treated as string literals, while values  
     390without quotes are assumed to refer to context variables.  
     391 
     392You can also separate values with commas:: 
     393 
     394    {% cycle row1,row2,row3 %} 
     395     
     396In this syntax, each value will be interpreted as literal text. The  
     397comma-based syntax exists for backwards-compatibility, and should not be  
     398used for new projects. 
    388399 
    389400debug 
  • django/branches/queryset-refactor/docs/testing.txt

    r6039 r6332  
    570570The ``get()`` and ``post()`` methods both return a ``Response`` object. This 
    571571``Response`` object is *not* the same as the ``HttpResponse`` object returned 
    572 Django views; this object is simpler and has some additional data useful for 
    573 tests
     572Django views; the test response object has some additional data useful for 
     573test code to verify
    574574 
    575575Specifically, a ``Response`` object has the following attributes: 
     
    583583    ``content``      The body of the response, as a string. This is the final 
    584584                     page content as rendered by the view, or any error 
    585                      message (such as the URL for a 302 redirect)
     585                     message
    586586 
    587587    ``context``      The template ``Context`` instance that was used to render 
     
    591591                     ``context`` will be a list of ``Context`` 
    592592                     objects, in the order in which they were rendered. 
     593 
     594    ``headers``      The HTTP headers of the response. This is a dictionary. 
    593595 
    594596    ``request``      The request data that stimulated the response. 
  • django/branches/queryset-refactor/tests/modeltests/pagination/models.py

    r5876 r6332  
    7878>>> paginator.pages 
    79792 
     80 
     81# The paginator can provide a list of all available pages 
     82>>> paginator.page_range 
     83[1, 2] 
    8084"""} 
  • django/branches/queryset-refactor/tests/regressiontests/forms/localflavor.py

    r6331 r6332  
    15151515>>> s.render('provinces', 'OV') 
    15161516u'<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') 
     1523u'<select name="provincias">\n<option va