=== added file 'tests/regressiontests/views/tests/generic/create_update.py'
--- tests/regressiontests/views/tests/generic/create_update.py	1970-01-01 00:00:00 +0000
+++ tests/regressiontests/views/tests/generic/create_update.py	2008-06-16 20:00:48 +0000
@@ -0,0 +1,105 @@
+import datetime
+
+from django.test import TestCase
+from regressiontests.views.models import Article, Author
+
+class CreateObjectTest(TestCase):
+    fixtures = ['testdata.json']
+
+    def test_not_logged_in(self):
+        """Verifies the user is logged in through the login_required kwarg"""
+        view_url = '/views/create_update/member/create/article/'
+        response = self.client.get(view_url)
+        self.assertRedirects(response, 'http://testserver/accounts/login/?next=%s' % view_url)
+
+    def test_create_article_display_page(self):
+        """Ensures the generic view returned the page and contains a form."""
+        view_url = '/views/create_update/create/article/'
+        response = self.client.get(view_url)
+        self.assertEqual(response.status_code, 200)
+        if not response.context.get('form'):
+            self.fail('No form found in the response.')
+
+    def test_create_article_with_errors(self):
+        """POSTs a form that contain validation errors."""
+        view_url = '/views/create_update/create/article/'
+        response = self.client.post(view_url, {
+            'title': 'My First Article',
+        })
+        self.assertFormError(response, 'form', 'slug', [u'This field is required.'])
+
+    def test_create_article(self):
+        """Creates a new article through the generic view and ensures it gets
+        redirected to the correct URL defined by post_save_redirect"""
+        view_url = '/views/create_update/create/article/'
+        response = self.client.post(view_url, {
+            'title': 'My First Article',
+            'slug': 'my-first-article',
+            'author': '1',
+            'date_created': datetime.datetime(2007, 6, 25),
+        })
+        self.assertRedirects(response,
+            'http://testserver/views/create_update/view/article/my-first-article/',
+            target_status_code=404)
+
+    def test_create_custom_save_article(self):
+        """
+        Creates a new article with a save method override to adjust the slug
+        before committing to the database.
+        """
+        view_url = '/views/create_update/create_custom/article/'
+        response = self.client.post(view_url, {
+            'title': 'Test Article',
+            'slug': 'this-should-get-replaced',
+            'author': 1,
+            'date_created': datetime.datetime(2007, 6, 25),
+        })
+        self.assertRedirects(response,
+            'http://testserver/views/create_update/view/article/some-other-slug/',
+            target_status_code=404)
+
+class UpdateDeleteObjectTest(TestCase):
+    fixtures = ['testdata.json']
+
+    def test_update_object_form_display(self):
+        """Verifies that the form was created properly and with initial values."""
+        response = self.client.get('/views/create_update/update/article/old_article/')
+        self.assertEquals(unicode(response.context['form']['title']),
+            u'<input id="id_title" type="text" name="title" value="Old Article" maxlength="100" />')
+
+    def test_update_object(self):
+        """Verifies the form POST data and performs a redirect to
+        post_save_redirect"""
+        response = self.client.post('/views/create_update/update/article/old_article/', {
+            'title': 'Another Article',
+            'slug': 'another-article-slug',
+            'author': 1,
+            'date_created': datetime.datetime(2007, 6, 25),
+        })
+        self.assertRedirects(response,
+            'http://testserver/views/create_update/view/article/another-article-slug/',
+            target_status_code=404)
+        article = Article.objects.get(pk=1)
+        self.assertEquals(article.title, "Another Article")
+
+    def test_delete_object_confirm(self):
+        """Verifies the confirm deletion page is displayed using a GET."""
+        response = self.client.get('/views/create_update/delete/article/old_article/')
+        self.assertTemplateUsed(response, 'views/article_confirm_delete.html')
+
+    def test_delete_object_redirect(self):
+        """Verifies that post_delete_redirect works properly."""
+        response = self.client.post('/views/create_update/delete/article/old_article/')
+        self.assertRedirects(response,
+            'http://testserver/views/create_update/',
+            target_status_code=404)
+
+    def test_delete_object(self):
+        """Verifies the object actually gets deleted on a POST."""
+        response = self.client.post('/views/create_update/delete/article/old_article/')
+        try:
+            Article.objects.get(slug='old_article')
+        except Article.DoesNotExist:
+            pass
+        else:
+            self.fail('Object was not deleted.')

=== added file 'tests/templates/views/article_confirm_delete.html'
--- tests/templates/views/article_confirm_delete.html	1970-01-01 00:00:00 +0000
+++ tests/templates/views/article_confirm_delete.html	2008-06-16 18:24:56 +0000
@@ -0,0 +1,1 @@
+This template intentionally left blank
\ No newline at end of file

=== added file 'tests/templates/views/article_form.html'
--- tests/templates/views/article_form.html	1970-01-01 00:00:00 +0000
+++ tests/templates/views/article_form.html	2008-06-16 20:01:20 +0000
@@ -0,0 +1,1 @@
+This template intentionally left blank
\ No newline at end of file

=== modified file 'django/views/generic/__init__.py'
--- django/views/generic/__init__.py	2005-07-13 01:25:57 +0000
+++ django/views/generic/__init__.py	2008-06-16 18:24:52 +0000
@@ -0,0 +1,3 @@
+class GenericViewError(Exception):
+    """A problem in a generic view."""
+    pass

=== modified file 'django/views/generic/create_update.py'
--- django/views/generic/create_update.py	2007-08-12 12:59:41 +0000
+++ django/views/generic/create_update.py	2008-06-16 20:06:02 +0000
@@ -1,44 +1,73 @@
+from django.newforms.models import ModelFormMetaclass, ModelForm
+from django.template import RequestContext, loader
+from django.http import Http404, HttpResponse, HttpResponseRedirect
 from django.core.xheaders import populate_xheaders
-from django.template import loader
-from django import oldforms
-from django.db.models import FileField
-from django.contrib.auth.views import redirect_to_login
-from django.template import RequestContext
-from django.http import Http404, HttpResponse, HttpResponseRedirect
 from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
 from django.utils.translation import ugettext
-
-def create_object(request, model, template_name=None,
+from django.contrib.auth.views import redirect_to_login
+from django.views.generic import GenericViewError
+
+def deprecate_follow(follow):
+    """
+    Raises a DeprecationWarning if follow is anything but None.
+    
+    The old Manipulator-based forms used an argument named follow, but it is
+    no longer needed for newforms-based forms. 
+    """
+    if follow is not None:
+        raise DeprecationWarning(
+            "Generic views have been changed to use newforms and the 'follow'"
+            " argument is no longer supported.  Please update your code to use"
+            " the new form_class argument in order to use a custom form.")
+
+def get_model_and_form_class(model, form_class):
+    """
+    Returns a model and form class based on the model and form_class
+    parameters that were passed to the generic view.
+    
+    If ``form_class`` is given then its associated model will be returned along
+    with ``form_class`` itself.  Otherwise, if ``model`` is given, ``model``
+    itself will be returned along with a ``ModelForm`` class created from
+    ``model``.
+    """
+    if form_class:
+        return form_class._meta.model, form_class
+    if model:
+        # The inner Meta class fails if model = model is used for some reason.
+        tmp_model = model
+        # TODO: we should be able to construct a ModelForm without creating
+        # and passing in a temporary inner class.
+        class Meta:
+            model = tmp_model
+        class_name = model.__name__ + 'Form'
+        form_class = ModelFormMetaclass(class_name, (ModelForm,), {'Meta': Meta})
+        return model, form_class
+    raise GenericViewError("Generic view must be called with either a model or"
+                           " form_class argument.")
+
+def create_object(request, model=None, template_name=None,
         template_loader=loader, extra_context=None, post_save_redirect=None,
-        login_required=False, follow=None, context_processors=None):
+        login_required=False, follow=None, context_processors=None,
+        form_class=None):
     """
     Generic object-creation function.
 
     Templates: ``<app_label>/<model_name>_form.html``
     Context:
         form
-            the form wrapper for the object
+            the form for the object
     """
+    deprecate_follow(follow)
     if extra_context is None: extra_context = {}
     if login_required and not request.user.is_authenticated():
         return redirect_to_login(request.path)
-
-    manipulator = model.AddManipulator(follow=follow)
-    if request.POST:
-        # If data was POSTed, we're trying to create a new object
-        new_data = request.POST.copy()
-
-        if model._meta.has_field_type(FileField):
-            new_data.update(request.FILES)
-
-        # Check for errors
-        errors = manipulator.get_validation_errors(new_data)
-        manipulator.do_html2python(new_data)
-
-        if not errors:
-            # No errors -- this means we can save the data!
-            new_object = manipulator.save(new_data)
-
+    
+    model, form_class = get_model_and_form_class(model, form_class)
+    if request.method == 'POST':
+        form = form_class(request.POST, request.FILES)
+        if form.is_valid():
+            new_object = form.save()
+            
             if request.user.is_authenticated():
                 request.user.message_set.create(message=ugettext("The %(verbose_name)s was created successfully.") % {"verbose_name": model._meta.verbose_name})
 
@@ -51,12 +80,9 @@
             else:
                 raise ImproperlyConfigured("No URL to redirect to from generic create view.")
     else:
-        # No POST, so we want a brand new form without any data or errors
-        errors = {}
-        new_data = manipulator.flatten_data()
+        form = form_class()
 
-    # Create the FormWrapper, template, context, response
-    form = oldforms.FormWrapper(manipulator, new_data, errors)
+    # Create the template, context, response
     if not template_name:
         template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
     t = template_loader.get_template(template_name)
@@ -70,25 +96,28 @@
             c[key] = value
     return HttpResponse(t.render(c))
 
-def update_object(request, model, object_id=None, slug=None,
+def update_object(request, model=None, object_id=None, slug=None,
         slug_field='slug', template_name=None, template_loader=loader,
         extra_context=None, post_save_redirect=None,
         login_required=False, follow=None, context_processors=None,
-        template_object_name='object'):
+        template_object_name='object', form_class=None):
     """
     Generic object-update function.
 
     Templates: ``<app_label>/<model_name>_form.html``
     Context:
         form
-            the form wrapper for the object
+            the form for the object
         object
             the original object being edited
     """
+    deprecate_follow(follow)
     if extra_context is None: extra_context = {}
     if login_required and not request.user.is_authenticated():
         return redirect_to_login(request.path)
-
+    
+    model, form_class = get_model_and_form_class(model, form_class)
+    
     # Look up the object to be edited
     lookup_kwargs = {}
     if object_id:
@@ -96,22 +125,16 @@
     elif slug and slug_field:
         lookup_kwargs['%s__exact' % slug_field] = slug
     else:
-        raise AttributeError("Generic edit view must be called with either an object_id or a slug/slug_field")
+        raise GenericViewError("Generic edit view must be called with either an object_id or a slug/slug_field")
     try:
         object = model.objects.get(**lookup_kwargs)
     except ObjectDoesNotExist:
         raise Http404, "No %s found for %s" % (model._meta.verbose_name, lookup_kwargs)
 
-    manipulator = model.ChangeManipulator(getattr(object, object._meta.pk.attname), follow=follow)
-
-    if request.POST:
-        new_data = request.POST.copy()
-        if model._meta.has_field_type(FileField):
-            new_data.update(request.FILES)
-        errors = manipulator.get_validation_errors(new_data)
-        manipulator.do_html2python(new_data)
-        if not errors:
-            object = manipulator.save(new_data)
+    if request.method == 'POST':
+        form = form_class(request.POST, request.FILES, instance=object)
+        if form.is_valid():
+            object = form.save()
 
             if request.user.is_authenticated():
                 request.user.message_set.create(message=ugettext("The %(verbose_name)s was updated successfully.") % {"verbose_name": model._meta.verbose_name})
@@ -124,11 +147,8 @@
             else:
                 raise ImproperlyConfigured("No URL to redirect to from generic create view.")
     else:
-        errors = {}
-        # This makes sure the form acurate represents the fields of the place.
-        new_data = manipulator.flatten_data()
+        form = form_class(instance=object)
 
-    form = oldforms.FormWrapper(manipulator, new_data, errors)
     if not template_name:
         template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
     t = template_loader.get_template(template_name)
@@ -145,10 +165,10 @@
     populate_xheaders(request, response, model, getattr(object, object._meta.pk.attname))
     return response
 
-def delete_object(request, model, post_delete_redirect,
-        object_id=None, slug=None, slug_field='slug', template_name=None,
-        template_loader=loader, extra_context=None,
-        login_required=False, context_processors=None, template_object_name='object'):
+def delete_object(request, model, post_delete_redirect, object_id=None,
+        slug=None, slug_field='slug', template_name=None,
+        template_loader=loader, extra_context=None, login_required=False,
+        context_processors=None, template_object_name='object'):
     """
     Generic object-delete function.
 
@@ -172,7 +192,7 @@
     elif slug and slug_field:
         lookup_kwargs['%s__exact' % slug_field] = slug
     else:
-        raise AttributeError("Generic delete view must be called with either an object_id or a slug/slug_field")
+        raise GenericViewError("Generic delete view must be called with either an object_id or a slug/slug_field")
     try:
         object = model._default_manager.get(**lookup_kwargs)
     except ObjectDoesNotExist:

=== modified file 'docs/generic_views.txt'
--- docs/generic_views.txt	2008-03-18 21:58:31 +0000
+++ docs/generic_views.txt	2008-06-16 18:24:53 +0000
@@ -701,7 +701,7 @@
       query string parameter (via ``GET``) or a ``page`` variable specified in
       the URLconf. See `Notes on pagination`_ below.
 
-    * ``page``: The current page number, as an integer. This is 1-based. 
+    * ``page``: The current page number, as an integer. This is 1-based.
       See `Notes on pagination`_ below.
 
     * ``template_name``: The full name of a template to use in rendering the
@@ -809,26 +809,26 @@
 
         /objects/?page=3
 
-    * To loop over all the available page numbers, use the ``page_range`` 
-      variable. You can iterate over the list provided by ``page_range`` 
+    * To loop over all the available page numbers, use the ``page_range``
+      variable. You can iterate over the list provided by ``page_range``
       to create a link to every page of results.
 
 These values and lists are 1-based, not 0-based, so the first page would be
-represented as page ``1``. 
+represented as page ``1``.
 
 An example of the use of pagination can be found in the `object pagination`_
-example model. 
-	 
+example model.
+
 .. _`object pagination`: ../models/pagination/
 
-**New in Django development version:** 
+**New in Django development version:**
 
-As a special case, you are also permitted to use 
+As a special case, you are also permitted to use
 ``last`` as a value for ``page``::
 
     /objects/?page=last
 
-This allows you to access the final page of results without first having to 
+This allows you to access the final page of results without first having to
 determine how many pages there are.
 
 Note that ``page`` *must* be either a valid page number or the value ``last``;
@@ -907,19 +907,33 @@
 The ``django.views.generic.create_update`` module contains a set of functions
 for creating, editing and deleting objects.
 
+**New in Django development version:**
+
+``django.views.generic.create_update.create_object`` and
+``django.views.generic.create_update.update_object`` now use `newforms`_ to
+build and display the form.
+
+.. _newforms: ../newforms/
+
 ``django.views.generic.create_update.create_object``
 ----------------------------------------------------
 
 **Description:**
 
 A page that displays a form for creating an object, redisplaying the form with
-validation errors (if there are any) and saving the object. This uses the
-automatic manipulators that come with Django models.
+validation errors (if there are any) and saving the object.
 
 **Required arguments:**
 
-    * ``model``: The Django model class of the object that the form will
-      create.
+    * Either ``form_class`` or ``model`` is required.
+
+      If you provide ``form_class``, it should be a
+      ``django.newforms.ModelForm`` subclass.  Use this argument when you need
+      to customize the model's form.  See the `ModelForm docs`_ for more
+      information.
+
+      Otherwise, ``model`` should be a Django model class and the form used
+      will be a standard ``ModelForm`` for ``model``.
 
 **Optional arguments:**
 
@@ -960,22 +974,23 @@
 
 In addition to ``extra_context``, the template's context will be:
 
-    * ``form``: A ``django.oldforms.FormWrapper`` instance representing the form
-      for editing the object. This lets you refer to form fields easily in the
+    * ``form``: A ``django.newforms.ModelForm`` instance representing the form
+      for creating the object. This lets you refer to form fields easily in the
       template system.
 
-      For example, if ``model`` has two fields, ``name`` and ``address``::
+      For example, if the model has two fields, ``name`` and ``address``::
 
           <form action="" method="post">
-          <p><label for="id_name">Name:</label> {{ form.name }}</p>
-          <p><label for="id_address">Address:</label> {{ form.address }}</p>
+          <p>{{ form.name.label_tag }} {{ form.name }}</p>
+          <p>{{ form.address.label_tag }} {{ form.address }}</p>
           </form>
 
-      See the `manipulator and formfield documentation`_ for more information
-      about using ``FormWrapper`` objects in templates.
+      See the `newforms documentation`_ for more information about using
+      ``Form`` objects in templates.
 
 .. _authentication system: ../authentication/
-.. _manipulator and formfield documentation: ../forms/
+.. _ModelForm docs: ../newforms/modelforms
+.. _newforms documentation: ../newforms/
 
 ``django.views.generic.create_update.update_object``
 ----------------------------------------------------
@@ -988,8 +1003,15 @@
 
 **Required arguments:**
 
-    * ``model``: The Django model class of the object that the form will
-      create.
+    * Either ``form_class`` or ``model`` is required.
+
+      If you provide ``form_class``, it should be a
+      ``django.newforms.ModelForm`` subclass.  Use this argument when you need
+      to customize the model's form.  See the `ModelForm docs`_ for more
+      information.
+
+      Otherwise, ``model`` should be a Django model class and the form used
+      will be a standard ``ModelForm`` for ``model``.
 
     * Either ``object_id`` or (``slug`` *and* ``slug_field``) is required.
 
@@ -1042,19 +1064,19 @@
 
 In addition to ``extra_context``, the template's context will be:
 
-    * ``form``: A ``django.oldforms.FormWrapper`` instance representing the form
+    * ``form``: A ``django.newforms.ModelForm`` instance representing the form
       for editing the object. This lets you refer to form fields easily in the
       template system.
 
-      For example, if ``model`` has two fields, ``name`` and ``address``::
+      For example, if the model has two fields, ``name`` and ``address``::
 
           <form action="" method="post">
-          <p><label for="id_name">Name:</label> {{ form.name }}</p>
-          <p><label for="id_address">Address:</label> {{ form.address }}</p>
+          <p>{{ form.name.label_tag }} {{ form.name }}</p>
+          <p>{{ form.address.label_tag }} {{ form.address }}</p>
           </form>
 
-      See the `manipulator and formfield documentation`_ for more information
-      about using ``FormWrapper`` objects in templates.
+      See the `newforms documentation`_ for more information about using
+      ``Form`` objects in templates.
 
     * ``object``: The original object being edited. This variable's name
       depends on the ``template_object_name`` parameter, which is ``'object'``

=== modified file 'tests/regressiontests/views/tests/__init__.py'
--- tests/regressiontests/views/tests/__init__.py	2007-09-19 13:26:56 +0000
+++ tests/regressiontests/views/tests/__init__.py	2008-06-16 18:24:55 +0000
@@ -1,4 +1,5 @@
 from defaults import *
 from i18n import *
 from static import *
-from generic.date_based import *
\ No newline at end of file
+from generic.date_based import *
+from generic.create_update import *
\ No newline at end of file

=== modified file 'tests/regressiontests/views/urls.py'
--- tests/regressiontests/views/urls.py	2007-09-19 13:26:56 +0000
+++ tests/regressiontests/views/urls.py	2008-06-16 19:52:46 +0000
@@ -20,6 +20,10 @@
     'month_format': '%m', 
 } 
 
+crud_form_info_dict = {
+    'model': Article,
+}
+
 urlpatterns = patterns('',
     (r'^$', views.index_page),
     
@@ -44,5 +48,16 @@
         dict(allow_future=True, slug_field='slug', **date_based_info_dict)), 
     (r'^date_based/archive_month/(?P<year>\d{4})/(?P<month>\d{1,2})/$', 
         'django.views.generic.date_based.archive_month', 
-        date_based_info_dict),     
+        date_based_info_dict),
+    
+    # crud generic views
+    (r'^create_update/member/create/article/$', 'django.views.generic.create_update.create_object',
+        dict(login_required=True, **crud_form_info_dict)),
+    (r'^create_update/create/article/$', 'django.views.generic.create_update.create_object',
+        dict(post_save_redirect='/views/create_update/view/article/%(slug)s/', **crud_form_info_dict)),
+    (r'^create_update/create_custom/article/$', views.custom_create),
+    (r'create_update/update/article/(?P<slug>[-\w]+)/$', 'django.views.generic.create_update.update_object',
+        dict(post_save_redirect='/views/create_update/view/article/%(slug)s/', slug_field='slug', **crud_form_info_dict)),
+    (r'create_update/delete/article/(?P<slug>[-\w]+)/$', 'django.views.generic.create_update.delete_object',
+        dict(post_delete_redirect='/views/create_update/', slug_field='slug', **crud_form_info_dict)),
 )

=== modified file 'tests/regressiontests/views/views.py'
--- tests/regressiontests/views/views.py	2007-12-02 01:44:58 +0000
+++ tests/regressiontests/views/views.py	2008-06-16 20:03:31 +0000
@@ -1,5 +1,27 @@
 from django.http import HttpResponse
+import django.newforms as forms
+from django.views.generic.create_update import create_object
+
+from models import Article
 
 def index_page(request):
     """Dummy index page"""
     return HttpResponse('<html><body>Dummy page</body></html>')
+
+def custom_create(request):
+    """
+    Calls create_object generic view with a custom form class.
+    """
+    class SlugChangingArticleForm(forms.ModelForm):
+        """Custom form class to overwrite the slug."""
+
+        class Meta:
+            model = Article
+
+        def save(self, *args, **kwargs):
+            self.cleaned_data['slug'] = 'some-other-slug'
+            return super(SlugChangingArticleForm, self).save(*args, **kwargs)
+
+    return create_object(request,
+        post_save_redirect='/views/create_update/view/article/%(slug)s/',
+        form_class=SlugChangingArticleForm)

