Author: gwilson
Date: 2007-10-29 18:52:17 -0500 (Mon, 29 Oct 2007)
New Revision: 6627

Modified:
   django/trunk/django/newforms/models.py
Log:
Style fixes.


Modified: django/trunk/django/newforms/models.py
===================================================================
--- django/trunk/django/newforms/models.py      2007-10-28 22:32:25 UTC (rev 
6626)
+++ django/trunk/django/newforms/models.py      2007-10-29 23:52:17 UTC (rev 
6627)
@@ -6,7 +6,6 @@
 from django.utils.translation import ugettext
 from django.utils.encoding import smart_unicode
 
-
 from util import ValidationError
 from forms import BaseForm, SortedDictFromList
 from fields import Field, ChoiceField
@@ -17,7 +16,8 @@
     'ModelChoiceField', 'ModelMultipleChoiceField'
 )
 
-def save_instance(form, instance, fields=None, fail_message='saved', 
commit=True):
+def save_instance(form, instance, fields=None, fail_message='saved',
+                  commit=True):
     """
     Saves bound Form ``form``'s cleaned_data into model instance ``instance``.
 
@@ -27,15 +27,17 @@
     from django.db import models
     opts = instance.__class__._meta
     if form.errors:
-        raise ValueError("The %s could not be %s because the data didn't 
validate." % (opts.object_name, fail_message))
+        raise ValueError("The %s could not be %s because the data didn't"
+                         " validate." % (opts.object_name, fail_message))
     cleaned_data = form.cleaned_data
     for f in opts.fields:
-        if not f.editable or isinstance(f, models.AutoField) or not f.name in 
cleaned_data:
+        if not f.editable or isinstance(f, models.AutoField) \
+                or not f.name in cleaned_data:
             continue
         if fields and f.name not in fields:
             continue
-        f.save_form_data(instance, cleaned_data[f.name])        
-    # Wrap up the saving of m2m data as a function
+        f.save_form_data(instance, cleaned_data[f.name])
+    # Wrap up the saving of m2m data as a function.
     def save_m2m():
         opts = instance.__class__._meta
         cleaned_data = form.cleaned_data
@@ -45,28 +47,29 @@
             if f.name in cleaned_data:
                 f.save_form_data(instance, cleaned_data[f.name])
     if commit:
-        # If we are committing, save the instance and the m2m data immediately
+        # If we are committing, save the instance and the m2m data immediately.
         instance.save()
         save_m2m()
     else:
-        # We're not committing. Add a method to the form to allow deferred 
-        # saving of m2m data
+        # We're not committing. Add a method to the form to allow deferred
+        # saving of m2m data.
         form.save_m2m = save_m2m
     return instance
 
 def make_model_save(model, fields, fail_message):
-    "Returns the save() method for a Form."
+    """Returns the save() method for a Form."""
     def save(self, commit=True):
         return save_instance(self, model(), fields, fail_message, commit)
     return save
-    
+
 def make_instance_save(instance, fields, fail_message):
-    "Returns the save() method for a Form."
+    """Returns the save() method for a Form."""
     def save(self, commit=True):
         return save_instance(self, instance, fields, fail_message, commit)
     return save
 
-def form_for_model(model, form=BaseForm, fields=None, 
formfield_callback=lambda f: f.formfield()):
+def form_for_model(model, form=BaseForm, fields=None,
+                   formfield_callback=lambda f: f.formfield()):
     """
     Returns a Form class for the given Django model class.
 
@@ -87,10 +90,12 @@
         if formfield:
             field_list.append((f.name, formfield))
     base_fields = SortedDictFromList(field_list)
-    return type(opts.object_name + 'Form', (form,), 
-        {'base_fields': base_fields, '_model': model, 'save': 
make_model_save(model, fields, 'created')})
+    return type(opts.object_name + 'Form', (form,),
+        {'base_fields': base_fields, '_model': model,
+         'save': make_model_save(model, fields, 'created')})
 
-def form_for_instance(instance, form=BaseForm, fields=None, 
formfield_callback=lambda f, **kwargs: f.formfield(**kwargs)):
+def form_for_instance(instance, form=BaseForm, fields=None,
+                      formfield_callback=lambda f, **kwargs: 
f.formfield(**kwargs)):
     """
     Returns a Form class for the given Django model instance.
 
@@ -115,16 +120,22 @@
             field_list.append((f.name, formfield))
     base_fields = SortedDictFromList(field_list)
     return type(opts.object_name + 'InstanceForm', (form,),
-        {'base_fields': base_fields, '_model': model, 'save': 
make_instance_save(instance, fields, 'changed')})
+        {'base_fields': base_fields, '_model': model,
+         'save': make_instance_save(instance, fields, 'changed')})
 
 def form_for_fields(field_list):
-    "Returns a Form class for the given list of Django database field 
instances."
-    fields = SortedDictFromList([(f.name, f.formfield()) for f in field_list 
if f.editable])
+    """
+    Returns a Form class for the given list of Django database field instances.
+    """
+    fields = SortedDictFromList([(f.name, f.formfield())
+                                 for f in field_list if f.editable])
     return type('FormForFields', (BaseForm,), {'base_fields': fields})
 
 class QuerySetIterator(object):
     def __init__(self, queryset, empty_label, cache_choices):
-        self.queryset, self.empty_label, self.cache_choices = queryset, 
empty_label, cache_choices
+        self.queryset = queryset
+        self.empty_label = empty_label
+        self.cache_choices = cache_choices
 
     def __iter__(self):
         if self.empty_label is not None:
@@ -136,11 +147,13 @@
             self.queryset._result_cache = None
 
 class ModelChoiceField(ChoiceField):
-    "A ChoiceField whose choices are a model QuerySet."
+    """A ChoiceField whose choices are a model QuerySet."""
     # This class is a subclass of ChoiceField for purity, but it doesn't
     # actually use any of ChoiceField's implementation.
+
     def __init__(self, queryset, empty_label=u"---------", cache_choices=False,
-            required=True, widget=Select, label=None, initial=None, 
help_text=None):
+                 required=True, widget=Select, label=None, initial=None,
+                 help_text=None):
         self.queryset = queryset
         self.empty_label = empty_label
         self.cache_choices = cache_choices
@@ -160,7 +173,8 @@
         # *each* time _get_choices() is called (and, thus, each time
         # self.choices is accessed) so that we can ensure the QuerySet has not
         # been consumed.
-        return QuerySetIterator(self.queryset, self.empty_label, 
self.cache_choices)
+        return QuerySetIterator(self.queryset, self.empty_label,
+                                self.cache_choices)
 
     def _set_choices(self, value):
         # This method is copied from ChoiceField._set_choices(). It's necessary
@@ -177,16 +191,20 @@
         try:
             value = self.queryset.model._default_manager.get(pk=value)
         except self.queryset.model.DoesNotExist:
-            raise ValidationError(ugettext(u'Select a valid choice. That 
choice is not one of the available choices.'))
+            raise ValidationError(ugettext(u'Select a valid choice. That'
+                                           u' choice is not one of the'
+                                           u' available choices.'))
         return value
 
 class ModelMultipleChoiceField(ModelChoiceField):
-    "A MultipleChoiceField whose choices are a model QuerySet."
+    """A MultipleChoiceField whose choices are a model QuerySet."""
     hidden_widget = MultipleHiddenInput
+
     def __init__(self, queryset, cache_choices=False, required=True,
-            widget=SelectMultiple, label=None, initial=None, help_text=None):
-        super(ModelMultipleChoiceField, self).__init__(queryset, None, 
cache_choices,
-            required, widget, label, initial, help_text)
+                 widget=SelectMultiple, label=None, initial=None,
+                 help_text=None):
+        super(ModelMultipleChoiceField, self).__init__(queryset, None,
+            cache_choices, required, widget, label, initial, help_text)
 
     def clean(self, value):
         if self.required and not value:
@@ -200,7 +218,9 @@
             try:
                 obj = self.queryset.model._default_manager.get(pk=val)
             except self.queryset.model.DoesNotExist:
-                raise ValidationError(ugettext(u'Select a valid choice. %s is 
not one of the available choices.') % val)
+                raise ValidationError(ugettext(u'Select a valid choice. %s is'
+                                               u' not one of the available'
+                                               u' choices.') % val)
             else:
                 final_values.append(obj)
         return final_values


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to