Use correct fullname prefixes for message parents

Previously, all parent_id values would be prefixed with t4_ (message),
even if the message was from a comment, which would actually have either
a comment or link parent.
This commit is contained in:
Chad Birch
2013-05-08 23:39:41 -06:00
parent 810bbc1096
commit 6211d82f7a

View File

@@ -469,7 +469,7 @@ class MessageJsonTemplate(ThingJsonTemplate):
first_message_name = "first_message_name")
def thing_attr(self, thing, attr):
from r2.models import Message
from r2.models import Comment, Link, Message
if attr == "was_comment":
return thing.was_comment
elif attr == "context":
@@ -489,7 +489,12 @@ class MessageJsonTemplate(ThingJsonTemplate):
elif attr == "author" and getattr(thing, "hide_author", False):
return None
elif attr == "parent_id":
if getattr(thing, "parent_id", None):
if thing.was_comment:
if getattr(thing, "parent_id", None):
return make_fullname(Comment, thing.parent_id)
else:
return make_fullname(Link, thing.link_id)
elif getattr(thing, "parent_id", None):
return make_fullname(Message, thing.parent_id)
elif attr == "first_message_name":
if getattr(thing, "first_message", None):