- avars = self.vars.copy()
- avars.update( {
- 'arttitle': article.title,
- 'author': article.author,
- 'date': article.created.isoformat(' '),
- 'uuid': article.uuid,
- 'created': article.created.isoformat(' '),
- 'updated': article.updated.isoformat(' '),
- 'tags': article.get_tags_links(),
-
- 'cyear': article.created.year,
- 'cmonth': article.created.month,
- 'cday': article.created.day,
- 'chour': article.created.hour,
- 'cminute': article.created.minute,
- 'csecond': article.created.second,
-
- 'uyear': article.updated.year,
- 'umonth': article.updated.month,
- 'uday': article.updated.day,
- 'uhour': article.updated.hour,
- 'uminute': article.updated.minute,
- 'usecond': article.updated.second,
- } )
+ return self.get_template(
+ 'art_footer', default_article_footer, article.to_vars())
+
+ def get_comment_header(self, comment):
+ vars = comment.to_vars()
+ if comment.link:
+ vars['linked_author'] = '<a href="%s">%s</a>' \
+ % (comment.link, comment.author)
+ else:
+ vars['linked_author'] = comment.author
+ return self.get_template(
+ 'com_header', default_comment_header, vars)
+
+ def get_comment_footer(self, comment):
+ return self.get_template(
+ 'com_footer', default_comment_footer, comment.to_vars())
+
+ 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,
+ }
+
+
+class Comment (object):
+ def __init__(self, article, number, created = None):
+ self.article = article
+ self.number = number
+ if created is None:
+ self.created = datetime.datetime.now()
+ else:
+ self.created = created
+
+ self.loaded = False
+
+ # loaded on demand
+ self._author = author
+ self._link = ''
+ self._raw_content = 'Removed comment'
+
+ @property
+ def author(self):
+ if not self.loaded:
+ self.load()
+ return self._author
+
+ @property
+ def link(self):
+ if not self.loaded:
+ self.load()
+ return self._link
+
+ @property
+ def raw_content(self):
+ if not self.loaded:
+ self.load()
+ return self._raw_content
+
+ def set(self, author, raw_content, link = '', created = None):
+ self.loaded = True
+ self._author = author
+ self._raw_content = raw_content
+ self._link = link
+ self.created = created or datetime.datetime.now()