Changeset 5596
- Timestamp:
- 07/03/07 11:03:51 (1 year ago)
- Files:
-
- django/branches/newforms-admin (modified) (1 prop)
- django/branches/newforms-admin/AUTHORS (modified) (1 diff)
- django/branches/newforms-admin/django/contrib/auth/models.py (modified) (1 diff)
- django/branches/newforms-admin/django/contrib/sessions/middleware.py (modified) (1 diff)
- django/branches/newforms-admin/django/contrib/sessions/tests.py (modified) (1 diff)
- django/branches/newforms-admin/django/core/mail.py (modified) (2 diffs)
- django/branches/newforms-admin/django/core/management.py (modified) (1 diff)
- django/branches/newforms-admin/django/newforms/fields.py (modified) (2 diffs)
- django/branches/newforms-admin/django/newforms/widgets.py (modified) (2 diffs)
- django/branches/newforms-admin/django/views/defaults.py (modified) (2 diffs)
- django/branches/newforms-admin/tests/modeltests/lookup/models.py (modified) (7 diffs)
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 236 236 torne-django@wolfpuppy.org.uk 237 237 Karen Tracey <graybark@bellsouth.net> 238 tstromberg@google.com 238 239 Makoto Tsuyuki <mtsuyuki@gmail.com> 239 240 tt@gurgle.no django/branches/newforms-admin/django/contrib/auth/models.py
r5572 r5596 268 268 269 269 def __str__(self): 270 return _('AnonymousUser')270 return 'AnonymousUser' 271 271 272 272 def __eq__(self, other): django/branches/newforms-admin/django/contrib/sessions/middleware.py
r5326 r5596 38 38 39 39 def pop(self, key, *args): 40 self.modified = self.modified or key in self._session 40 41 return self._session.pop(key, *args) 41 42 django/branches/newforms-admin/django/contrib/sessions/tests.py
r5326 r5596 6 6 >>> s._session_cache['some key'] = 'exists' 7 7 8 >>> s.accessed 9 False 10 >>> s.modified 11 False 12 13 >>> s.pop('non existant key', 'does not exist') 14 'does not exist' 15 >>> s.accessed 16 True 17 >>> s.modified 18 False 19 8 20 >>> s.pop('some key') 9 21 'exists' 22 >>> s.accessed 23 True 24 >>> s.modified 25 True 10 26 11 27 >>> s.pop('some key', 'does not exist') django/branches/newforms-admin/django/core/mail.py
r5572 r5596 63 63 pass 64 64 65 class Safe HeaderMixin(object):65 class SafeMIMEText(MIMEText): 66 66 def __setitem__(self, name, val): 67 67 "Forbids multi-line headers, to prevent header injection." … … 70 70 if name == "Subject": 71 71 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 74 class 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) 81 82 82 83 class SMTPConnection(object): django/branches/newforms-admin/django/core/management.py
r5572 r5596 833 833 sys.exit(1) 834 834 _start_helper('project', project_name, directory) 835 835 836 # Create a random SECRET_KEY hash, and put it in the main settings. 836 837 main_settings_file = os.path.join(directory, project_name, 'settings.py') 837 838 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 838 844 fp = open(main_settings_file, 'w') 839 845 secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) django/branches/newforms-admin/django/newforms/fields.py
r5572 r5596 483 483 class MultiValueField(Field): 484 484 """ 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 488 489 this list is cleaned by the corresponding field -- the first value is 489 490 cleaned by the first field, the second value is cleaned by the second … … 491 492 "compressed" into a single value. 492 493 493 Subclasses should implement compress(), which specifies how a list of494 valid values should be converted to a single value. Subclasses should not495 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. 496 497 497 498 You'll probably want to use this with MultiWidget. django/branches/newforms-admin/django/newforms/widgets.py
r5572 r5596 305 305 A widget that is composed of multiple widgets. 306 306 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. 315 324 316 325 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. 320 329 """ 321 330 def __init__(self, widgets, attrs=None): … … 352 361 353 362 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 """ 354 370 return u''.join(rendered_widgets) 355 371 django/branches/newforms-admin/django/views/defaults.py
r4617 r5596 22 22 23 23 # If the object actually defines a domain, we're done. 24 if absurl.startswith('http://') :24 if absurl.startswith('http://') or absurl.startswith('https://'): 25 25 return http.HttpResponseRedirect(absurl) 26 26 … … 62 62 # to whatever get_absolute_url() returned. 63 63 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)) 65 66 else: 66 67 return http.HttpResponseRedirect(absurl) django/branches/newforms-admin/tests/modeltests/lookup/models.py
r5572 r5596 6 6 7 7 from django.db import models 8 from django.conf import settings 8 9 9 10 class Article(models.Model): … … 264 265 >>> a4 = Article(pub_date=now, headline='fooo') 265 266 >>> a4.save() 266 >>> a5 = Article(pub_date=now, headline=' Foo')267 >>> a5 = Article(pub_date=now, headline='hey-Foo') 267 268 >>> a5.save() 268 269 … … 271 272 [<Article: f>, <Article: fo>, <Article: foo>, <Article: fooo>] 272 273 >>> 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>] 274 275 275 276 # one-or-more … … 284 285 >>> a6 = Article(pub_date=now, headline='bar') 285 286 >>> a6.save() 286 >>> a7 = Article(pub_date=now, headline=' Bar')287 >>> a7 = Article(pub_date=now, headline='AbBa') 287 288 >>> a7.save() 288 289 >>> a8 = Article(pub_date=now, headline='baz') 289 290 >>> a8.save() 290 >>> a9 = Article(pub_date=now, headline='ba Z')291 >>> a9 = Article(pub_date=now, headline='baxZ') 291 292 >>> a9.save() 292 293 293 294 # leading anchor 294 295 >>> Article.objects.filter(headline__regex=r'^b') 295 [<Article: ba Z>, <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>] 298 299 299 300 # trailing anchor … … 301 302 [<Article: baz>] 302 303 >>> Article.objects.filter(headline__iregex=r'z$') 303 [<Article: ba Z>, <Article: baz>]304 [<Article: baxZ>, <Article: baz>] 304 305 305 306 # character sets 306 307 >>> Article.objects.filter(headline__regex=r'ba[rz]') 307 308 [<Article: bar>, <Article: baz>] 308 >>> Article.objects.filter(headline__regex=r'ba [RZ]')309 [<Article: ba Z>]310 >>> Article.objects.filter(headline__iregex=r'ba[R Z]')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>] 312 313 313 314 # and yet more: … … 316 317 >>> a11 = Article(pub_date=now, headline='foobaz') 317 318 >>> a11.save() 318 >>> a12 = Article(pub_date=now, headline=' FooBarBaz')319 >>> a12 = Article(pub_date=now, headline='ooF') 319 320 >>> a12.save() 320 321 >>> a13 = Article(pub_date=now, headline='foobarbaz') … … 324 325 >>> a15 = Article(pub_date=now, headline='barfoobaz') 325 326 >>> a15.save() 326 >>> a16 = Article(pub_date=now, headline=' BAZBARFOO')327 >>> a16 = Article(pub_date=now, headline='bazbaRFOO') 327 328 >>> a16.save() 328 329 329 330 # alternation 330 >>> Article.objects.filter(headline__regex=r' foo(bar|baz)')331 >>> Article.objects.filter(headline__regex=r'oo(f|b)') 331 332 [<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)') 335 336 [<Article: foobar>, <Article: foobarbaz>, <Article: foobaz>] 336 337 337 338 # 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 346 if settings.DATABASE_ENGINE not in ('mysql', 'mysql_old'): 347 __test__['API_TESTS'] += r""" 343 348 # grouping and backreferences 344 349 >>> 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 """
