Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3409 -- Added render_value argument to newforms PasswordInput.…

… Thanks for the patch, scott@staplefish.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4523 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b93614ada658087cbc90403ee8f36d7f8c947dfe 1 parent a13a47e
Adrian Holovaty authored February 15, 2007
1  AUTHORS
@@ -157,6 +157,7 @@ answer newbie questions, and generally made Django that much better:
157 157
     Oliver Rutherfurd <http://rutherfurd.net/>
158 158
     Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
159 159
     David Schein
  160
+    scott@staplefish.com
160 161
     serbaut@gmail.com
161 162
     Pete Shinners <pete@shinners.org>
162 163
     SmileyChris <smileychris@gmail.com>
8  django/newforms/widgets.py
@@ -81,6 +81,14 @@ class TextInput(Input):
81 81
 class PasswordInput(Input):
82 82
     input_type = 'password'
83 83
 
  84
+    def __init__(self, attrs=None, render_value=True):
  85
+        self.attrs = attrs or {}
  86
+        self.render_value = render_value
  87
+
  88
+    def render(self, name, value, attrs=None):
  89
+        if not self.render_value: value=None
  90
+        return super(PasswordInput, self).render(name, value, attrs)
  91
+
84 92
 class HiddenInput(Input):
85 93
     input_type = 'hidden'
86 94
     is_hidden = True
16  tests/regressiontests/forms/tests.py
@@ -72,6 +72,22 @@
72 72
 >>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'})
73 73
 u'<input type="password" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" name="email" />'
74 74
 
  75
+The render_value argument lets you specify whether the widget should render
  76
+its value. You may want to do this for security reasons.
  77
+>>> w = PasswordInput(render_value=True)
  78
+>>> w.render('email', 'secret')
  79
+u'<input type="password" name="email" value="secret" />'
  80
+>>> w = PasswordInput(render_value=False)
  81
+>>> w.render('email', '')
  82
+u'<input type="password" name="email" />'
  83
+>>> w.render('email', None)
  84
+u'<input type="password" name="email" />'
  85
+>>> w.render('email', 'secret')
  86
+u'<input type="password" name="email" />'
  87
+>>> w = PasswordInput(attrs={'class': 'fun'}, render_value=False)
  88
+>>> w.render('email', 'secret')
  89
+u'<input type="password" class="fun" name="email" />'
  90
+
75 91
 # HiddenInput Widget ############################################################
76 92
 
77 93
 >>> w = HiddenInput()

0 notes on commit b93614a

Please sign in to comment.
Something went wrong with that request. Please try again.