Django

Code

Changeset 5596

Show
Ignore:
Timestamp:
07/03/07 11:03:51 (1 year ago)
Author:
adrian
Message:

newforms-admin: Merged to [5595]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin

    • Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-5571 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-5595
  • django/branches/newforms-admin/AUTHORS

    r5572 r5596  
    236236    torne-django@wolfpuppy.org.uk 
    237237    Karen Tracey <graybark@bellsouth.net> 
     238    tstromberg@google.com 
    238239    Makoto Tsuyuki <mtsuyuki@gmail.com> 
    239240    tt@gurgle.no 
  • django/branches/newforms-admin/django/contrib/auth/models.py

    r5572 r5596  
    268268 
    269269    def __str__(self): 
    270         return _('AnonymousUser') 
     270        return 'AnonymousUser' 
    271271 
    272272    def __eq__(self, other): 
  • django/branches/newforms-admin/django/contrib/sessions/middleware.py

    r5326 r5596  
    3838 
    3939    def pop(self, key, *args): 
     40        self.modified = self.modified or key in self._session  
    4041        return self._session.pop(key, *args) 
    4142 
  • django/branches/newforms-admin/django/contrib/sessions/tests.py

    r5326 r5596  
    66>>> s._session_cache['some key'] = 'exists' 
    77 
     8>>> s.accessed 
     9False 
     10>>> s.modified 
     11False 
     12 
     13>>> s.pop('non existant key', 'does not exist') 
     14'does not exist' 
     15>>> s.accessed 
     16True 
     17>>> s.modified 
     18False 
     19 
    820>>> s.pop('some key') 
    921'exists' 
     22>>> s.accessed 
     23True 
     24>>> s.modified 
     25True 
    1026 
    1127>>> s.pop('some key', 'does not exist') 
  • django/branches/newforms-admin/django/core/mail.py

    r5572 r5596  
    6363    pass 
    6464 
    65 class SafeHeaderMixin(object): 
     65class SafeMIMEText(MIMEText): 
    6666    def __setitem__(self, name, val): 
    6767        "Forbids multi-line headers, to prevent header injection." 
     
    7070        if name == "Subject": 
    7171            val = Header(val, settings.DEFAULT_CHARSET) 
    72         # Note: using super() here is safe; any __setitem__ overrides must use 
    73         # the same argument signature. 
    74         super(SafeHeaderMixin, self).__setitem__(name, val) 
    75  
    76 class SafeMIMEText(MIMEText, SafeHeaderMixin): 
    77     pass 
    78  
    79 class SafeMIMEMultipart(MIMEMultipart, SafeHeaderMixin): 
    80     pass 
     72        MIMEText.__setitem__(self, name, val) 
     73 
     74class SafeMIMEMultipart(MIMEMultipart): 
     75    def __setitem__(self, name, val): 
     76        "Forbids multi-line headers, to prevent header injection." 
     77        if '\n' in val or '\r' in val: 
     78            raise BadHeaderError, "Header values can't contain newlines (got %r for header %r)" % (val, name) 
     79        if name == "Subject": 
     80            val = Header(val, settings.DEFAULT_CHARSET) 
     81        MIMEMultipart.__setitem__(self, name, val) 
    8182 
    8283class SMTPConnection(object): 
  • django/branches/newforms-admin/django/core/management.py

    r5572 r5596  
    833833        sys.exit(1) 
    834834    _start_helper('project', project_name, directory) 
     835 
    835836    # Create a random SECRET_KEY hash, and put it in the main settings. 
    836837    main_settings_file = os.path.join(directory, project_name, 'settings.py') 
    837838    settings_contents = open(main_settings_file, 'r').read() 
     839 
     840    # If settings.py was copied from a read-only source, make it writeable. 
     841    if not os.access(main_settings_file, os.W_OK): 
     842        os.chmod(main_settings_file, 0600) 
     843 
    838844    fp = open(main_settings_file, 'w') 
    839845    secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) 
  • django/branches/newforms-admin/django/newforms/fields.py

    r5572 r5596  
    483483class MultiValueField(Field): 
    484484    """ 
    485     A Field that is composed of multiple Fields. 
    486  
    487     Its clean() method takes a "decompressed" list of values. Each value in 
     485    A Field that aggregates the logic of multiple Fields. 
     486     
     487    Its clean() method takes a "decompressed" list of values, which are then 
     488    cleaned into a single value according to self.fields. Each value in 
    488489    this list is cleaned by the corresponding field -- the first value is 
    489490    cleaned by the first field, the second value is cleaned by the second 
     
    491492    "compressed" into a single value. 
    492493 
    493     Subclasses should implement compress(), which specifies how a list of 
    494     valid values should be converted to a single value. Subclasses should not 
    495     have to implement clean()
     494    Subclasses should not have to implement clean(). Instead, they must 
     495    implement compress(), which takes a list of valid values and returns a 
     496    "compressed" version of those values -- a single value
    496497 
    497498    You'll probably want to use this with MultiWidget. 
  • django/branches/newforms-admin/django/newforms/widgets.py

    r5572 r5596  
    305305    A widget that is composed of multiple widgets. 
    306306 
    307     Its render() method takes a "decompressed" list of values, not a single 
    308     value. Each value in this list is rendered in the corresponding widget -- 
    309     the first value is rendered in the first widget, the second value is 
    310     rendered in the second widget, etc. 
    311  
    312     Subclasses should implement decompress(), which specifies how a single 
    313     value should be converted to a list of values. Subclasses should not 
    314     have to implement clean(). 
     307    Its render() method is different than other widgets', because it has to 
     308    figure out how to split a single value for display in multiple widgets. 
     309    The ``value`` argument can be one of two things: 
     310 
     311        * A list. 
     312        * A normal value (e.g., a string) that has been "compressed" from 
     313          a list of values. 
     314 
     315    In the second case -- i.e., if the value is NOT a list -- render() will 
     316    first "decompress" the value into a list before rendering it. It does so by 
     317    calling the decompress() method, which MultiWidget subclasses must 
     318    implement. This method takes a single "compressed" value and returns a 
     319    list. 
     320 
     321    When render() does its HTML rendering, each value in the list is rendered 
     322    with the corresponding widget -- the first value is rendered in the first 
     323    widget, the second value is rendered in the second widget, etc. 
    315324 
    316325    Subclasses may implement format_output(), which takes the list of rendered 
    317     widgets and returns HTML that formats them any way you'd like. 
    318  
    319     You'll probably want to use this with MultiValueField. 
     326    widgets and returns a string of HTML that formats them any way you'd like. 
     327 
     328    You'll probably want to use this class with MultiValueField. 
    320329    """ 
    321330    def __init__(self, widgets, attrs=None): 
     
    352361 
    353362    def format_output(self, rendered_widgets): 
     363        """ 
     364        Given a list of rendered widgets (as strings), returns a Unicode string 
     365        representing the HTML for the whole lot. 
     366 
     367        This hook allows you to format the HTML design of the widgets, if 
     368        needed. 
     369        """ 
    354370        return u''.join(rendered_widgets) 
    355371 
  • django/branches/newforms-admin/django/views/defaults.py

    r4617 r5596  
    2222 
    2323    # If the object actually defines a domain, we're done. 
    24     if absurl.startswith('http://')
     24    if absurl.startswith('http://') or absurl.startswith('https://')
    2525        return http.HttpResponseRedirect(absurl) 
    2626 
     
    6262    # to whatever get_absolute_url() returned. 
    6363    if object_domain is not None: 
    64         return http.HttpResponseRedirect('http://%s%s' % (object_domain, absurl)) 
     64        protocol = request.is_secure() and 'https' or 'http' 
     65        return http.HttpResponseRedirect('%s://%s%s' % (protocol, object_domain, absurl)) 
    6566    else: 
    6667        return http.HttpResponseRedirect(absurl) 
  • django/branches/newforms-admin/tests/modeltests/lookup/models.py

    r5572 r5596  
    66 
    77from django.db import models 
     8from django.conf import settings 
    89 
    910class Article(models.Model): 
     
    264265>>> a4 = Article(pub_date=now, headline='fooo') 
    265266>>> a4.save() 
    266 >>> a5 = Article(pub_date=now, headline='Foo') 
     267>>> a5 = Article(pub_date=now, headline='hey-Foo') 
    267268>>> a5.save() 
    268269 
     
    271272[<Article: f>, <Article: fo>, <Article: foo>, <Article: fooo>] 
    272273>>> Article.objects.filter(headline__iregex=r'fo*') 
    273 [<Article: Foo>, <Article: f>, <Article: fo>, <Article: foo>, <Article: fooo>] 
     274[<Article: f>, <Article: fo>, <Article: foo>, <Article: fooo>, <Article: hey-Foo>] 
    274275 
    275276# one-or-more 
     
    284285>>> a6 = Article(pub_date=now, headline='bar') 
    285286>>> a6.save() 
    286 >>> a7 = Article(pub_date=now, headline='Bar') 
     287>>> a7 = Article(pub_date=now, headline='AbBa') 
    287288>>> a7.save() 
    288289>>> a8 = Article(pub_date=now, headline='baz') 
    289290>>> a8.save() 
    290 >>> a9 = Article(pub_date=now, headline='baZ') 
     291>>> a9 = Article(pub_date=now, headline='baxZ') 
    291292>>> a9.save() 
    292293 
    293294# leading anchor 
    294295>>> Article.objects.filter(headline__regex=r'^b') 
    295 [<Article: baZ>, <Article: bar>, <Article: baz>] 
    296 >>> Article.objects.filter(headline__iregex=r'^b') 
    297 [<Article: Bar>, <Article: baZ>, <Article: bar>, <Article: baz>] 
     296[<Article: bar>, <Article: baxZ>, <Article: baz>] 
     297>>> Article.objects.filter(headline__iregex=r'^a') 
     298[<Article: AbBa>] 
    298299 
    299300# trailing anchor 
     
    301302[<Article: baz>] 
    302303>>> Article.objects.filter(headline__iregex=r'z$') 
    303 [<Article: baZ>, <Article: baz>] 
     304[<Article: baxZ>, <Article: baz>] 
    304305 
    305306# character sets 
    306307>>> Article.objects.filter(headline__regex=r'ba[rz]') 
    307308[<Article: bar>, <Article: baz>] 
    308 >>> Article.objects.filter(headline__regex=r'ba[RZ]') 
    309 [<Article: baZ>] 
    310 >>> Article.objects.filter(headline__iregex=r'ba[RZ]') 
    311 [<Article: Bar>, <Article: baZ>, <Article: bar>, <Article: baz>] 
     309>>> Article.objects.filter(headline__regex=r'ba.[RxZ]') 
     310[<Article: baxZ>] 
     311>>> Article.objects.filter(headline__iregex=r'ba[RxZ]') 
     312[<Article: bar>, <Article: baxZ>, <Article: baz>] 
    312313 
    313314# and yet more: 
     
    316317>>> a11 = Article(pub_date=now, headline='foobaz') 
    317318>>> a11.save() 
    318 >>> a12 = Article(pub_date=now, headline='FooBarBaz') 
     319>>> a12 = Article(pub_date=now, headline='ooF') 
    319320>>> a12.save() 
    320321>>> a13 = Article(pub_date=now, headline='foobarbaz') 
     
    324325>>> a15 = Article(pub_date=now, headline='barfoobaz') 
    325326>>> a15.save() 
    326 >>> a16 = Article(pub_date=now, headline='BAZBARFOO') 
     327>>> a16 = Article(pub_date=now, headline='bazbaRFOO') 
    327328>>> a16.save() 
    328329 
    329330# alternation 
    330 >>> Article.objects.filter(headline__regex=r'foo(bar|baz)') 
     331>>> Article.objects.filter(headline__regex=r'oo(f|b)') 
    331332[<Article: barfoobaz>, <Article: foobar>, <Article: foobarbaz>, <Article: foobaz>] 
    332 >>> Article.objects.filter(headline__iregex=r'foo(bar|baz)') 
    333 [<Article: FooBarBaz>, <Article: barfoobaz>, <Article: foobar>, <Article: foobarbaz>, <Article: foobaz>] 
    334 >>> Article.objects.filter(headline__regex=r'^foo(bar|baz)') 
     333>>> Article.objects.filter(headline__iregex=r'oo(f|b)') 
     334[<Article: barfoobaz>, <Article: foobar>, <Article: foobarbaz>, <Article: foobaz>, <Article: ooF>] 
     335>>> Article.objects.filter(headline__regex=r'^foo(f|b)') 
    335336[<Article: foobar>, <Article: foobarbaz>, <Article: foobaz>] 
    336337 
    337338# greedy matching 
    338 >>> Article.objects.filter(headline__regex=r'f.*z') 
    339 [<Article: barfoobaz>, <Article: foobarbaz>, <Article: foobaz>, <Article: zoocarfaz>] 
    340 >>> Article.objects.filter(headline__iregex=r'f.*z') 
    341 [<Article: FooBarBaz>, <Article: barfoobaz>, <Article: foobarbaz>, <Article: foobaz>, <Article: zoocarfaz>] 
    342  
     339>>> Article.objects.filter(headline__regex=r'b.*az') 
     340[<Article: barfoobaz>, <Article: baz>, <Article: bazbaRFOO>, <Article: foobarbaz>, <Article: foobaz>] 
     341>>> Article.objects.filter(headline__iregex=r'b.*ar') 
     342[<Article: bar>, <Article: barfoobaz>, <Article: bazbaRFOO>, <Article: foobar>, <Article: foobarbaz>] 
     343"""} 
     344 
     345 
     346if settings.DATABASE_ENGINE not in ('mysql', 'mysql_old'): 
     347    __test__['API_TESTS'] += r""" 
    343348# grouping and backreferences 
    344349>>> Article.objects.filter(headline__regex=r'b(.).*b\1') 
    345 [<Article: barfoobaz>, <Article: foobarbaz>] 
    346 >>> Article.objects.filter(headline__iregex=r'b(.).*b\1') 
    347 [<Article: BAZBARFOO>, <Article: FooBarBaz>, <Article: barfoobaz>, <Article: foobarbaz>] 
    348 """} 
     350[<Article: barfoobaz>, <Article: bazbaRFOO>, <Article: foobarbaz>] 
     351"""