Changeset 5419
- Timestamp:
- 06/02/07 23:45:23 (1 year ago)
- Files:
-
- django/branches/unicode (modified) (1 prop)
- django/branches/unicode/AUTHORS (modified) (1 diff)
- django/branches/unicode/django/bin/daily_cleanup.py (modified) (1 diff)
- django/branches/unicode/django/conf/project_template/settings.py (modified) (1 diff)
- django/branches/unicode/django/contrib/comments/feeds.py (modified) (2 diffs)
- django/branches/unicode/django/core/serializers/json.py (modified) (1 diff)
- django/branches/unicode/django/core/serializers/pyyaml.py (modified) (1 diff)
- django/branches/unicode/django/db/backends/dummy/base.py (modified) (2 diffs)
- django/branches/unicode/django/middleware/common.py (modified) (1 diff)
- django/branches/unicode/docs/django-admin.txt (modified) (2 diffs)
- django/branches/unicode/docs/generic_views.txt (modified) (1 diff)
- django/branches/unicode/docs/serialization.txt (modified) (2 diffs)
- django/branches/unicode/docs/settings.txt (modified) (1 diff)
- django/branches/unicode/docs/templates_python.txt (modified) (1 diff)
- django/branches/unicode/docs/testing.txt (modified) (1 diff)
- django/branches/unicode/docs/tutorial04.txt (modified) (2 diffs)
- django/branches/unicode/docs/url_dispatch.txt (modified) (1 diff)
- django/branches/unicode/tests/modeltests/serializers/models.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/serializers_regress/models.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/serializers_regress/tests.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode
- Property svnmerge-integrated changed from /django/trunk:1-5398 to /django/trunk:1-5418
django/branches/unicode/AUTHORS
r5381 r5419 145 145 kurtiss@meetro.com 146 146 lakin.wecker@gmail.com 147 Nick Lane <nick.lane.au@gmail.com> 147 148 Stuart Langridge <http://www.kryogenix.org/> 148 149 Nicola Larosa <nico@teknico.net> django/branches/unicode/django/bin/daily_cleanup.py
r4271 r5419 8 8 """ 9 9 10 from django.db import backend, connection, transaction 10 import datetime 11 from django.db import transaction 12 from django.contrib.sessions.models import Session 11 13 12 14 def clean_up(): 13 # Clean up old database records 14 cursor = connection.cursor() 15 cursor.execute("DELETE FROM %s WHERE %s < NOW()" % \ 16 (backend.quote_name('django_session'), backend.quote_name('expire_date'))) 15 """Clean up expired sessions.""" 16 Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete() 17 17 transaction.commit_unless_managed() 18 18 django/branches/unicode/django/conf/project_template/settings.py
r4678 r5419 39 39 MEDIA_ROOT = '' 40 40 41 # URL that handles the media served from MEDIA_ROOT. 42 # Example: "http://media.lawrence.com" 41 # URL that handles the media served from MEDIA_ROOT. Make sure to use a 42 # trailing slash if there is a path component (optional in other cases). 43 # Examples: "http://media.lawrence.com", "http://example.com/media/" 43 44 MEDIA_URL = '' 44 45 django/branches/unicode/django/contrib/comments/feeds.py
r5257 r5419 24 24 return u"Latest comments on %s" % self._site.name 25 25 26 def get_query_set(self): 27 return self.comments_class.objects.filter(site__pk=settings.SITE_ID, is_public=True) 28 26 29 def items(self): 27 return self. comments_class.objects.filter(site__pk=settings.SITE_ID, is_public=True)[:40]30 return self.get_query_set()[:40] 28 31 29 32 class LatestCommentsFeed(LatestFreeCommentsFeed): … … 32 35 comments_class = Comment 33 36 34 def items(self):35 qs = LatestFreeCommentsFeed.items(self)37 def get_query_set(self): 38 qs = super(LatestCommentsFeed, self).get_query_set() 36 39 qs = qs.filter(is_removed=False) 37 40 if settings.COMMENTS_BANNED_USERS_GROUP: django/branches/unicode/django/core/serializers/json.py
r5337 r5419 22 22 """ 23 23 def end_serialization(self): 24 self.options.pop('stream', None) 25 self.options.pop('fields', None) 24 26 simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options) 25 27 django/branches/unicode/django/core/serializers/pyyaml.py
r5248 r5419 19 19 """ 20 20 def end_serialization(self): 21 self.options.pop('stream', None) 22 self.options.pop('fields', None) 21 23 yaml.dump(self.objects, self.stream, **self.options) 22 24 django/branches/unicode/django/db/backends/dummy/base.py
r5081 r5419 13 13 raise ImproperlyConfigured, "You haven't set the DATABASE_ENGINE setting yet." 14 14 15 def ignore(*args, **kwargs): 16 pass 17 15 18 class DatabaseError(Exception): 16 19 pass … … 22 25 cursor = complain 23 26 _commit = complain 24 _rollback = complain27 _rollback = ignore 25 28 26 29 def __init__(self, **kwargs): django/branches/unicode/django/middleware/common.py
r5126 r5419 76 76 if settings.USE_ETAGS: 77 77 etag = md5.new(response.content).hexdigest() 78 if re quest.META.get('HTTP_IF_NONE_MATCH') == etag:78 if response.status_code >= 200 and response.status_code < 300 and request.META.get('HTTP_IF_NONE_MATCH') == etag: 79 79 response = http.HttpResponseNotModified() 80 80 else: django/branches/unicode/docs/django-admin.txt
r5054 r5419 296 296 297 297 By default, the development server doesn't serve any static files for your site 298 (such as CSS files, images, things under ``MEDIA_ ROOT_URL`` and so forth). If298 (such as CSS files, images, things under ``MEDIA_URL`` and so forth). If 299 299 you want to configure Django to serve static media, read the `serving static files`_ 300 300 documentation. … … 404 404 give you the option of creating a superuser immediately. 405 405 406 ``syncdb`` will also search for and install any fixture named ``initial_data``. 407 See the documentation for ``loaddata`` for details on the specification of 408 fixture data files. 406 ``syncdb`` will also search for and install any fixture named ``initial_data`` 407 with an appropriate extension (e.g. ``json`` or ``xml``). See the 408 documentation for ``loaddata`` for details on the specification of fixture 409 data files. 409 410 410 411 test django/branches/unicode/docs/generic_views.txt
r5081 r5419 100 100 just before rendering the template. 101 101 102 * ``mimetype``: The MIME type to use for the resulting document. Defaults 103 to the value of the ``DEFAULT_CONTENT_TYPE`` setting. 104 102 105 **Example:** 103 106 django/branches/unicode/docs/serialization.txt
r5185 r5419 44 44 45 45 .. _HTTPResponse: ../request_response/#httpresponse-objects 46 47 Subset of fields 48 ~~~~~~~~~~~~~~~~ 49 50 If you only want a subset of fields to be serialized, you can 51 specify a `fields` argument to the serializer:: 52 53 from django.core import serializers 54 data = serializers.serialize('xml', SomeModel.objects.all(), fields=('name','size')) 55 56 In this example, only the `name` and `size` attributes of each model will 57 be serialized. 58 59 .. note:: 60 61 Depending on your model, you may find that it is not possible to deserialize 62 a model that only serializes a subset of its fields. If a serialized object 63 doesn't specify all the fields that are required by a model, the deserializer 64 will not be able to save deserialized instances. 46 65 47 66 Deserializing data … … 93 112 strings, etc.). Not really all that useful on its own, but 94 113 used as a base for other serializers. 114 115 ``yaml`` Serializes to YAML (Yet Another Markup Lanuage). This 116 serializer is only available if PyYAML_ is installed. 95 117 ========== ============================================================== 96 118 97 119 .. _json: http://json.org/ 98 120 .. _simplejson: http://undefined.org/python/#simplejson 121 .. _PyYAML: http://www.pyyaml.org/ 99 122 100 123 Notes for specific serialization formats django/branches/unicode/docs/settings.txt
r5381 r5419 861 861 862 862 The collation order to use when creating the test database. This value is 863 passed directly to the backend, so it 's format is backend-specific.863 passed directly to the backend, so its format is backend-specific. 864 864 865 865 Only supported for ``mysql`` and ``mysql_old`` backends (see `section 10.3.2`_ django/branches/unicode/docs/templates_python.txt
r5381 r5419 395 395 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 396 396 397 If ``TEMPLATE_CONTEXT_PROCESSORS`` contains this processor s, every398 ``RequestContext`` will contain ``MEDIA_URL``, providing the397 If ``TEMPLATE_CONTEXT_PROCESSORS`` contains this processor, every 398 ``RequestContext`` will contain a variable ``MEDIA_URL``, providing the 399 399 value of the `MEDIA_URL setting`_. 400 400 django/branches/unicode/docs/testing.txt
r5399 r5419 572 572 you can use the ``TEST_DATABASE_NAME`` setting to provide a name. 573 573 574 575 **New in Django development version:** If you wish to have fine-grained 576 control over the character set encoding used in your database, you can control 577 this with the ``TEST_DATABASE_CHARSET`` setting. For MySQL users, you can also 578 control the particular collation used by the test database with the 579 ``TEST_DATABASE_COLLATION`` setting. Refer to the settings_ documentation for 580 details of these advanced settings. 574 **New in Django development version:** For fine-grained control over the 575 character encoding of your database, use the ``TEST_DATABASE_CHARSET`` setting. 576 If you're using MySQL, you can also use the ``TEST_DATABASE_COLLATION`` setting 577 to control the particular collation used by the test database. See the 578 settings_ documentation for details of these advanced settings. 581 579 582 580 .. _settings: ../settings/ django/branches/unicode/docs/tutorial04.txt
r5381 r5419 68 68 # with POST data. This prevents data from being posted twice if a 69 69 # user hits the Back button. 70 return HttpResponseRedirect(reverse(' results', args=(p.id,)))70 return HttpResponseRedirect(reverse('mysite.polls.views.results', args=(p.id,))) 71 71 72 72 This code includes a few things we haven't covered yet in this tutorial: … … 105 105 106 106 ... where the ``3`` is the value of ``p.id``. This redirected URL will 107 then call the ``'results'`` view to display the final page. 107 then call the ``'results'`` view to display the final page. Note that 108 you need to use the full name of the view here (including the prefix). 108 109 109 110 For more information about ``reverse()``, see the `URL dispatcher`_ django/branches/unicode/docs/url_dispatch.txt
r5381 r5419 565 565 reverse(viewname, urlconf=None, args=None, kwargs=None) 566 566 567 The view name is either the function name or the `URL pattern name`_. 568 Normally you will not need to worry about the ``urlconf`` parameter and will 569 only pass in the positional and keyword arguments to use in the url matching. 570 For example:: 567 ``viewname`` is either the function name (either a function reference, or the 568 string version of the name, if you used that form in ``urlpatterns``) or the 569 `URL pattern name`_. Normally, you won't need to worry about the 570 ``urlconf`` parameter and will only pass in the positional and keyword 571 arguments to use in the URL matching. For example:: 571 572 572 573 from django.core.urlresolvers import reverse django/branches/unicode/tests/modeltests/serializers/models.py
r5386 r5419 160 160 <Author: Agnes> 161 161 162 # Serializer output can be restricted to a subset of fields 163 >>> print serializers.serialize("json", Article.objects.all(), fields=('headline','pub_date')) 164 [{"pk": "1", "model": "serializers.article", "fields": {"headline": "Just kidding; I love TV poker", "pub_date": "2006-06-16 11:00:00"}}, {"pk": "2", "model": "serializers.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": "3", "model": "serializers.article", "fields": {"headline": "Forward references pose no problem", "pub_date": "2006-06-16 15:00:00"}}] 165 162 166 """} django/branches/unicode/tests/regressiontests/serializers_regress/models.py
r5381 r5419 206 206 # data = models.XMLField(primary_key=True) 207 207 208 class ComplexModel(models.Model): 209 field1 = models.CharField(maxlength=10) 210 field2 = models.CharField(maxlength=10) 211 field3 = models.CharField(maxlength=10) django/branches/unicode/tests/regressiontests/serializers_regress/tests.py
r5381 r5419 10 10 11 11 import unittest, datetime 12 from cStringIO import StringIO 12 13 13 14 from django.utils.functional import curry … … 282 283 func[1](self, pk, klass, datum) 283 284 285 def fieldsTest(format, self): 286 # Clear the database first 287 management.flush(verbosity=0, interactive=False) 288 289 obj = ComplexModel(field1='first',field2='second',field3='third') 290 obj.save() 291 292 # Serialize then deserialize the test database 293 serialized_data = serializers.serialize(format, [obj], indent=2, fields=('field1','field3')) 294 result = serializers.deserialize(format, serialized_data).next() 295 296 # Check that the deserialized object contains data in only the serialized fields. 297 self.assertEqual(result.object.field1, 'first') 298 self.assertEqual(result.object.field2, '') 299 self.assertEqual(result.object.field3, 'third') 300 301 def streamTest(format, self): 302 # Clear the database first 303 management.flush(verbosity=0, interactive=False) 304 305 obj = ComplexModel(field1='first',field2='second',field3='third') 306 obj.save() 307 308 # Serialize the test database to a stream 309 stream = StringIO() 310 serializers.serialize(format, [obj], indent=2, stream=stream) 311 312 # Serialize normally for a comparison 313 string_data = serializers.serialize(format, [obj], indent=2) 314 315 # Check that the two are the same 316 self.assertEqual(string_data, stream.buffer()) 317 stream.close() 318 284 319 for format in serializers.get_serializer_formats(): 285 320 setattr(SerializerTests, 'test_'+format+'_serializer', curry(serializerTest, format)) 321 setattr(SerializerTests, 'test_'+format+'_serializer_fields', curry(fieldsTest, format)) 322 setattr(SerializerTests, 'test_'+format+'_serializer_stream', curry(fieldsTest, format))
