1. Andriy Kornatskyy
  2. wheezy.web

Commits

Andriy Kornatskyy  committed a69d59e

Be explicit about use of widgets

  • Participants
  • Parent commits d9a9e6b
  • Branches default

Comments (0)

Files changed (3)

File demos/public/content/templates/membership/signup.html

View file
                 </p>
                 <p>
                 ${account.account_type.label('Account Type:')}
-                ${account.account_type.radio(choices=account_types.model)}
+                ${account.account_type.radio(choices=account_types)}
                 ${account.account_type.error()}
                 </p>
                 <p>
                 </p>
                 <p>
                 ${model.questionid.label('Security question:')}
-                ${model.questionid.dropdown(choices=questions.model)}
+                ${model.questionid.dropdown(choices=questions)}
                 ${model.questionid.error()}
                 </p>
                 <p>

File demos/public/src/membership/web/views.py

View file
 from wheezy.core.collections import attrdict
 from wheezy.core.comp import u
 from wheezy.core.descriptors import attribute
-from wheezy.http import bad_request
 from wheezy.security import Principal
 from wheezy.web import authorize
 from wheezy.web import handler_cache
             return self.redirect_for('default')
         credential = credential or Credential()
         return self.render_response('membership/signin.html',
-                credential=credential,
-                model=self.model)
+                self.widgets(
+                    credential=credential,
+                    model=self.model))
 
     def post(self):
         if not self.validate_xsrf_token():
             return self.redirect_for('default')
         registration = registration or Registration()
         return self.render_response('membership/signup.html',
-                registration=registration,
-                credential=registration.credential,
-                account=registration.account,
-                model=self.model,
+                self.widgets(
+                    registration=registration,
+                    credential=registration.credential,
+                    account=registration.account,
+                    model=self.model),
                 questions=sorted(
                     self.factory.membership.password_questions.items(),
                     key=itemgetter(1)),

File src/wheezy/web/handlers/base.py

View file
 from wheezy.security import Principal
 from wheezy.validation import ValidationMixin
 from wheezy.validation import try_update_model
-from wheezy.web.comp import iteritems
 from wheezy.web.handlers.method import MethodHandler
 
 
                 model, values or self.request.form, self.errors,
                 self.translations['validation'])
 
+    # region: widgets
+
+    def widgets(self, **kwargs):
+        errors = self.errors
+        return [(name, widget(kwargs[name], errors))
+                    for name in kwargs]
+
     # region: templates
 
     @attribute
         return {
             '_': self._,
             'absolute_url_for': self.absolute_url_for,
+            'errors': self.errors,
+            'handler': self,
             'path_for': self.path_for,
             'principal': self.principal,
             'resubmission': self.resubmission_widget,
             'xsrf': self.xsrf_widget
         }
 
-    def render_template(self, template_name, **kwargs):
+    def render_template(self, template_name, widgets=None, **kwargs):
+        data = self.helpers
         if kwargs:
-            errors = self.errors
-            kwargs = dict([(name, widget(kwargs[name], errors))
-                    for name in kwargs])
-        kwargs.update(self.helpers)
-        return self.options['render_template'](template_name, **kwargs)
+            data.update(kwargs)
+        if widgets:
+            data.update(widgets)
+        return self.options['render_template'](template_name, **data)
 
-    def render_response(self, template_name, **kwargs):
+    def render_response(self, template_name, widgets=None, **kwargs):
         options = self.options
         response = HTTPResponse(options['CONTENT_TYPE'], options['ENCODING'])
         response.write(self.render_template(
             template_name,
+            widgets,
             **kwargs))
         return response