1. Benoit Chesneau
  2. Pypaste

Commits

ben...@pollen  committed 86551f7

added validation

  • Participants
  • Parent commits 07f0700
  • Branches default

Comments (0)

Files changed (2)

File friendpaste/views.py

View file
         ('private', 'Require a password to view and edit')
 ]
 
+
+
 class PasteForm(Form):
     title=TextField('Title')
     snippet=TextAreaField('Paste', [validators.length(min=3, max=500000)])
     privacy = SelectField(u'Kind of paste', choices=PRIVACY_CHOICES, default='open')
     password = PasswordField(u'Password', default='')
 
+    def validate_privacy(form, field):
+        if field.data != "open" and not form.data['password']:
+            raise ValidationError(u'Password is empty.')
+
 def create_snippet(request):
     mimetypes = request.accept_mimetypes
     if request.method=='POST' and 'application/json' in mimetypes:

File templates/paste/index.html

View file
             {% if form.snippet.errors %}
             <li><strong>Paste text:</strong><ul>{% for e in form.snippet.errors %}<li>{{ e }}</li>{% endfor %}</ul></li>
             {% endif %}
+            {% if form.privacy.errors %}
+            <li><strong>Paste password:</strong><ul>{% for e in form.password.errors %}<li>{{ e }}</li>{% endfor %}</ul></li>
+            {% endif %}
         </ul>
         {% endif %}
         <div{% if form.snippet.errors %}
         <strong>remove</strong> or 
         <strong>lock edit</strong> of paste you upload.</p></li>
             <li><span class="privacy">Privacy settings</span>
-                <ol id="privacy" class="hidden">
-                    <li>{{ form.privacy.label }}{{ form.privacy }}</li>
-                    <li>{{ form.password.label }}{{ form.password }}</li>
+            <ol id="privacy"{% if form.data['privacy'] == "open"%} class="hidden"{% endif %}>
+                <li>{{ form.privacy.label }}{{ form.privacy }}</li>
+                    <li{% if form.privacy.errors %}
+            class="errors"{% endif %}>{{ form.password.label }}{{ form.password }}</li>
                 </ol>
             </li>
             <li class="ccode"><input type="submit" name="psubmit" value="Submit post" /></li>