コード例 #1
0
 def post(self, postID):
     if self.session.get("username"):
         user = db.GqlQuery("SELECT * FROM User WHERE username='******'"
                            % self.session.get("username"))
         userID = user.get().key().id()
         form = PostsForm(self.request.POST)
         key = db.Key.from_path('Posts', int(postID))
         post = db.get(key)
         if form.validate() and form.submit.data and int(post.author) == \
                 int(userID):
             post.title = form.title.data
             post.content = form.content.data
             post.accessLevel = form.accessLevel.data
             post.put()
             self.redirect("/post/%s" % post.key().id())
         elif form.cancel.data:
             self.redirect("/post/%s" % post.key().id())
         else:
             self.redirect("/")
     else:
         self.redirect("/")
コード例 #2
0
 def post(self):
     if self.session.get("username"):
         form = PostsForm(self.request.POST)
         # Get the userID in order to associate it with the post
         username = self.session.get("username")
         user = db.GqlQuery("SELECT * FROM User WHERE username='******'"
                            % username)
         userID = user.get()
         userID = userID.key().id()
         # if the form is valid add the post to the datastore and then
         # redirect to the detail View of the post.
         if form.validate():
             newPost = Posts(title=form.title.data,
                             content=form.content.data,
                             accessLevel=form.accessLevel.data,
                             author=userID)
             newPost.put()
             self.redirect("/post/%s" % newPost.key().id())
         else:
             self.render("newPost.html", form=form,
                         username=self.session.get("username"))
     else:
         self.redirect("/register")