Beispiel #1
0
    def get(self, post_uid):

        post_obj = PostsDb.find_path(post_uid)  # find the path of post

        if not post_obj:
            self.render("404")
        else:

            # check it there is a user cookie
            if self.user_cookie:
                self.render("/permalink.html", post=post_obj, user=self.user_cookie)
Beispiel #2
0
    def post(self):

        subject = self.request.get("subject")
        blog = self.request.get("blog")

        if not subject and not blog:
            self.render("newpost.html", error="please enter a subject and a body.", user=self.user_cookie)
        elif not subject and blog:
            self.render(
                "newpost.html", body=blog, body_err="Looks like you have forgotten the subject!", user=self.user_cookie
            )
        elif subject and not blog:
            self.render("newpost.html", subject=subject, blog_err="Enter the blog content.", user=self.user_cookie)
        else:
            uid = PostsDb.add(subject, blog)  # add the latest blog to the database
            self.redirect("/blog/%s" % (str(uid)))  # redirect it to a permalink
Beispiel #3
0
    def get(self, uid):
        self.response.headers["Content-Type"] = "application/json; charset=UTF-8"

        if not self.user_cookie:
            self.redirect("/login")
        else:
            post_obj = PostsDb.find_path(uid)
            json_post = Json()

            sub = post_obj.subject
            cont = post_obj.content
            created = post_obj.created.strftime("%b %d, %Y")
            last_time = post_obj.last_created.strftime("%b %d, %Y")

            json_post.set_variables(sub, cont, created, last_time)
            json_post.make_json_str()
            self.write(json_post.get_json())
Beispiel #4
0
 def get(self):
     if self.user_cookie:
         posts = PostsDb.get_all()
         self.render("/posts.html", user=self.user_cookie, posts=posts)
     else:
         self.redirect("/login")