From: David ‘Bombe’ Roden Date: Sun, 24 Apr 2011 12:28:27 +0000 (+0200) Subject: Store request in template context when rendering posts and replies. X-Git-Tag: 0.6.3^2~15 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=445a0bc68d136a9f33e49ea4f47ab57e10d6a9c2;hp=543601314f9213c4d4b5c8ae1177cdb2ab94a854;p=Sone.git Store request in template context when rendering posts and replies. --- diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java index 4e5f1b8..f12f603 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java @@ -62,7 +62,7 @@ public class GetPostAjaxPage extends JsonPage { if (post == null) { return createErrorJsonObject("invalid-post-id"); } - return createSuccessJsonObject().put("post", createJsonPost(post, getCurrentSone(request.getToadletContext()))); + return createSuccessJsonObject().put("post", createJsonPost(request, post, getCurrentSone(request.getToadletContext()))); } /** @@ -87,7 +87,7 @@ public class GetPostAjaxPage extends JsonPage { * The currently logged in Sone (to store in the template) * @return The JSON representation of the post */ - private JsonObject createJsonPost(Post post, Sone currentSone) { + private JsonObject createJsonPost(Request request, Post post, Sone currentSone) { JsonObject jsonPost = new JsonObject(); jsonPost.put("id", post.getId()); jsonPost.put("sone", post.getSone().getId()); @@ -95,6 +95,7 @@ public class GetPostAjaxPage extends JsonPage { jsonPost.put("time", post.getTime()); StringWriter stringWriter = new StringWriter(); TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext(); + templateContext.set("request", request); templateContext.set("post", post); templateContext.set("currentSone", currentSone); templateContext.set("localSones", webInterface.getCore().getLocalSones()); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java index c19bcba..82226e3 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -65,7 +65,7 @@ public class GetReplyAjaxPage extends JsonPage { if ((reply == null) || (reply.getSone() == null)) { return createErrorJsonObject("invalid-reply-id"); } - return createSuccessJsonObject().put("reply", createJsonReply(reply, getCurrentSone(request.getToadletContext()))); + return createSuccessJsonObject().put("reply", createJsonReply(request, reply, getCurrentSone(request.getToadletContext()))); } /** @@ -89,7 +89,7 @@ public class GetReplyAjaxPage extends JsonPage { * The currently logged in Sone (to store in the template) * @return The JSON representation of the reply */ - private JsonObject createJsonReply(Reply reply, Sone currentSone) { + private JsonObject createJsonReply(Request request, Reply reply, Sone currentSone) { JsonObject jsonReply = new JsonObject(); jsonReply.put("id", reply.getId()); jsonReply.put("postId", reply.getPost().getId()); @@ -97,6 +97,7 @@ public class GetReplyAjaxPage extends JsonPage { jsonReply.put("time", reply.getTime()); StringWriter stringWriter = new StringWriter(); TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext(); + templateContext.set("request", request); templateContext.set("reply", reply); templateContext.set("currentSone", currentSone); try {