Django

Code

Changeset 6337

Show
Ignore:
Timestamp:
09/15/07 16:42:51 (1 year ago)
Author:
adrian
Message:

queryset-refactor: Merged to [6220]

Files:

Legend:

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

    r6335 r6337  
    233233    phil.h.smith@gmail.com 
    234234    Gustavo Picon 
     235    pigletto 
    235236    Luke Plant <http://lukeplant.me.uk/> 
    236237    plisk 
     
    263264    smurf@smurf.noris.de 
    264265    sopel 
     266    Leo Soto <leo.soto@gmail.com> 
    265267    Wiliam Alves de Souza <wiliamsouza83@gmail.com> 
    266268    Georgi Stanojevski <glisha@gmail.com> 
     
    275277    Aaron Swartz <http://www.aaronsw.com/> 
    276278    Ville Säävuori <http://www.unessa.net/> 
     279    Tyler Tarabula <tyler.tarabula@gmail.com> 
    277280    Tyson Tate <tyson@fallingbullets.com> 
    278281    Frank Tegtmeyer <fte@fte.to> 
  • django/branches/queryset-refactor/django/contrib/admin/media/css/widgets.css

    r2809 r6337  
    4444/* CALENDARS & CLOCKS */ 
    4545.calendarbox, .clockbox { margin:5px auto; font-size:11px; width:16em; text-align:center; background:white; position:relative; } 
    46 .clockbox { width:9em; } 
     46.clockbox { width:auto; } 
    4747.calendar { margin:0; padding: 0; } 
    4848.calendar table { margin:0; padding:0; border-collapse:collapse; background:white; width:99%; } 
  • django/branches/queryset-refactor/django/contrib/admin/media/js/admin/DateTimeShortcuts.js

    r4087 r6337  
    196196        var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1+num) 
    197197        var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName+num) 
     198        var inp = DateTimeShortcuts.calendarInputs[num]; 
     199 
     200        // Determine if the current value in the input has a valid date. 
     201        // If so, draw the calendar with that date's year and month. 
     202        if (inp.value) { 
     203            var date_parts = inp.value.split('-'); 
     204            var year = date_parts[0]; 
     205            var month = parseFloat(date_parts[1]); 
     206            if (year.match(/\d\d\d\d/) && month >= 1 && month <= 12) { 
     207                DateTimeShortcuts.calendars[num].drawDate(month, year); 
     208            } 
     209        } 
     210 
    198211     
    199212        // Recalculate the clockbox position 
  • django/branches/queryset-refactor/django/contrib/auth/decorators.py

    r5072 r6337  
    33from urllib import quote 
    44 
    5 def user_passes_test(test_func, login_url=None): 
     5def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): 
    66    """ 
    77    Decorator for views that checks that the user passes the given test, 
     
    1616            if test_func(request.user): 
    1717                return view_func(request, *args, **kwargs) 
    18             return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, quote(request.get_full_path()))) 
     18            return HttpResponseRedirect('%s?%s=%s' % (login_url, redirect_field_name, quote(request.get_full_path()))) 
    1919        _checklogin.__doc__ = view_func.__doc__ 
    2020        _checklogin.__dict__ = view_func.__dict__ 
     
    2323    return _dec 
    2424 
    25 login_required = user_passes_test(lambda u: u.is_authenticated()) 
    26 login_required.__doc__ = ( 
     25def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME): 
    2726    """ 
    2827    Decorator for views that checks that the user is logged in, redirecting 
    2928    to the log-in page if necessary. 
    3029    """ 
     30    actual_decorator = user_passes_test( 
     31        lambda u: u.is_authenticated(), 
     32        redirect_field_name=redirect_field_name 
    3133    ) 
     34    if function: 
     35        return actual_decorator(function) 
     36    return actual_decorator 
    3237 
    3338def permission_required(perm, login_url=None): 
  • django/branches/queryset-refactor/django/contrib/auth/views.py

    r6004 r6337  
    1010from django.utils.translation import ugettext as _ 
    1111 
    12 def login(request, template_name='registration/login.html'): 
     12def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME): 
    1313    "Displays the login form and handles the login action." 
    1414    manipulator = AuthenticationForm(request) 
    15     redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '') 
     15    redirect_to = request.REQUEST.get(redirect_field_name, '') 
    1616    if request.POST: 
    1717        errors = manipulator.get_validation_errors(request.POST) 
     
    3636    return render_to_response(template_name, { 
    3737        'form': oldforms.FormWrapper(manipulator, request.POST, errors), 
    38         REDIRECT_FIELD_NAME: redirect_to, 
     38        redirect_field_name: redirect_to, 
    3939        'site_name': current_site.name, 
    4040    }, context_instance=RequestContext(request)) 
     
    5757    return logout(request, login_url) 
    5858 
    59 def redirect_to_login(next, login_url=None): 
     59def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): 
    6060    "Redirects the user to the login page, passing the given 'next' page" 
    6161    if not login_url: 
    6262        from django.conf import settings 
    6363        login_url = settings.LOGIN_URL 
    64     return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next)) 
     64    return HttpResponseRedirect('%s?%s=%s' % (login_url, redirect_field_name, next)) 
    6565 
    6666def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', 
  • django/branches/queryset-refactor/django/core/handlers/base.py

    r6334 r6337  
    143143    this function converts them to absolute paths. 
    144144    """ 
    145     if 'Location' in response.headers and http.get_host(request): 
     145    if 'location' in response.headers and http.get_host(request): 
    146146        response['Location'] = request.build_absolute_uri(response['Location']) 
    147147    return response 
  • django/branches/queryset-refactor/django/core/management/commands/adminindex.py

    r5898 r6337  
    11from django.core.management.base import AppCommand 
     2from django.utils.encoding import force_unicode 
    23from django.utils.text import capfirst 
    34 
     
    2526                    'app': app_label, 
    2627                    'mod': model._meta.module_name, 
    27                     'name': capfirst(model._meta.verbose_name_plural), 
     28                    'name': force_unicode(capfirst(model._meta.verbose_name_plural)), 
    2829                    'addperm': model._meta.get_add_permission(), 
    2930                    'changeperm': model._meta.get_change_permission(), 
  • django/branches/queryset-refactor/django/core/management/commands/testserver.py

    r6075 r6337  
    88            type='choice', choices=['0', '1', '2'], 
    99            help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), 
     10        make_option('--addrport', action='store', dest='addrport',  
     11            type='string', default='', 
     12            help='port number or ipaddr:port to run the server on'), 
    1013    ) 
    1114    help = 'Runs a development server with data from the given fixture(s).' 
     
    2023 
    2124        verbosity = int(options.get('verbosity', 1)) 
     25        addrport = options.get('addrport') 
    2226 
    2327        # Create a test database. 
     
    3135        # multiple times. 
    3236        shutdown_message = '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name 
    33         call_command('runserver', shutdown_message=shutdown_message, use_reloader=False) 
     37        call_command('runserver', addrport=addrport, shutdown_message=shutdown_message, use_reloader=False) 
  • django/branches/queryset-refactor/django/core/management/validation.py

    r5898 r6337  
    11import sys 
    22from django.core.management.color import color_style 
     3from django.utils.itercompat import is_iterable 
    34 
    45class ModelErrorCollection: 
     
    5253                e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name) 
    5354            if f.choices: 
    54                 if not hasattr(f.choices, '__iter__'): 
     55                if isinstance(f.choices, basestring) or \ 
     56                       not is_iterable(f.choices): 
    5557                    e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name) 
    5658                else: 
  • django/branches/queryset-refactor/django/db/backends/oracle/base.py

    r6336 r6337  
    439439    charset = 'utf-8' 
    440440 
    441     def _rewrite_args(self, query, params=None): 
    442         if params is None: 
    443             params = [] 
    444         else: 
    445             params = self._format_params(params) 
    446         args = [(':arg%d' % i) for i in range(len(params))] 
    447         query = smart_str(query, self.charset) % tuple(args) 
    448         # cx_Oracle wants no trailing ';' for SQL statements.  For PL/SQL, it 
    449         # it does want a trailing ';' but not a trailing '/'.  However, these 
    450         # characters must be included in the original query in case the query 
    451         # is being passed to SQL*Plus. 
    452         if query.endswith(';') or query.endswith('/'): 
    453             query = query[:-1] 
    454         return query, params 
    455  
    456441    def _format_params(self, params): 
    457442        if isinstance(params, dict): 
     
    465450 
    466451    def execute(self, query, params=None): 
    467         query, params = self._rewrite_args(query, params) 
     452        if params is None: 
     453            params = [] 
     454        else: 
     455            params = self._format_params(params) 
     456        args = [(':arg%d' % i) for i in range(len(params))] 
     457        # cx_Oracle wants no trailing ';' for SQL statements.  For PL/SQL, it 
     458        # it does want a trailing ';' but not a trailing '/'.  However, these 
     459        # characters must be included in the original query in case the query 
     460        # is being passed to SQL*Plus. 
     461        if query.endswith(';') or query.endswith('/'): 
     462            query = query[:-1] 
     463        query = smart_str(query, self.charset) % tuple(args) 
    468464        return Database.Cursor.execute(self, query, params) 
    469465 
    470466    def executemany(self, query, params=None): 
    471         query, params = self._rewrite_args(query, params) 
    472         return Database.Cursor.executemany(self, query, params) 
     467        try: 
     468          args = [(':arg%d' % i) for i in range(len(params[0]))] 
     469        except (IndexError, TypeError): 
     470          # No params given, nothing to do 
     471          return None 
     472        # cx_Oracle wants no trailing ';' for SQL statements.  For PL/SQL, it 
     473        # it does want a trailing ';' but not a trailing '/'.  However, these 
     474        # characters must be included in the original query in case the query 
     475        # is being passed to SQL*Plus. 
     476        if query.endswith(';') or query.endswith('/'): 
     477            query = query[:-1] 
     478        query = smart_str(query, self.charset) % tuple(args) 
     479        new_param_list = [self._format_params(i) for i in params] 
     480        return Database.Cursor.executemany(self, query, new_param_list) 
    473481 
    474482    def fetchone(self): 
  • django/branches/queryset-refactor/django/db/backends/sqlite3/base.py

    r6035 r6337  
    134134 
    135135    def executemany(self, query, param_list): 
    136         query = self.convert_query(query, len(param_list[0])) 
    137         return Database.Cursor.executemany(self, query, param_list) 
     136        try: 
     137          query = self.convert_query(query, len(param_list[0])) 
     138          return Database.Cursor.executemany(self, query, param_list) 
     139        except (IndexError,TypeError): 
     140          # No parameter list provided 
     141          return None 
    138142 
    139143    def convert_query(self, query, num_params): 
  • django/branches/queryset-refactor/django/db/models/base.py

    r6334 r6337  
    1313from django.utils.datastructures import SortedDict 
    1414from django.utils.functional import curry 
    15 from django.utils.encoding import smart_str, force_unicode 
     15from django.utils.encoding import smart_str, force_unicode, smart_unicode 
    1616from django.conf import settings 
    1717from itertools import izip 
     
    214214        # Note: the comparison with '' is required for compatibility with 
    215215        # oldforms-style model creation. 
    216         pk_set = pk_val is not None and pk_val != u'' 
     216        pk_set = pk_val is not None and smart_unicode(pk_val) != u'' 
    217217        record_exists = True 
    218218        if pk_set: 
  • django/branches/queryset-refactor/django/db/models/fields/__init__.py

    r6335 r6337  
    694694class EmailField(CharField): 
    695695    def __init__(self, *args, **kwargs): 
    696         kwargs['max_length'] = 75 
     696        if 'max_length' not in kwargs: 
     697            kwargs['max_length'] = 75 
    697698        CharField.__init__(self, *args, **kwargs) 
    698699 
  • django/branches/queryset-refactor/django/db/models/options.py

    r6335 r6337  
    5353            for attr_name in DEFAULT_NAMES: 
    5454                setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name))) 
     55 
     56            # unique_together can be either a tuple of tuples, or a single 
     57            # tuple of two strings. Normalize it to a tuple of tuples, so that 
     58            # calling code can uniformly expect that. 
     59            ut = meta_attrs.pop('unique_together', getattr(self, 'unique_together')) 
     60            if ut and not isinstance(ut[0], (tuple, list)): 
     61                ut = (ut,) 
     62            setattr(self, 'unique_together', ut) 
     63 
    5564            # verbose_name_plural is a special case because it uses a 's' 
    5665            # by default. 
    5766            setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's'))) 
     67 
    5868            # Any leftover attributes must be invalid. 
    5969            if meta_attrs != {}: 
  • django/branches/queryset-refactor/django/http/__init__.py

    r6334 r6337  
    247247            self._container = [content] 
    248248            self._is_string = True 
    249         self.headers = {'Content-Type': content_type} 
     249        self.headers = {'content-type': content_type} 
    250250        self.cookies = SimpleCookie() 
    251251        if status: 
     
    259259 
    260260    def __setitem__(self, header, value): 
    261         self.headers[header] = value 
     261        self.headers[header.lower()] = value 
    262262 
    263263    def __delitem__(self, header): 
    264264        try: 
    265             del self.headers[header
     265            del self.headers[header.lower()
    266266        except KeyError: 
    267267            pass 
    268268 
    269269    def __getitem__(self, header): 
    270         return self.headers[header
     270        return self.headers[header.lower()
    271271 
    272272    def has_header(self, header): 
    273273        "Case-insensitive check for a header" 
    274         header = header.lower() 
    275         for key in self.headers.keys(): 
    276             if key.lower() == header: 
    277                 return True 
    278         return False 
     274        return self.headers.has_key(header.lower()) 
    279275 
    280276    def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=None): 
     
    305301 
    306302    def __iter__(self): 
    307         self._iterator = self._container.__iter__(
     303        self._iterator = iter(self._container
    308304        return self 
    309305 
  • django/branches/queryset-refactor/django/shortcuts/__init__.py

    r5756 r6337  
    1515    django.template.loader.render_to_string() with the passed arguments. 
    1616    """ 
    17     return HttpResponse(loader.render_to_string(*args, **kwargs)) 
     17    httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype')} 
     18    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) 
    1819load_and_render = render_to_response # For backwards compatibility. 
    1920 
  • django/branches/queryset-refactor/django/template/__init__.py

    r5630 r6337  
    5959from django.conf import settings 
    6060from django.template.context import Context, RequestContext, ContextPopException 
     61from django.utils.itercompat import is_iterable 
    6162from django.utils.functional import curry, Promise 
    6263from django.utils.text import smart_split 
     
    901902                    if not getattr(self, 'nodelist', False): 
    902903                        from django.template.loader import get_template, select_template 
    903                         if hasattr(file_name, '__iter__'): 
     904                        if not isinstance(file_name, basestring) and is_iterable(file_name): 
    904905                            t = select_template(file_name) 
    905906                        else: 
  • django/branches/queryset-refactor/django/test/client.py

    r6039 r6337  
    1717from django.utils.encoding import smart_str 
    1818from django.utils.http import urlencode 
     19from django.utils.itercompat import is_iterable 
    1920 
    2021BOUNDARY = 'BoUnDaRyStRiNg' 
     
    7576                value.read() 
    7677            ]) 
    77         elif hasattr(value, '__iter__'): 
    78             for item in value: 
     78        else: 
     79            if not isinstance(value, basestring) and is_iterable(value): 
     80                for item in value: 
     81                    lines.extend([ 
     82                        '--' + boundary, 
     83                        'Content-Disposition: form-data; name="%s"' % to_str(key), 
     84                        '', 
     85                        to_str(item) 
     86                    ]) 
     87            else: 
    7988                lines.extend([ 
    8089                    '--' + boundary, 
    8190                    'Content-Disposition: form-data; name="%s"' % to_str(key), 
    8291                    '', 
    83                     to_str(item
     92                    to_str(value
    8493                ]) 
    85         else: 
    86             lines.extend([ 
    87                 '--' + boundary, 
    88                 'Content-Disposition: form-data; name="%s"' % to_str(key), 
    89                 '', 
    90                 to_str(value) 
    91             ]) 
    9294 
    9395    lines.extend([ 
  • django/branches/queryset-refactor/django/utils/itercompat.py

    r5526 r6337  
    5858if hasattr(itertools, 'groupby'): 
    5959    groupby = itertools.groupby 
     60 
     61def is_iterable(x): 
     62    "A implementation independent way of checking for iterables" 
     63    try: 
     64        iter(x) 
     65    except TypeError: 
     66        return False 
     67    else: 
     68        return True 
     69 
  • django/branches/queryset-refactor/docs/authentication.txt

    r6037 r6337  
    403403        # ... 
    404404 
     405In the Django development version, ``login_required`` also takes an optional 
     406``redirect_field_name`` parameter. Example:: 
     407     
     408    from django.contrib.auth.decorators import login_required 
     409 
     410    def my_view(request): 
     411        # ... 
     412    my_view = login_required(redirect_field_name='redirect_to')(my_view) 
     413 
     414Again, an equivalent example of the more compact decorator syntax introduced in Python 2.4:: 
     415     
     416    from django.contrib.auth.decorators import login_required 
     417 
     418    @login_required(redirect_field_name='redirect_to') 
     419    def my_view(request): 
     420        # ... 
     421 
    405422``login_required`` does the following: 
    406423 
    407424    * If the user isn't logged in, redirect to ``settings.LOGIN_URL`` 
    408425      (``/accounts/login/`` by default), passing the current absolute URL 
    409       in the query string as ``next``. For example: 
     426      in the query string as ``next`` or the value of ``redirect_field_name``.  
     427      For example: 
    410428      ``/accounts/login/?next=/polls/3/``. 
    411429    * If the user is logged in, execute the view normally. The view code is 
  • django/branches/queryset-refactor/docs/databrowse.txt

    r5866 r6337  
    5959    4. Run the Django server and visit ``/databrowse/`` in your browser. 
    6060 
     61Requiring user login 
     62==================== 
     63 
     64You can restrict access to logged-in users with only a few extra lines of 
     65code. Simply add the following import to your URLconf:: 
     66 
     67    from django.contrib.auth.decorators import login_required 
     68 
     69Then modify the URLconf so that the ``databrowse.site.root`` view is decorated 
     70with ``login_required``:: 
     71 
     72    (r'^databrowse/(.*)', login_required(databrowse.site.root)), 
     73 
     74If you haven't already added support for user logins to your URLconf, as 
     75described in the `user authentication docs`_, then you will need to do so 
     76now with the following mapping:: 
     77 
     78    (r'^accounts/login/$', 'django.contrib.auth.views.login'), 
     79 
     80The final step is to create the login form required by 
     81``django.contrib.auth.views.login``. The `user authentication docs`_ 
     82provide full details and a sample template that can be used for this 
     83purpose. 
     84 
    6185.. _template loader docs: ../templates_python/#loader-types 
     86.. _user authentication docs: ../authentication/ 
  • django/branches/queryset-refactor/docs/django-admin.txt

    r6077 r6337  
    628628      being made to a test database. 
    629629 
    630 Note that this server can only run on the default port on localhost; it does 
    631 not yet accept a ``host`` or ``port`` parameter. 
    632  
    633 Also note that it does *not* automatically detect changes to your Python source 
    634 code (as ``runserver`` does). It does, however, detect changes to templates. 
     630Note that this server does *not* automatically detect changes to your Python 
     631source code (as ``runserver`` does). It does, however, detect changes to 
     632templates. 
    635633 
    636634.. _unit tests: ../testing/ 
     635 
     636--addrport [port number or ipaddr:port] 
     637~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     638 
     639Use ``--addrport`` to specify a different port, or IP address and port, from 
     640the default of 127.0.0.1:8000. This value follows exactly the same format and 
     641serves exactly the same function as the argument to the ``runserver`` subcommand. 
     642 
     643Examples: 
     644 
     645To run the test server on port 7000 with ``fixture1`` and ``fixture2``:: 
     646 
     647    django-admin.py testserver --addrport 7000 fixture1 fixture2 
     648    django-admin.py testserver fixture1 fixture2 --addrport 8080 
     649 
     650(The above statements are equivalent. We include both of them to demonstrate 
     651that it doesn't matter whether the options come before or after the 
     652``testserver`` command.) 
     653 
     654To run on 1.2.3.4:7000 with a `test` fixture:: 
     655 
     656    django-admin.py testserver --addrport 1.2.3.4:7000 test 
    637657 
    638658--verbosity 
  • django/branches/queryset-refactor/docs/model-api.txt

    r6334 r6337  
    222222 
    223223A ``CharField`` that checks that the value is a valid e-mail address. 
    224 This doesn't accept ``max_length``; its ``max_length`` is automatically set to 
    225 75. 
     224 
     225In Django 0.96, this doesn't accept ``max_length``; its ``max_length`` is 
     226automatically set to 75. In the Django development version, ``max_length`` is 
     227set to 75 by default, but you can specify it to override default behavior. 
    226228 
    227229``FileField`` 
     
    12241226level (i.e., the appropriate ``UNIQUE`` statements are included in the 
    12251227``CREATE TABLE`` statement). 
     1228 
     1229**New in Django development version** 
     1230 
     1231For convenience, unique_together can be a single list when dealing 
     1232with a single set of fields:: 
     1233 
     1234        unique_together = ("driver", "restaurant") 
    12261235 
    12271236``verbose_name`` 
  • django/branches/queryset-refactor/tests/modeltests/custom_pk/models.py

    r5876 r6337  
     1# -*- coding: utf-8 -*- 
    12""" 
    2314. Using a custom primary key 
     
    9394[<Business: Sears>] 
    9495 
     96# Primary key may be unicode string 
     97>>> emp = Employee(employee_code='jaźń') 
     98>>> emp.save() 
     99 
    95100"""} 
  • django/branches/queryset-refactor/tests/modeltests/test_client/models.py

    r6334 r6337  
    251251        self.assertEqual(response.context['user'].username, 'testclient') 
    252252 
     253    def test_view_with_login_and_custom_redirect(self): 
     254        "Request a page that is protected with @login_required(redirect_field_name='redirect_to')" 
     255         
     256        # Get the page without logging in. Should result in 302. 
     257        response = self.client.get('/test_client/login_protected_view_custom_redirect/') 
     258        self.assertRedirects(response, 'http://testserver/accounts/login/?redirect_to=/test_client/login_protected_view_custom_redirect/') 
     259 
     260        # Log in 
     261        login = self.client.login(username='testclient', password='password') 
     262        self.failUnless(login, 'Could not log in') 
     263 
     264        # Request a page that requires a login 
     265        response = self.client.get('/test_client/login_protected_view_custom_redirect/') 
     266        self.assertEqual(response.status_code, 200) 
     267        self.assertEqual(response.context['user'].username, 'testclient') 
     268 
    253269    def test_view_with_bad_login(self): 
    254270        "Request a page that is protected with @login, but use bad credentials" 
  • django/branches/queryset-refactor/tests/modeltests/test_client/urls.py

    r5876 r6337  
    1414    (r'^form_view_with_template/$', views.form_view_with_template), 
    1515    (r'^login_protected_view/$', views.login_protected_view), 
     16    (r'^login_protected_view_custom_redirect/$', views.login_protected_view_changed_redirect), 
    1617    (r'^session_view/$', views.session_view), 
    1718    (r'^broken_view/$', views.broken_view), 
  • django/branches/queryset-refactor/tests/modeltests/test_client/views.py

    r6046 r6337  
    123123login_protected_view = login_required(login_protected_view) 
    124124 
     125def login_protected_view_changed_redirect(request): 
     126    "A simple view that is login protected with a custom redirect field set" 
     127    t = Template('This is a login protected test. Username is {{ user.username }}.', name='Login Template') 
     128    c = Context({'user': request.user}) 
     129     
     130    return HttpResponse(t.render(c)) 
     131login_protected_view_changed_redirect = login_required(redirect_field_name="redirect_to")(login_protected_view_changed_redirect) 
     132 
    125133def session_view(request): 
    126134    "A view that modifies the session" 
  • django/branches/queryset-refactor/tests/regressiontests/forms/localflavor.py

    r6334 r6337  
    18191819>>> f.clean(u'') 
    18201820u'' 
     1821 
     1822# CAPostalCodeField ############################################################## 
     1823 
     1824CAPostalCodeField validates that the data is a six-character Canadian postal code. 
     1825>>> from django.contrib.localflavor.ca.forms import CAPostalCodeField 
     1826>>> f = CAPostalCodeField() 
     1827>>> f.clean('T2S 2H7') 
     1828u'T2S 2H7' 
     1829>>> f.clean('T2S 2H') 
     1830Traceback (most recent call last): 
     1831... 
     1832ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1833>>> f.clean('2T6 H8I') 
     1834Traceback (most recent call last): 
     1835... 
     1836ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1837>>> f.clean('T2S2H') 
     1838Traceback (most recent call last): 
     1839... 
     1840ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1841>>> f.clean(90210) 
     1842Traceback (most recent call last): 
     1843... 
     1844ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1845>>> f.clean(None) 
     1846Traceback (most recent call last): 
     1847... 
     1848ValidationError: [u'This field is required.'] 
     1849>>> f.clean('') 
     1850Traceback (most recent call last): 
     1851... 
     1852ValidationError: [u'This field is required.'] 
     1853>>> f = CAPostalCodeField(required=False) 
     1854>>> f.clean('T2S 2H7') 
     1855u'T2S 2H7' 
     1856>>> f.clean('T2S2H7') 
     1857Traceback (most recent call last): 
     1858... 
     1859ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1860>>> f.clean('T2S 2H') 
     1861Traceback (most recent call last): 
     1862... 
     1863ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1864>>> f.clean('2T6 H8I') 
     1865Traceback (most recent call last): 
     1866... 
     1867ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1868>>> f.clean('T2S2H') 
     1869Traceback (most recent call last): 
     1870... 
     1871ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1872>>> f.clean(90210) 
     1873Traceback (most recent call last): 
     1874... 
     1875ValidationError: [u'Enter a postal code in the format XXX XXX.'] 
     1876>>> f.clean(None) 
     1877u'' 
     1878>>> f.clean('') 
     1879u'' 
     1880 
     1881# CAPhoneNumberField ########################################################## 
     1882 
     1883CAPhoneNumberField validates that the data is a valid Canadian phone number, 
     1884including the area code. It's normalized to XXX-XXX-XXXX format. 
     1885Note: This test is exactly the same as the USPhoneNumberField except using a real 
     1886Candian area code 
     1887 
     1888>>> from django.contrib.localflavor.ca.forms import CAPhoneNumberField 
     1889>>> f = CAPhoneNumberField() 
     1890>>> f.clean('403-555-1212') 
     1891u'403-555-1212' 
     1892>>> f.clean('4035551212') 
     1893u'403-555-1212' 
     1894>>> f.clean('403 555-1212') 
     1895u'403-555-1212' 
     1896>>> f.clean('(403) 555-1212') 
     1897u'403-555-1212' 
     1898>>> f.clean('403 555 1212') 
     1899u'403-555-1212' 
     1900>>> f.clean('403.555.1212') 
     1901u'403-555-1212' 
     1902>>> f.clean('403.555-1212') 
     1903u'403-555-1212' 
     1904>>> f.clean(' (403) 555.1212 ') 
     1905u'403-555-1212' 
     1906>>> f.clean('555-1212') 
     1907Traceback (most recent call last): 
     1908... 
     1909ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.'] 
     1910>>> f.clean('403-55-1212'