Code

Ticket #8438: t8438-r8767.diff

File t8438-r8767.diff, 20.5 KB (added by ramiro, 6 years ago)

Please disregard previous bogus patch, use this instead. Aplly with patch -p1

Line 
1diff -r cef9b5a51e89 docs/releases/index.txt
2--- a/docs/releases/index.txt   Sun Aug 31 14:38:54 2008 -0300
3+++ b/docs/releases/index.txt   Sun Aug 31 19:44:37 2008 -0300
4@@ -9,13 +9,14 @@
5 
6 .. toctree::
7    :maxdepth: 1
8-   
9+
10    0.95
11    0.96
12    1.0-alpha-1
13    1.0-alpha-2
14    1.0-beta
15    1.0-beta-2
16+   porting-guide
17 
18 .. seealso::
19 
20@@ -23,5 +24,5 @@
21     development "trunk". If you're running versions of Django newer than an
22     official release, you should keep track of new pieces pointed there. It's
23     also fun reading if you're looking forward to new versions of Django.
24-   
25+
26 .. _backwards-incompatible changes: http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
27diff -r cef9b5a51e89 docs/releases/porting-guide.txt
28--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
29+++ b/docs/releases/porting-guide.txt   Sun Aug 31 19:44:37 2008 -0300
30@@ -0,0 +1,339 @@
31+========================
32+Porting 0.96 apps to 1.0
33+========================
34+
35+Version 1.0 breaks compatibility with 0.96. This guide will help you port 0.96 projects and apps to 1.0. The first part of this document includes the common changes needed to run with 1.0. If after going through the first part your code still breaks, check the section `Other Changes`_ for a list of all compatibility issues.
36+
37+Common Changes
38+==============
39+
40+models
41+------
42+    * The ``maxlength`` argument for model fields was replaced with ``max_length``.
43+    * Rename your model's ``__str__`` function to ``__unicode__`` and use unicode strings: ``u'foo'`` instead of ``'foo'``.
44+    * The ``prepopulated_from`` argument for model fields has been moved to the ``AdminModel`` class in ``admin.py`` (see below).
45+    * All of the Admin definitions moved from the ``Model`` definition to the new ``AdminModel`` class stored in an ``admin.py`` file. You can read about the new class in `The Django admin site`_. Here is an example with some of the most common changes::
46+
47+        # 0.96:
48+        class Author(models.Model):
49+            first_name = models.CharField(maxlength=30)
50+            last_name = models.CharField(maxlength=30)
51+            slug = models.CharField(max_length=60, prepopulate_from=('first_name', 'last_name'))
52+
53+            class Admin:
54+                 fields = (
55+                     ('full name', {'fields': ('first_name','last_name'), 'classes': 'collapse wide'}),
56+                 )
57+                 js = (
58+                     "/static/my_code.js",
59+                 )
60+
61+         class Book(models.Model):
62+             author = models.ForeignKey(Author, edit_inline=models.TABULAR)
63+             title = models.CharField(maxlength=100)
64+
65+        # 1.0:
66+        class Author(models.Model):
67+            first_name = models.CharField(max_length=30)
68+            last_name = models.CharField(max_length=30)
69+
70+        class Book(models.Model):
71+            author = models.ForeignKey(Author)
72+            title = models.CharField(max_length=100)
73+
74+        # admin.py
75+        from django.contrib import admin
76+        from models import Book, Author
77+
78+        class BookInline(admin.TabularInline):
79+            model = Book
80+            extra = 3
81+
82+        class AuthorAdmin(admin.ModelAdmin):
83+            inlines = [BookInline]
84+            fieldsets = (
85+                ('full name', {'fields': ('first_name','last_name'), 'classes': ('collapse', 'wide')}),
86+            )
87+            prepopulated_fields = {'slug': ('first_name', 'last_name')}
88+
89+            class Media:
90+                js = (
91+                    "/static/my_code.js",
92+                )
93+        admin.site.register(Author, AuthorAdmin)
94+
95+      NOTE: There is a script_ that scans your models.py and automatically outputs the corresponding source code for ``admin.py``.
96+
97+.. _The Django admin site: http://docs.djangoproject.com/en/dev/ref/contrib/admin/
98+.. _script: http://www.djangosnippets.org/snippets/603/
99+
100+
101+Templates
102+---------
103+    * By default the templating system automatically escapes the output of every variable tag.  To learn more take a look at `automatic html escaping`_. To disable auto-escaping for an individual variable, use the safe filter::
104+
105+        This will be escaped: {{ data }}
106+        This will not be escaped: {{ data|safe }}
107+
108+      To disable auto-escaping for an entire template, wrap the template (or just a particular section of the template) in the autoescape tag, like so::
109+
110+        {% autoescape off %}
111+           ... normal template content here ...
112+        {% endautoescape %}
113+
114+.. _automatic html escaping: http://docs.djangoproject.com/en/dev/topics/templates/#automatic-html-escaping
115+
116+urls
117+----
118+    * If you are using the Admin you need to update your root ``urls.py``::
119+
120+        # 0.96:
121+        from django.conf.urls.defaults import *
122+
123+        urlpatterns = patterns('',
124+            (r'^admin/', include('django.contrib.admin.urls')),
125+        )
126+
127+        # 1.0:
128+        from django.conf.urls.defaults import *
129+        from django.contrib import admin
130+
131+        # automatically load the INSTALLED_APPS admin.py modules
132+        admin.autodiscover()
133+
134+        urlpatterns = patterns('',
135+            (r'^admin/doc/', include('django.contrib.admindocs.urls')),
136+            (r'^admin/(.*)', admin.site.root),
137+        )
138+
139+views
140+-----
141+    * With 1.0 ``newforms`` were renamed ``forms`` and ``oldforms`` were removed. If you are already using new forms all you have to do is change your import statement::
142+
143+        # 0.96
144+        from django import newforms as forms
145+
146+        # 1.0
147+        from django import forms
148+
149+       If you are using the old forms, you will have to rewrite your forms - a good place to start is the `forms documentation`_.
150+
151+.. _forms documentation: http://docs.djangoproject.com/en/dev/topics/forms/
152+
153+    * In 0.96 uploaded files -- that is, entries in ``request.FILES`` -- were represented by simple dictionaries with a few well-known keys. Uploaded files are now represented by an `UploadedFile object`_, and thus the file's information is accessible through object attributes. Thus, given ``f = request.FILES['file_field_name']``:
154+
155+        ===================== =====================
156+        0.96                  1.0
157+        ===================== =====================
158+        ``f['content']``      ``f.read()``
159+        ``f['filename']``     ``f.name``
160+        ``f['content-type']`` ``f.content_type``
161+        ===================== =====================
162+
163+.. _UploadedFile object: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#uploadedfile-objects
164+
165+Signals
166+-------
167+    * All handlers now must be declared as accepting ``**kwargs``.
168+    * Signals are now instances of ``django.dispatch.Signal`` instead of anonymous objects.
169+    * Connecting, disconnecting, and sending signals are done via methods on the ``Signal`` object instead of through module methods in ``django.dispatch.dispatcher``. The module-level methods are deprecated.
170+    * The ``Anonymous`` and ``Any`` sender options no longer exist. You can still receive signals sent by any sender by using ``sender=None``
171+    * So, a quick summary of the code changes you'd need to make:
172+
173+        ========================================================= ================================================
174+        0.96                                                      1.0
175+        ========================================================= ================================================
176+        ``def my_handler(sender)``                                ``def my_handler(sender, **kwargs)``
177+        ``my_signal = object()``                                  ``my_signal = django.dispatch.Signal()``
178+        ``dispatcher.connect(my_handler, my_signal)``             ``my_signal.connect(my_handler)``
179+        ``dispatcher.send(my_signal, sender)``                    ``my_signal.send(sender)``
180+        ``dispatcher.connect(my_handler, my_signal, sender=Any)`` ``my_signal.connect(my_handler, sender=None)``
181+        ========================================================= ================================================
182+
183+.. Other Changes_:
184+
185+Other Changes
186+=============
187+    * The spaceless template tag removes *all* spaces between HTML tags instead of preserving a single space
188+    * ``localflavor.usa`` has been renamed ``localflavor.us``. This change was made to match the naming scheme of other local flavors.
189+    * Renamed ``SeesionBase.get_new_session_key()`` to ``_get_new_session_key()`` and removed ``get_new_session_object()``.
190+    * Fixture behaviour has changed slightly: previously, loading a row automatically ran the model's ``save()`` method. This is no longer the case, so any fields (for example: timestamps) that were auto-populated by a ``save()`` now need explicit values in any fixture.
191+    * Settings exception changed. ``EnvironmentError`` was split into an ``ImportError`` raised when Django fails to find the settings module and ``RuntimeError`` when you try to reconfigure settings after having already used them
192+    * The models manager now returns a ``MultipleObjectsReturned`` exception instead of ``AssertionError``::
193+
194+        #0.96
195+        try:
196+            Model.objects.get(...)
197+        except AssertionError:
198+            ...
199+
200+        #1.0
201+        try:
202+            Model.objects.get(...)
203+        except Model.MultipleObjectsReturned:
204+            ...
205+
206+    * The manager option to class ``Admin`` no longer exists. In favor of this option, a ``ModelAdmin`` class may now define a queryset method::
207+
208+        class BookAdmin(admin.ModelAdmin):
209+            def queryset(self, request):
210+                """
211+                Filter based on the current user.
212+                """
213+                return self.model._default_manager.filter(user=request.user)
214+
215+    * ``django.views.i18n.set_language`` requires a POST request. Previously, a GET request was used. The old behavior meant that state (the locale used to display the site) could be changed by a GET request, which is against the HTTP specification's recommendations.
216+      Code calling this view must ensure that a POST request is now made, instead of a GET. This means you can no longer use a link to access the view, but must use a form submission of some kind (e.g. a button).
217+    * ``django.http.HttpResponse.headers`` has been renamed to ``_headers`` and ``HttpResponse`` now supports containment checking directly::
218+
219+        # 0.96
220+        if header in response.headers:
221+
222+        # 1.0
223+        if header in response:
224+
225+    * The generic relation classes - ``GenericForeignKey`` and ``GenericRelation`` - have moved into the ``django.contrib.contenttypes module``::
226+
227+        #0.96
228+        generic_field = models.GenericRelation(SomeOtherModel)
229+
230+        #1.0
231+        from django.contrib.contenttypes import generic
232+        ...
233+        generic_field = generic.GenericRelation(SomeOtherModel)
234+
235+    * ``_()`` is no longer in builtins so if you were previously relying on ``_()`` always being present, you should now explicitly import ``ugettext`` or ``ugettext_lazy``, if appropriate, and alias it to _ yourself::
236+
237+        from django.utils.translation import ugettext as _
238+
239+    * The ``LazyDate`` helper class was removed. Default field values and query arguments can both be callable objects, so instances of ``LazyDate`` can be replaced with a reference to datetime.now::
240+
241+        # 0.96
242+        class Article(models.Model):
243+            title = models.CharField(maxlength=100)
244+            published = models.DateField(default=LazyDate())
245+
246+        # 1.0
247+        from datetime import datetime
248+        class Article(models.Model):
249+            title = models.CharField(maxlength=100)
250+            published = models.DateField(default=datetime.now)
251+
252+    * The ``LOGIN_URL`` constant moved from ``django.contrib.auth`` into the ``settings`` module. Instead of using ``from django.contrib.auth import LOGIN_URL`` refer to ``settings.LOGIN_URL``.
253+
254+    * Test client login method changed::
255+
256+        # 0.96
257+        from django.test import Client
258+        c = Client()
259+        c.login('/path/to/login','myuser','mypassword')
260+
261+        # 1.0
262+        ...
263+        c.login(username='myuser', password='mypassword')
264+
265+
266+    * Changes to ``django.core.management`` - calls to management services in your code will need to use the ``call_command``. For example, if you have some test code that calls flush and load_data::
267+
268+        from django.core import management
269+        management.flush(verbosity=0, interactive=False)
270+        management.load_data(['test_data'], verbosity=0)
271+
272+      You will need to change this code to read::
273+
274+        from django.core import management
275+        management.call_command('flush', verbosity=0, interactive=False)
276+        management.call_command('loaddata', 'test_data', verbosity=0)
277+
278+    * ``django-admin.py`` and ``manage.py`` now require subcommands to precede options::
279+
280+        django-admin.py --settings=foo.bar runserver
281+
282+      changed to::
283+
284+        django-admin.py runserver --settings=foo.bar
285+
286+    * Changed ``__init__()`` parameters in syndication framework's Feed class to take an ``HttpRequest`` object as its second parameter, instead of the feed's URL. This allows the syndication framework to work without requiring the sites framework.
287+      This only affects code that subclass Feed and overrides the ``__init__()`` method, and code that calls ``Feed.__init__()`` directly.
288+    * ``django.newforms.forms.SortedDictFromList`` class removed, due to ``django.utils.datastructures.SortedDict`` gaining the ability to be instantiated with a sequence of tuples. Two things need to be done to fix your code:
289+
290+       1. Use ``django.utils.datastructures.SortedDict`` wherever you were using ``django.newforms.forms.SortedDictFromList``.
291+       2. Since ``SortedDict``'s copy method doesn't return a deepcopy as ``SortedDictFromList'``s copy method did, you will need to update your code if you were relying on ``SortedDictFromList.copy`` to return a deepcopy. Do this by using ``copy.deepcopy`` instead of ``SortedDict``'s copy method.
292+
293+    * Change to ``APPEND_SLASH`` behaviour. In 0.96, if a URL didn't end in a slash or have a period in the final component of it's path, and ``APPEND_SLASH`` was True, Django would redirect to the same URL, but with a slash appended to the end.
294+      Now, Django checks to see if the pattern without the trailing slash would be matched by something in your URL patterns. If so, no redirection takes place, because it is assumed you deliberately wanted to catch that pattern.
295+      For most people, this won't require any changes. Some people, though, have URL patterns that look like this::
296+
297+        r'/some_prefix/(.*)$'
298+
299+      Previously, those patterns would have been redirected to have a trailing slash. If you always want a slash on such URLs, rewrite the pattern as::
300+
301+        r'/some_prefix/(.*/)$'
302+
303+    * Introduced ``DecimalField`` and changed ``FloatField`` to proper float - one that takes no ``max_digits``::
304+
305+        # 0.96
306+        class MyModel(models.Model):
307+            ...
308+            field_name = models.FloatField(max_digits=10, decimal_places=3)
309+
310+        #1.0
311+        class MyModel(models.Model):
312+            ...
313+            field_name = models.DecimalField(max_digits=10, decimal_places=3)
314+
315+      If you forget to make this change, you will see errors about ``FloatField`` not taking a ``max_digits`` attribute in ``__init__``, since the new ``FloatField`` takes no precision-related arguments.
316+      If you are using MySQL or PostgreSQL, there are no further changes needed. The database column types for ``DecimalField`` are the same as for the old ``FloatField``.
317+      If you are using SQLite, you need to force the database to view the appropriate columns as decimal types, rather than floats. To do this, follow this procedure for every application you have that contains a ``DecimalField``. Do this after you have made the change to using ``DecimalField`` in your code and updated the Django code.
318+      Warning: Back up your database first! For SQLite, this means making a copy of the single file that stores the database (the name of that file is the ``DATABASE_NAME`` in your settings.py file).
319+
320+      For every application using a ``DecimalField``, do the following. We will use applications called some_app and another_app in this example::
321+
322+        ./manage.py dumpdata --format=xml some_app another_app > data-dump.xml
323+        ./manage.py reset some_app another_app
324+        ./manage.py loaddata data-dump.xml
325+
326+      Notes:
327+
328+       1. It is important that you remember to use XML format in the first step of this process. We are exploiting a feature of the XML data dumps that makes porting floats to decimals with SQLite possible.
329+       2. In the second step you will be asked to confirm that you are prepared to lose the data for the application(s) in question. We restore this data in the third step, of course.
330+       3. DecimalField is not used in any of the apps shipped with Django prior to this change being made, so you do not need to worry about performing this procedure for any of the standard Django applications.
331+
332+      If something goes wrong in the above process, just copy your backed up database file over the top of the original file and start again.
333+    * Almost *all* of the database backend-level functions have been renamed and/or relocated. None of these were documented, but you'll need to change your code if you're using any of these functions:
334+
335+        ============================================= =========================================================
336+        0.96 name/location                            1.0 name/location
337+        ============================================= =========================================================
338+        django.db.backend.get_autoinc_sql             django.db.connection.ops.autoinc_sql
339+        django.db.backend.get_date_extract_sql        django.db.connection.ops.date_extract_sql
340+        django.db.backend.get_date_trunc_sql          django.db.connection.ops.date_trunc_sql
341+        django.db.backend.get_datetime_cast_sql       django.db.connection.ops.datetime_cast_sql
342+        django.db.backend.get_deferrable_sql          django.db.connection.ops.deferrable_sql
343+        django.db.backend.get_drop_foreignkey_sql     django.db.connection.ops.drop_foreignkey_sql
344+        django.db.backend.get_fulltext_search_sql     django.db.connection.ops.fulltext_search_sql
345+        django.db.backend.get_last_insert_id          django.db.connection.ops.last_insert_id
346+        django.db.backend.get_limit_offset_sql        django.db.connection.ops.limit_offset_sql
347+        django.db.backend.get_max_name_length         django.db.connection.ops.max_name_length
348+        django.db.backend.get_pk_default_value        django.db.connection.ops.pk_default_value
349+        django.db.backend.get_random_function_sql     django.db.connection.ops.random_function_sql
350+        django.db.backend.get_sql_flush               django.db.connection.ops.sql_flush
351+        django.db.backend.get_sql_sequence_reset      django.db.connection.ops.sequence_reset_sql
352+        django.db.backend.get_start_transaction_sql   django.db.connection.ops.start_transaction_sql
353+        django.db.backend.get_tablespace_sql          django.db.connection.ops.tablespace_sql
354+        django.db.backend.quote_name                  django.db.connection.ops.quote_name
355+        django.db.backend.get_query_set_class         django.db.connection.ops.query_set_class
356+        django.db.backend.get_field_cast_sql          django.db.connection.ops.field_cast_sql
357+        django.db.backend.get_drop_sequence           django.db.connection.ops.drop_sequence_sql
358+        django.db.backend.OPERATOR_MAPPING            django.db.connection.operators
359+        django.db.backend.allows_group_by_ordinal     django.db.connection.features.allows_group_by_ordinal
360+        django.db.backend.allows_unique_and_pk        django.db.connection.features.allows_unique_and_pk
361+        django.db.backend.autoindexes_primary_keys    django.db.connection.features.autoindexes_primary_keys
362+        django.db.backend.needs_datetime_string_cast  django.db.connection.features.needs_datetime_string_cast
363+        django.db.backend.needs_upper_for_iops        django.db.connection.features.needs_upper_for_iops
364+        django.db.backend.supports_constraints        django.db.connection.features.supports_constraints
365+        django.db.backend.supports_tablespaces        django.db.connection.features.supports_tablespaces
366+        django.db.backend.uses_case_insensitive_names django.db.connection.features.uses_case_insensitive_names
367+        django.db.backend.uses_custom_queryset        django.db.connection.features.uses_custom_queryset
368+        ============================================= =========================================================
369+