Commits

Steve Losh committed 0c5b058

Clean up for release.

Comments (0)

Files changed (11)

 =================
 
 Customizing the markup of Django forms is a pain. django-goodfields tries to
-make it hurt less by making it easy to render form fields and add inline
-validation.
+make it hurt less by making it easy to render form fields.
 
 Requirements
 ------------
 
 * [Django][] 1.1+
 
-Inline validation:
-
-* [jQuery][]
-* [LiveValidation][]
-
 [Django]: http://djangoproject.com/
-[jQuery]: http://jquery.com/
-[LiveValidation]: http://livevalidation.com/
 
 Installation
 ------------
 
 ### With Pip
 
-    pip install -e hg+http://bitbucket.org/dwaiter/django-goodfields@stable#egg=django-goodfields
-    
+    pip install -e hg+http://bitbucket.org/dwaiter/django-goodfields#egg=django-goodfields
     # or...
-    
-    pip install -e git://github.com/dwaiter/django-goodfields@stable#egg=django-goodfields
+    pip install -e git://github.com/dwaiter/django-goodfields#egg=django-goodfields
 
-Now symlink (or copy) the media into your project:
+Now copy the sample templates into your project:
 
-    ln -s /path/to/django-goodfields/goodfields/media/goodfields/ media/goodfields
+    cp -R /path/to/django-goodfields/goodfields/templates/goodfields/ templates/goodfields
 
 ### Or From Source
 
 Get the code:
 
     hg clone http://bitbucket.org/dwaiter/django-goodfields/
-    hg update stable
-    
     # or...
-    
     git clone git://github.com/dwaiter/django-goodfields/
-    git checkout stable
 
 Install:
 
     cd django-goodfields
     python setup.py install
 
-Now symlink (or copy) the media into your project:
+Now copy the sample templates into your project:
 
-    ln -s /path/to/django-goodfields/goodfields/media/goodfields/ media/goodfields
+    cp -R /path/to/django-goodfields/goodfields/templates/goodfields/ templates/goodfields
 
 Usage (Field Rendering)
 -----------------------
 fields in your form:
 
     <h1>Sign up for free!</h1>
-    
+
     <form action="" method="post">
-        
+
         {% load goodfields %}
         {% goodfield form.username text %}
         {% goodfield form.first_name text %}
         {% goodfield form.last_name text %}
         {% goodfield form.password password %}
-        
+
         {{ form.non_field_errors }}
         <input type="submit" value="Sign Up" />
     </form>
 
     <div class="field" id="id_username-container">
         <label for="id_username">Username</label>
-        <input type="text" class="text" id="id_username" 
+        <input type="text" class="text" id="id_username"
                name="username"
                value="" />
     </div>
 
 Feel free to customize the templates to look however you prefer. Each field
 type (`text`, `password`, `radio`, etc) has its own template in
-templates/goodfields. You can add new field types by adding new templates.
+`templates/goodfields`. You can add new field types by adding new templates.
 
 django-goodfields will use the `label` attribute of the form field to create
 the `<label>` element by default. You can specify a custom label for a
         <input type="submit" value="Sign Up" />
     </form>
 
-Usage (Inline Validation)
--------------------------
+You can also use the `class` keyword in the tag to pass a value along into the
+template as the variable `class`.  This is intended to be used to specify CSS
+classes:
 
-django-goodfields can automatically add some sane inline validation to
-rendered form fields by looking at attributes of your Django fields.
-
-To use this you'll first need to include the [jQuery][] and [LiveValidation][]
-libraries somewhere in your pages.
-
+    {% goodfield form.email text class "full-column" %}
+    {% goodfield form.first_name text class "half-column" %}
+    {% goodfield form.last_name text class "half-column" %}

goodfields/media/goodfields/goodfields.css

-span.LV_validation_message {
-    margin-left: 1.5em;
-}
-span.LV_validation_message.LV_invalid {
-    color: #F10057;
-}
-div.field .LV_invalid_field, 
-div.field input.LV_invalid_field,
-div.field textarea.LV_invalid_field {
-    border: 1px solid #F10057;
-}

goodfields/templates/goodfields/fields/checkbox.html

-<li>
+<li class="{{ class }}">
     <label>
         <input id="{{ field.auto_id }}" type="checkbox" class="checkbox"
                name="{{ field.html_name }}"

goodfields/templates/goodfields/fields/password.html

-{% if validate %}
-{% include "goodfields/fields/validation.html" %}   
-{% endif %}
-
-
-<div class="field">
+<div class="{{ class }} field">
     <label for="{{ field.auto_id }}">{% firstof label field.label %} {{ field.errors }}</label>
-    <input type="password" class="password" id="{{ field.auto_id }}" 
+    <input type="password" class="password" id="{{ field.auto_id }}"
            name="{{ field.html_name }}" />
     {% if field.help_text %}
         <p class="form-help-text">{{ field.help_text }}</p>

goodfields/templates/goodfields/fields/radio.html

-<label>{{ label }} {{ field.errors }}</label>
-<ul class="fields">
-    {% for choice in field.field.choices %}
-        <li>
-            <label>
-            <input type="radio" class="radio"
-                   name="{{ field.html_name }}"
-                   value="{{ choice.0 }}"
-                   {% ifequal initial choice.0 %}checked="checked"{% endifequal %} />
-            {{ choice.1 }}
-            </label>
-        </li>
-    {% endfor %}
-</ul>
-{% if field.help_text %}
-    <p class="form-help-text">{{ field.help_text }}</p>
-{% endif %}
+<div class="{{ class }}">
+    <label>{{ label }} {{ field.errors }}</label>
+    <ul class="fields">
+        {% for choice in field.field.choices %}
+            <li>
+                <label>
+                <input type="radio" class="radio"
+                       name="{{ field.html_name }}"
+                       value="{{ choice.0 }}"
+                       {% ifequal initial choice.0 %}checked="checked"{% endifequal %} />
+                {{ choice.1 }}
+                </label>
+            </li>
+        {% endfor %}
+    </ul>
+    {% if field.help_text %}
+        <p class="form-help-text">{{ field.help_text }}</p>
+    {% endif %}
+</div>

goodfields/templates/goodfields/fields/text-date.html

-{% if validate %}
-{% include "goodfields/fields/validation.html" %}   
-{% endif %}
-
-
-<div class="field">
+<div class="{{ class }} field">
     <label for="{{ field.auto_id }}">{% firstof label field.label %} {{ field.errors }}</label>
     <input type="text" class="text" id="{{ field.auto_id }}" 
            name="{{ field.html_name }}"

goodfields/templates/goodfields/fields/text-datetime.html

-<div class="split-datetime-field">
+<div class="{{ class }} split-datetime-field">
     {{ field.errors }}
-    
+
     <div class="field split-datetime-date-field">
         <label for="{{ field.auto_id }}_0">{% firstof label field.label %} Date</label>
-        <input type="text" class="text" id="{{ field.auto_id }}_0" 
+        <input type="text" class="text" id="{{ field.auto_id }}_0"
                name="{{ field.html_name }}_0"
                value="{% if initial_date %}{{ initial_date }}{% endif %}" />
 
 
     <div class="field split-datetime-time-field">
         <label for="{{ field.auto_id }}_1">{% firstof label field.label %} Time</label>
-        <input type="text" class="text" id="{{ field.auto_id }}_1" 
+        <input type="text" class="text" id="{{ field.auto_id }}_1"
                name="{{ field.html_name }}_1"
                value="{% if initial_time %}{{ initial_time }}{% endif %}" />
     </div>
             firstDay: 1
         });
     });
-</script>
+</script>

goodfields/templates/goodfields/fields/text.html

-{% if validate %}
-{% include "goodfields/fields/validation.html" %}   
-{% endif %}
-
-
-<div class="field" id="{{ field.auto_id }}-container">
+<div class="{{ class }} field" id="{{ field.auto_id }}-container">
     <label for="{{ field.auto_id }}">{% firstof label field.label %}</label>
     <input type="text" class="text" id="{{ field.auto_id }}" 
            name="{{ field.html_name }}"

goodfields/templates/goodfields/fields/textarea.html

-{% if validate %}
-{% include "goodfields/fields/validation.html" %}   
-{% endif %}
-
-
-<div class="field" id="{{ field.auto_id }}-container">
+<div class="{{ class }} field" id="{{ field.auto_id }}-container">
     <label for="{{ field.auto_id }}">{% firstof label field.label %} {{ field.errors }}</label>
     <textarea id="{{ field.auto_id }}" rows="8"
               name="{{ field.html_name }}">{% if initial %}{{ initial }}{% endif %}</textarea>

goodfields/templates/goodfields/fields/validation.html

-{% if field.field.required or field.field.min_length or field.field.max_length or validation %}
-
-<script type="text/javascript" charset="utf-8">
-    $(function() {
-        var lv = new LiveValidation(
-            "{{ field.auto_id }}", { validMessage: " ", onlyOnBlur: true,
-                onValid: function() {
-                    this.insertMessage( this.createMessageSpan() );
-                    this.addFieldClass();
-                    $("#{{ field.auto_id }}-container ul.errorlist").hide();
-                }
-            });
-        
-        {% if field.field.required %}
-            lv.add(
-                Validate.Presence,
-                { failureMessage: "This field is required." }
-            );
-        {% endif %}
-        {% if field.field.min_length or field.field.max_length %}
-            lv.add(
-                Validate.Length,
-                {
-                    minimum: {% firstof field.field.min_length "0" %},
-                    maximum: {% firstof field.field.max_length "1000000000000000" %}
-                }
-            );
-        {% endif %}
-        {% if validation.email %}
-            lv.add(Validate.Email);
-        {% endif %}
-        {% if validation.pattern %}
-            lv.add(
-                Validate.Format,
-                {
-                    pattern: {{ validation.pattern.re }},
-                    failureMessage: "{{ validation.pattern.message }}"
-                }
-            );
-        {% endif %}
-    });
-</script>
-
-{% endif %}

goodfields/templatetags/goodfields.py

 from django import template
-from django.conf import settings
 from django.template.loader import render_to_string
 
-validate = (hasattr(settings, 'GOODFIELDS_VALIDATE') and settings.GOODFIELDS_VALIDATE)
 register = template.Library()
 
 class GoodfieldNode(template.Node):
-    def __init__(self, field, field_type, label=None, cls='', validation=None):
+    def __init__(self, field, field_type, label=None, cls=''):
         self.field = template.Variable(field)
         self.field_type = field_type.strip('\'"')
         self.label = label.strip('\'"') if label else None
         self.cls = cls.strip('\'"')
-        self.validation = validation
-    
+
     def render(self, context):
         field = self.field.resolve(context)
         f = field.form
         initial = field.data if f.data else f.initial.get(field.name, '')
         label = self.label or field.label
-        
+
         template = "goodfields/fields/%s.html" % self.field_type
-        
+
         return render_to_string(template, {
             'field': field,
             'initial': initial,
             'label': label,
             'class': self.cls,
-            'validation': self.validation,
-            'validate': validate,
         })
-    
+
 
 
 @register.tag
 def goodfield(parser, token):
     """Render good form fields."""
-    
+
     bits = token.split_contents()
     tag_name = bits.pop(0)
-    
+
     if len(bits) < 2:
         raise template.TemplateSyntaxError(
             u"'%s' tag requires at least a field and field type." % tag_name
         )
-    
+
     field = bits.pop(0)
     field_type = bits.pop(0)
-    
-    bits, kwargs = iter(bits), { 'validation': {} }
-    
+
+    bits, kwargs = iter(bits), {}
+
     for bit in bits:
         if bit == 'label':
             kwargs['label'] = bits.next()
         if bit == 'class':
             kwargs['cls'] = bits.next()
-        if bit == 'email':
-            kwargs['validation']['email'] = True
-        if bit == 'pattern':
-            kwargs['validation']['pattern'] = {
-                're': bits.next().strip('"'),
-                'message': bits.next().strip('"'),
-            }
-    
+
     return GoodfieldNode(field, field_type, **kwargs)