def dict_for_view(self, user, through=None):
if not through:
through = self.id
humanized_timestamp = "%s (edited)" % self.humanized_timestamp if self.edited else self.humanized_timestamp
is_author = bool(user.is_authenticated and self.author == user.profile)
is_following_author = bool(user.is_authenticated and self.author_id in user.profile.following_ids)
profile_id = user.profile.id if getattr(user, "profile", None) else ""
return {
"author": self.author_id,
"author_guid": self.author.guid,
"author_handle": self.author.handle,
"author_home_url": self.author.home_url,
"author_image": self.author.safer_image_url_small,
"author_is_local": self.local,
"author_name": escape(self.author.name) or self.author.handle,
"author_profile_url": self.author.get_absolute_url(),
"reply_count": self.reply_count,
"content_type": self.content_type.string_value,
"delete_url": reverse("content:delete", kwargs={"pk": self.id}) if is_author else "",
"detail_url": self.get_absolute_url(),
"formatted_timestamp": self.timestamp,
"guid": self.guid,
"has_shared": Content.has_shared(self.id, profile_id) if profile_id else False,
"humanized_timestamp": humanized_timestamp,
"id": self.id,
"is_authenticated": bool(user.is_authenticated),
"is_author": is_author,
"is_following_author": is_following_author,
"parent": self.parent_id if self.content_type == ContentType.REPLY else "",
"profile_id": profile_id,
"rendered": self.rendered,
"reply_url": reverse("content:reply", kwargs={"pk": self.id}) if user.is_authenticated else "",
"shares_count": self.shares_count,
"slug": self.slug,
"through": through,
"update_url": reverse("content:update", kwargs={"pk": self.id}) if is_author else "",
}
评论列表
文章目录