1. Dan Jacob
  2. pyramid_simpleform

Commits

danjac  committed 1fc88b1

renderer changes

  • Participants
  • Parent commits 289187c
  • Branches colander

Comments (0)

Files changed (1)

File pyramid_simpleform/renderers.py

View file
  • Ignore whitespace
     def __init__(self, form, csrf_field='_csrf'):
 
         self.form = form
+        self.request = self.form.request
         self.data = self.form.data
         self.csrf_field = csrf_field
 
     def value(self, name, default=None):
         return self.data.get(name, default)
 
-    def begin(self, url, **attrs):
+    def begin(self, url=None, **attrs):
         """
         Creates the opening <form> tags.
         """
-        return tags.form(url, multipart=self.form.multipart, **attrs)
+        if url is None:
+            url = url or self.request.path
+        multipart = attrs.pop('multipart', self.form.multipart)
+        return tags.form(url, multipart=multipart, **attrs)
 
     def end(self):
         """
         """
         return HTML.tag("div", self.csrf(), style="display:none;")
 
+    def hidden_tag(self, *names):
+        """
+        Convenience for printing all hidden fields in a form inside a 
+        hidden DIV. Will also render the CSRF hidden field.
+
+        :versionadded: 0.4
+        """
+        inputs = [self.hidden(name) for name in names]
+        inputs.append(self.csrf())
+        return HTML.tag("div", 
+                        tags.literal("".join(inputs)), 
+                        style="display:none;")
+
     def text(self, name, value=None, id=None, **attrs):
         """
         Outputs text input.