+ def get_comment_form(self, article, form_data, captcha_puzzle):
+ vars = article.to_vars()
+ vars.update(form_data.to_vars(self))
+ vars['captcha_puzzle'] = captcha_puzzle
+ return self.get_template(
+ 'com_form', default_comment_form, vars)
+
+ def get_comment_error(self, error):
+ return self.get_template(
+ 'com_error', default_comment_error, dict(error=error))
+
+
+class CommentFormData (object):
+ def __init__(self, author = '', link = '', captcha = '', body = ''):
+ self.author = author
+ self.link = link
+ self.captcha = captcha
+ self.body = body
+ self.author_error = ''
+ self.link_error = ''
+ self.captcha_error = ''
+ self.body_error = ''
+ self.action = ''
+ self.method = 'post'
+
+ def to_vars(self, template):
+ render_error = template.get_comment_error
+ a_error = self.author_error and render_error(self.author_error)
+ l_error = self.link_error and render_error(self.link_error)
+ c_error = self.captcha_error \
+ and render_error(self.captcha_error)
+ b_error = self.body_error and render_error(self.body_error)
+ return {
+ 'form_author': sanitize(self.author),
+ 'form_link': sanitize(self.link),
+ 'form_captcha': sanitize(self.captcha),
+ 'form_body': sanitize(self.body),
+
+ 'form_author_error': a_error,
+ 'form_link_error': l_error,
+ 'form_captcha_error': c_error,
+ 'form_body_error': b_error,
+
+ 'form_action': self.action,
+ 'form_method': self.method,
+ }
+