Exemple #1
0
    def post(self, page_title):
        # Again, only accept saves from a signed in user
        current_user = users.get_current_user()

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

        # See if this user has a profile
        wiki_user = WikiUser.gql('WHERE wiki_user = :1', current_user).get()

        # If not, create the profile
        if not wiki_user:
            wiki_user = WikiUser(wiki_user=current_user)
            wiki_user.put()

        # get the user entered content in the form
        body = self.request.get('body')

        # Find the entry, if it exists
        entry = WikiContent.gql('WHERE title = :1', page_title).get()

        # Generate the version number based on the entries previous existence
        if entry:
            latest_version = WikiRevision.gql(
                'WHERE wiki_page = :content'
                ' ORDER BY version_number DESC',
                content=entry).get()
            version_number = latest_version.version_number + 1
        else:
            version_number = 1
            entry = WikiContent(title=page_title)
            entry.put()

        # Create a version for this entry
        version = WikiRevision(version_number=version_number,
                               revision_body=body,
                               author=wiki_user,
                               wiki_page=entry)
        version.put()

        # above, memcache sets the following:
        # return [wiki_body, author_email, author_nickname, version, version_date]
        content = [
            markdown.markdown(body),
            current_user.email(),
            current_user.nickname(), version_number, version.created
        ]
        memcache.set(page_title, content, 600)
        # After the entry has been saved, direct the user back to view the page
        self.redirect('/view/' + page_title)
  def get_page_content(self, page_title):
    """When memcache lookup fails, we want to query the information from
       the datastore and return it.  If the data isn't in the data store,
       simply return empty strings
    """
    # Find the wiki entry
    entry = WikiContent.gql('WHERE title = :1', page_title).get()

    if entry:
      # Retrieve the current version
      current_version = WikiRevision.gql('WHERE wiki_page =  :1 '
                                         'ORDER BY version_number DESC', entry).get()
      # Define the body, version number, author email, author nickname
      # and revision date
      body = current_version.revision_body
      version = current_version.version_number
      author_email = urllib.quote(current_version.author.wiki_user.email())
      author_nickname = current_version.author.wiki_user.nickname()
      version_date = current_version.created
      # Replace all wiki words with links to those wiki pages
      wiki_body, count = _WIKI_WORD.subn(r'<a href="/view/\1">\1</a>',
                                         body)
      # Markdown the body to allow formatting of the wiki page
      wiki_body = markdown.markdown(wiki_body)
    else:
      # These things do not exist
      wiki_body = ''
      author_email = ''
      author_nickname = ''
      version = ''
      version_date = ''

    return [wiki_body, author_email, author_nickname, version, version_date]
Exemple #3
0
  def get(self):
    self.acl.check_read_pages()

    if '.rss' == self.request.path[-4:]:
      self.generateRss('changes-rss.html', template_values={
        'changes': WikiContent.gql('ORDER BY updated DESC').fetch(1000),
      })
    else:
      content = memcache.get('/w/changes')
      if not content or self.request.get('nc'):
        template_values={
          'self': self.request.url,
          'changes': WikiContent.gql('ORDER BY updated DESC').fetch(1000),
        }
        content = self.generate('changes.html', template_values, ret=True)
        memcache.set('/w/changes', content)

      self.response.out.write(content)
Exemple #4
0
    def get(self, page_title):
        entry = WikiContent.gql('WHERE title = :1', page_title).get()

        if entry:
            revisions = WikiRevision.all()
            # Render the template view_revisionlist.html, which extends base.html
            self.generate('view_revisionlist.html', template_values={'page_title': page_title,
                                                        'revisions': revisions,
                                                       })
Exemple #5
0
def get(name, revision=None, create=False):
  page = WikiContent.gql('WHERE title = :1', name).get()
  if not page:
    if create:
      return WikiContent(title=name)
    raise NotFoundException()
  if revision:
    return WikiRevision.gql('WHERE wiki_page = :1 AND version_number = :2', page, int(revision)).get()
  return page
  def post(self, page_title):
    # Again, only accept saves from a signed in user
    current_user = users.get_current_user()

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

    # See if this user has a profile
    wiki_user = WikiUser.gql('WHERE wiki_user = :1', current_user).get()

    # If not, create the profile
    if not wiki_user:
      wiki_user = WikiUser(wiki_user=current_user)
      wiki_user.put()

    # get the user entered content in the form
    body = self.request.get('body')

    # Find the entry, if it exists
    entry = WikiContent.gql('WHERE title = :1', page_title).get()

    # Generate the version number based on the entries previous existence
    if entry:
      latest_version = WikiRevision.gql('WHERE wiki_page = :content'
                                        ' ORDER BY version_number DESC', content=entry).get()
      version_number = latest_version.version_number + 1
    else:
      version_number = 1
      entry = WikiContent(title=page_title)
      entry.put()

    # Create a version for this entry
    version = WikiRevision(version_number=version_number,
                           revision_body=body, author=wiki_user,
                           wiki_page=entry)
    version.put()

    # above, memcache sets the following:
    # return [wiki_body, author_email, author_nickname, version, version_date]
    content = [markdown.markdown(body), current_user.email(), 
               current_user.nickname(), version_number, version.created]
    memcache.set(page_title, content, 600)
    # After the entry has been saved, direct the user back to view the page
    self.redirect('/view/' + page_title)
Exemple #7
0
    def get(self, page_title):
        entry = WikiContent.gql('WHERE title = :1', page_title).get()

        if entry:
            revisions = WikiRevision.all()
            # Render the template view_revisionlist.html, which extends base.html
            self.generate('view_revisionlist.html',
                          template_values={
                              'page_title': page_title,
                              'revisions': revisions,
                          })
Exemple #8
0
    def get(self, page_title, first_revision, second_revision):
        entry = WikiContent.gql('WHERE title = :1', page_title).get()

        if entry:
            first_revision = WikiRevision.gql('WHERE wiki_page =  :1 '
                                              'AND version_number = :2', entry, int(first_revision)).get()
            second_revision = WikiRevision.gql('WHERE wiki_page =  :1 '
                                              'AND version_number = :2', entry, int(second_revision)).get()

            import diff
            body = diff.textDiff(first_revision.revision_body, second_revision.revision_body)

            self.generate('view_diff.html', template_values={'page_title': page_title,
                                                             'body': body,
                                                             })
    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
    """
        # Find the wiki entry
        entry = WikiContent.gql('WHERE title = :1', page_title).get()

        if entry:
            # Retrieve the current version
            current_version = WikiRevision.gql(
                'WHERE wiki_page =  :1 '
                'ORDER BY version_number DESC', entry).get()
            # Define the body, version number, author email, author nickname
            # and revision date
            body = current_version.revision_body
            version = current_version.version_number
            author_email = urllib.quote(
                current_version.author.wiki_user.email())
            author_nickname = current_version.author.wiki_user.nickname()
            version_date = current_version.created
            # Replace all wiki words with links to those wiki pages
            wiki_body, count = _WIKI_WORD.subn(r'<a href="/view/\1">\1</a>',
                                               body)
            # Markdown the body to allow formatting of the wiki page
            wiki_body = markdown.markdown(wiki_body)

        else:
            # These things do not exist
            wiki_body = ''
            author_email = ''
            author_nickname = ''
            version = ''
            version_date = ''

        # Render the template view.html, which extends base.html
        self.generate('view.html',
                      template_values={
                          'page_title': page_title,
                          'body': wiki_body,
                          'author': author_nickname,
                          'author_email': author_email,
                          'version': version,
                          'version_date': version_date
                      })
Exemple #10
0
  def get(self):
    self.acl.check_read_pages()

    if '.rss' == self.request.path[-4:]:
      plist = {}
      for revision in WikiRevision.gql('ORDER BY created DESC').fetch(1000):
        page = revision.wiki_page.title
        if page not in plist:
          plist[page] = { 'name': page, 'title': self.get_page_name(page), 'created': revision.created, 'author': revision.author }
      self.generateRss('index-rss.html', template_values = {
        'items': [plist[page] for page in plist],
      });
    else:
      self.generate('index.html', template_values={'pages': [{
        'name': page.title,
        'uri': '/' + pages.quote(page.title),
      } for page in WikiContent.gql('ORDER BY title').fetch(1000)] })
Exemple #11
0
  def get(self):
    self.acl.check_edit_settings()

    for page in WikiContent.all().fetch(1000):
      if page.updated is None or page.author is None or page.body is None:
        rev = WikiRevision.gql('WHERE wiki_page = :1 ORDER BY version_number DESC', page).get()
        if rev is not None:
          page.updated = rev.created
          page.author = rev.author
          page.pread = rev.pread
          page.body = rev.revision_body
          page.put()
      elif '_' in page.title:
        page.title = page.title.replace('_', ' ')
        page.put()

    self.redirect('/w/index')
  def get(self, page_title):
    # We require that the user be signed in to edit a page
    current_user = users.get_current_user()

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

    # Get the entry along with the current version
    entry = WikiContent.gql('WHERE title = :1', page_title).get()

    current_version = WikiRevision.gql('WHERE wiki_page = :1 '
                                       'ORDER BY version_number DESC', entry).get()

    # Generate edit template, which posts to the save handler
    self.generate('edit.html',
                  template_values={'page_title': page_title,
                                   'current_version': current_version})
Exemple #13
0
    def get_page_content(self, page_title, revision_number=1):
        """When memcache lookup fails, we want to query the information from
       the datastore and return it.  If the data isn't in the data store,
       simply return empty strings
    """
        # Find the wiki entry
        entry = WikiContent.gql('WHERE title = :1', page_title).get()

        if entry:
            # Retrieve the current version
            if revision_number is not None:
                requested_version = WikiRevision.gql(
                    'WHERE wiki_page =  :1 '
                    'AND version_number = :2', entry,
                    int(revision_number)).get()
            else:
                requested_version = WikiRevision.gql(
                    'WHERE wiki_page =  :1 '
                    'ORDER BY version_number DESC', entry).get()
            # Define the body, version number, author email, author nickname
            # and revision date
            body = requested_version.revision_body
            version = requested_version.version_number
            author_email = urllib.quote(
                requested_version.author.wiki_user.email())
            author_nickname = requested_version.author.wiki_user.nickname()
            version_date = requested_version.created
            # Replace all wiki words with links to those wiki pages
            wiki_body, count = _WIKI_WORD.subn(r'<a href="/view/\1">\1</a>',
                                               body)
            # Markdown the body to allow formatting of the wiki page
            wiki_body = markdown.markdown(wiki_body)
        else:
            # These things do not exist
            wiki_body = ''
            author_email = ''
            author_nickname = ''
            version = ''
            version_date = ''

        return [
            wiki_body, author_email, author_nickname, version, version_date
        ]
Exemple #14
0
    def get(self, page_title, first_revision, second_revision):
        entry = WikiContent.gql('WHERE title = :1', page_title).get()

        if entry:
            first_revision = WikiRevision.gql(
                'WHERE wiki_page =  :1 '
                'AND version_number = :2', entry, int(first_revision)).get()
            second_revision = WikiRevision.gql(
                'WHERE wiki_page =  :1 '
                'AND version_number = :2', entry, int(second_revision)).get()

            import diff
            body = diff.textDiff(first_revision.revision_body,
                                 second_revision.revision_body)

            self.generate('view_diff.html',
                          template_values={
                              'page_title': page_title,
                              'body': body,
                          })
    def get(self, page_title):
        # We require that the user be signed in to edit a page
        current_user = users.get_current_user()

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

        # Get the entry along with the current version
        entry = WikiContent.gql('WHERE title = :1', page_title).get()

        current_version = WikiRevision.gql(
            'WHERE wiki_page = :1 '
            'ORDER BY version_number DESC', entry).get()

        # Generate edit template, which posts to the save handler
        self.generate('edit.html',
                      template_values={
                          'page_title': page_title,
                          'current_version': current_version
                      })
  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
    """
    # Find the wiki entry
    entry = WikiContent.gql('WHERE title = :1', page_title).get()

    if entry:
      # Retrieve the current version
      current_version = WikiRevision.gql('WHERE wiki_page =  :1 '
                                         'ORDER BY version_number DESC', entry).get()
      # Define the body, version number, author email, author nickname
      # and revision date
      body = current_version.revision_body
      version = current_version.version_number
      author_email = urllib.quote(current_version.author.wiki_user.email())
      author_nickname = current_version.author.wiki_user.nickname()
      version_date = current_version.created
      # Replace all wiki words with links to those wiki pages
      wiki_body, count = _WIKI_WORD.subn(r'<a href="/view/\1">\1</a>',
                                         body)
      # Markdown the body to allow formatting of the wiki page
      wiki_body = markdown.markdown(wiki_body)

    else:
      # These things do not exist
      wiki_body = ''
      author_email = ''
      author_nickname = ''
      version = ''
      version_date = ''

    # Render the template view.html, which extends base.html
    self.generate('view.html', template_values={'page_title': page_title,
                                                'body': wiki_body,
                                                'author': author_nickname,
                                                'author_email': author_email,
                                                'version': version,
                                                'version_date': version_date})
Exemple #17
0
  def get(self):
    content = memcache.get('/sitemap.xml')
    if True or not content:
      content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
      content += "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"

      settings = self.settings
      host = self.request.environ['HTTP_HOST']

      for page in WikiContent.all().fetch(1000):
        if settings.data.pread or page.pread:
          line = "<url><loc>http://%s/%s</loc>" % (host, pages.quote(page.title))
          if page.updated:
            line += "<lastmod>%s</lastmod>" % (page.updated.strftime('%Y-%m-%d'))
          line += "</url>\n"
          content += line
      content += "</urlset>\n"

      memcache.set('/sitemap.xml', content)

    self.response.headers['Content-Type'] = 'text/xml'
    self.response.out.write(content)
Exemple #18
0
  def get_page_content(self, page_title, revision_number=1):
    """When memcache lookup fails, we want to query the information from
       the datastore and return it.  If the data isn't in the data store,
       simply return empty strings
    """
    # Find the wiki entry
    entry = WikiContent.gql('WHERE title = :1', self.get_page_name(page_title)).get()

    if entry:
      # Retrieve the current version
      if revision_number is not None:
          requested_version = WikiRevision.gql('WHERE wiki_page =  :1 '
                                               'AND version_number = :2', entry, int(revision_number)).get()
      else:
          requested_version = WikiRevision.gql('WHERE wiki_page =  :1 '
                                               'ORDER BY version_number DESC', entry).get()
      # Define the body, version number, author email, author nickname
      # and revision date
      body = requested_version.revision_body
      version = requested_version.version_number
      author_email = urllib.quote(requested_version.author.wiki_user.email())
      author_nickname = requested_version.author.wiki_user.nickname()
      version_date = requested_version.created
      # Replace all wiki words with links to those wiki pages
      wiki_body = pages.wikifier(self.settings).wikify(body)
      pread = requested_version.pread
    else:
      # These things do not exist
      wiki_body = ''
      author_email = ''
      author_nickname = ''
      version = ''
      version_date = ''
      pread = False

    return [wiki_body, author_email, author_nickname, version, version_date, pread]