def get(self, page_title):
        """When we receive an HTTP Get request to the view pages, we pull that
       page from the datastore and render it.  If the page does not exist
       we pass empty arguments to the template and the template displays
       the option to the user to create the page
    """
        # Attempt to locate the page
        entry = WikiPage.gql('WHERE title = :1', page_title).get()

        # If it exists, render the body, if not, don't
        if entry and entry.body:
            wiki_body, count = _WIKI_WORD.subn(r'<a href="/view/\1" >\1</a>',
                                               entry.body)
            wiki_body = markdown.markdown(wiki_body)
            author = entry.author
        else:
            wiki_body = ""
            author = ""

        self.generate('view.html',
                      template_values={
                          'page_title': page_title,
                          'body': wiki_body,
                          'author': author
                      })
  def post(self, page_title):

    current_user = users.get_current_user()
    
    if not current_user:
      self.redirect(users.create_login_url("/edit/" + page_title))

    # Get the posted edit
    body = self.request.get('body')
    
    # If the entry exists, overwrite it, if not, create it
    entry = WikiPage.gql('WHERE title = :1', page_title).get()
    
    if entry:
        entry.body = body
        entry.author = current_user
    else:
        entry = WikiPage(title=page_title, body=body, author=current_user)

    entry.put()
    self.redirect('/view/' + page_title)
 def get(self, page_title):
   # A user must be signed in to edit the page    
   current_user = users.get_current_user()
   
   if not current_user:
     self.redirect(users.create_login_url(self.request.path))
     
   # Display the existing body if it exists
   entry = WikiPage.gql('WHERE title = :1', page_title).get()
   
   self.generate('edit.html', template_values={'page_title': page_title,
                                               'entry': entry})
    def post(self, page_title):

        current_user = users.get_current_user()

        if not current_user:
            self.redirect(users.create_login_url("/edit/" + page_title))

        # Get the posted edit
        body = self.request.get('body')

        # If the entry exists, overwrite it, if not, create it
        entry = WikiPage.gql('WHERE title = :1', page_title).get()

        if entry:
            entry.body = body
            entry.author = current_user
        else:
            entry = WikiPage(title=page_title, body=body, author=current_user)

        entry.put()
        self.redirect('/view/' + page_title)
示例#5
0
文件: wiki.py 项目: alexaverbuch/GAE
  def post(self, title):
    content = self.request.get('content')
    
    # Logging
    logging.error("WikiEditHandler.post()")
    logging.error("title=" + str(title))
    logging.error("content=" + str(content))

    secure_username = self.request.cookies.get("user_id")
    username = None
    if secure_username:
      username = sec_utils.extract_secure_val(secure_username)
      
    if username:    
      page = get_page(title)
      version = 1    
      if page:
        version = page.version + 1      
      newPage = WikiPage(username=username, title=title, content=content, version=version)    
      newPage.put()    
      self.redirect("/wiki" + str(title))
    else:
      self.redirect("/wiki")
    def get(self, page_title):
        # A user must be signed in to edit the page
        current_user = users.get_current_user()

        if not current_user:
            self.redirect(users.create_login_url(self.request.path))

        # Display the existing body if it exists
        entry = WikiPage.gql('WHERE title = :1', page_title).get()

        self.generate('edit.html',
                      template_values={
                          'page_title': page_title,
                          'entry': entry
                      })
 def get(self, page_title):
   """When we receive an HTTP Get request to the view pages, we pull that
      page from the datastore and render it.  If the page does not exist
      we pass empty arguments to the template and the template displays
      the option to the user to create the page
   """
   # Attempt to locate the page
   entry = WikiPage.gql('WHERE title = :1', page_title).get()
   
   # If it exists, render the body, if not, don't
   if entry and entry.body:
       wiki_body, count = _WIKI_WORD.subn(r'<a href="/view/\1" >\1</a>', entry.body)
       wiki_body = markdown.markdown(wiki_body)
       author = entry.author
   else:
       wiki_body = ""
       author = ""
   
   self.generate('view.html', template_values={'page_title': page_title,
                                               'body': wiki_body,
                                               'author': author})