Commits

Chris Beaven committed e65d8f4

Give the forms the optional ability to decide whether they should be shown (e.g. the default form doesn't show if no passwords are provided)

  • Participants
  • Parent commits 8ae35a6

Comments (0)

Files changed (2)

lockdown/forms.py

         """
         return token_value is True
 
+    def show_form(self):
+        """
+        Determine whether or not the form should be shown on locked pages.
+        
+        """
+        return True
+
 
 class LockdownForm(BaseLockdownForm):
     password = forms.CharField(widget=forms.PasswordInput(render_value=False))
         
         """
         return token_value in settings.PASSWORDS
+
+    def show_form(self):
+        """
+        Show the form if there are any passwords in the LOCKDOWN_PASSWORDS
+        setting.
+         
+        """
+        return bool(settings.PASSWORDS)

lockdown/middleware.py

             session[settings.SESSION_KEY] = token
             return HttpResponseRedirect(request.path)
 
-        return render_to_response('lockdown/form.html',
-                                  {'form': form},
+        page_data = {}
+        if not hasattr(form, 'show_form') or form.show_form():
+            page_data['form'] = form
+
+        return render_to_response('lockdown/form.html', page_data,
                                   context_instance=RequestContext(request))