Exemplo n.º 1
0
    def get(self, path):
        LINKS_IN = (("edit", "/_edit" + path), ("history", "/_history" + path), ("logout", "/logout" + path))
        LINKS_OUT = (("history", "/_history" + path), ("log in", "/login"), ("sign up", "/signup"))

        vdata = dict(self.request.params)
        vdata["user"] = self.user
        vdata["path"] = path
        vdata["linkinfo"] = LINKS_IN if self.user else LINKS_OUT

        post_id = vdata.get("v")
        if post_id:
            post_rec = WikiPosts.by_id(path, post_id)
        else:
            post_rec = WikiPosts.most_recent_by_path(path)

        if post_rec:
            vdata["post"] = post_rec
            user_rec = Users.by_id(post_rec.user_id)
            vdata["username"] = user_rec.username

            self.render("wikiview.html", vdata=vdata)
        else:
            # We couldn't find a post record.  What we do now
            # depends on the type of item we're trying to view.
            # if it's a DB reference, we're stuck so show an error.
            # If it's a path, we switch to edit mode.
            if post_id:
                self.error(404)
            else:
                # if user not logged in, edit page handler will redirect to login.
                # Do we want to have a double redixrect???
                url = URL_RD_EDIT.format(path)
                self.redirect(url)
Exemplo n.º 2
0
    def get(self, path):
        if not self.user:
            # no logged in user, this is not allowed.  redirect to login page.
            self.redirect(URL_LOGIN)

        LINKS_IN = (('view', path),
                    ('history', '/_history' + path),
                    ('logout', '/logout' + path))
        
        vdata = dict(self.request.params)
        vdata['user'] = self.user
        vdata['path'] = path
        vdata['linkinfo'] = LINKS_IN
        
        post_rec = WikiPosts.most_recent_by_path(path)
        if post_rec:
            vdata['content'] = post_rec.content
        self.render("wikiedit.html", vdata=vdata)
Exemplo n.º 3
0
    def post(self, path):
        if not self.user:
            self.redirect(URL_LOGIN)
            
        vdata = dict(self.request.params)
        content = self.request.get('content')
        if not content:
            vdata['e_entry'] = "Please enter some text"
            post_rec = WikiPosts.most_recent_by_path(path)
            if post_rec:
                vdata['content'] = post_rec.content
            self.render("wikiedit.html", vdata=vdata)
        else:
            new_rec = WikiPosts.register(path, content, self.user.key().id())
            new_rec.put()
            
#            host_url = self.request.host_url
#            full_url = host_url + path
#            self.response.headers.add_header('Location', full_url)
#            self.response.set_status(302)
            self.redirect(path, permanent=False)