Exemplo n.º 1
0
def comments(context):
    bo = context.get('object')
    comments = Comment.get_comments(bo)
    length = len(comments)
    thread = {}
    for comment in comments:
        thread.setdefault(getattr(comment.re, 'id', 0), []).append(comment)

    def html_thread(ul):
        html = u"<ul>"
        for li in ul:
            html += u'''<li><div class='comment'>
				<div class='comment-title'><b>%(username)s</b>, %(date)s написал(а):
					<a href="javascript:;" comment_id='%(id)s' class="local-link add_comment">Комментировать</a>
				</div>
				%(text)s</div>''' % {
                'username':
                li.username,
                'date':
                dt.ru_strftime(
                    u"%d %B %Y г. в %H:%M", li.date_created, inflected=True),
                'text':
                li.text,
                'id':
                li.id
            }
            if li.id in thread:
                html += html_thread(thread[li.id])
            html += u"</li>"
        html += u"</ul>"
        return html

    html = html_thread(thread.get(0, []))

    return {'object': bo, 'length': length, 'html': html}
Exemplo n.º 2
0
def comments(context):
	bo = context.get('object')
	comments = Comment.get_comments(bo)
	length = len(comments)
	thread = {}
	for comment in comments:
		thread.setdefault(getattr(comment.re, 'id', 0), []).append(comment)

	def html_thread(ul):
		html = u"<ul>"
		for li in ul:
			html += u'''<li><div class='comment'>
				<div class='comment-title'><b>%(username)s</b>, %(date)s написал(а):
					<a href="javascript:;" comment_id='%(id)s' class="local-link add_comment">Комментировать</a>
				</div>
				%(text)s</div>'''%{
						'username': li.username,
						'date': dt.ru_strftime(u"%d %B %Y г. в %H:%M", li.date_created, inflected=True),
						'text': li.text,
						'id': li.id}
			if li.id in thread:
				html += html_thread(thread[li.id])
			html += u"</li>"
		html += u"</ul>"
		return html
	html = html_thread(thread.get(0, []))

	return {'object': bo, 'length': length, 'html': html}
Exemplo n.º 3
0
def comments_count(bo):
    return Comment.get_comments_count(bo)
Exemplo n.º 4
0
def comments_count(bo):
	return Comment.get_comments_count(bo)