Пример #1
0
 def get_wiki_user(self, create=False, back=None):
   current_user = self.get_current_user(back)
   wiki_user = WikiUser.gql('WHERE wiki_user = :1', current_user).get()
   if not wiki_user and create:
     wiki_user = WikiUser(wiki_user=current_user)
     wiki_user.put()
   return wiki_user
Пример #2
0
 def post(self):
   self.acl.check_edit_settings()
   email = self.request.get('email').strip()
   if email and not WikiUser.gql('WHERE wiki_user = :1', users.User(email)).get():
     user = WikiUser(wiki_user=users.User(email))
     user.put()
   self.redirect('/w/users')
Пример #3
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)
Пример #4
0
    def post(self, user):
        # Get the user information
        unescaped_user = urllib.unquote(user)
        wiki_user_object = users.User(unescaped_user)
        # Only that user can edit his or her profile
        if users.get_current_user() != wiki_user_object:
            self.redirect('/view/StartPage')

        wiki_user = WikiUser.gql('WHERE wiki_user = :1',
                                 wiki_user_object).get()

        user_photo = self.request.get('user_picture')
        if user_photo:
            raw_photo = images.Image(user_photo)
            raw_photo.resize(width=256, height=256)
            raw_photo.im_feeling_lucky()
            wiki_user.wiki_user_picture = raw_photo.execute_transforms(
                output_encoding=images.PNG)
        feed_url = self.request.get('feed_url')
        if feed_url:
            wiki_user.user_feed = feed_url

        wiki_user.put()

        self.redirect('/user/%s' % user)
  def generate(self, template_name, template_values={}):
    """Generate takes renders and HTML template along with values
       passed to that template

       Args:
         template_name: A string that represents the name of the HTML template
         template_values: A dictionary that associates objects with a string
           assigned to that object to call in the HTML template.  The defualt
           is an empty dictionary.
    """
    # We check if there is a current user and generate a login or logout URL
    user = users.get_current_user()

    if user:
      log_in_out_url = users.create_logout_url('/view/StartPage')
      wiki_user = WikiUser.gql('WHERE wiki_user = :1', user).get()
    else:
      log_in_out_url = users.create_login_url(self.request.path)

    # We'll display the user name if available and the URL on all pages
    values = {'user': user, 'log_in_out_url': log_in_out_url}
    values.update(template_values)

    # Construct the path to the template
    directory = os.path.dirname(__file__)
    path = os.path.join(directory, 'templates', template_name)

    # Respond to the request by rendering the template
    self.response.out.write(template.render(path, values, debug=_DEBUG))
Пример #6
0
 def new_user(self, username, password, email):
   q = db.GqlQuery("SELECT * FROM WikiUser " + 
                   "WHERE username = :1",
                   username)
   results = q.fetch(1)
   if results:
     # user exists
     return None
   else:
     # create new user
     secure_password = sec_utils.make_pw_hash(username, password)
     newUser = WikiUser(username=username, password=secure_password) 
     if email:
       newUser.email = email
     newUser.put()
     return newUser
Пример #7
0
    def generate(self, template_name, template_values={}):
        """Generate takes renders and HTML template along with values
       passed to that template

       Args:
         template_name: A string that represents the name of the HTML template
         template_values: A dictionary that associates objects with a string
           assigned to that object to call in the HTML template.  The defualt
           is an empty dictionary.
    """
        # We check if there is a current user and generate a login or logout URL
        user = users.get_current_user()

        if user:
            log_in_out_url = users.create_logout_url('/view/StartPage')
            wiki_user = WikiUser.gql('WHERE wiki_user = :1', user).get()
        else:
            log_in_out_url = users.create_login_url(self.request.path)

        # We'll display the user name if available and the URL on all pages
        values = {'user': user, 'log_in_out_url': log_in_out_url}
        values.update(template_values)

        # Construct the path to the template
        directory = os.path.dirname(__file__)
        path = os.path.join(directory, 'templates', template_name)

        # Respond to the request by rendering the template
        self.response.out.write(template.render(path, values, debug=_DEBUG))
  def get(self, user):
    """When requesting the URL, we find out that user's WikiUser information.
       We also retrieve articles written by the user
    """
    # Webob over quotes the request URI, so we have to unquote twice
    unescaped_user = urllib.unquote(urllib.unquote(user))

    # Query for the user information
    wiki_user_object = users.User(unescaped_user)
    wiki_user = WikiUser.gql('WHERE wiki_user = :1', wiki_user_object).get()

    # Retrieve the unique set of articles the user has revised
    # Please note that this doesn't gaurentee that user's revision is
    # live on the wiki page
    article_list = []
    for article in wiki_user.wikirevision_set:
      article_list.append(article.wiki_page.title)
    articles = set(article_list)

    # If the user has specified a feed, fetch it
    feed_content = ''
    feed_titles = []
    if wiki_user.user_feed:
      feed = urlfetch.fetch(wiki_user.user_feed)
      # If the fetch is a success, get the blog article titles
      if feed.status_code == 200:
        feed_content = feed.content
        xml_content = xml.dom.minidom.parseString(feed_content)
        for title in xml_content.getElementsByTagName('title'):
          feed_titles.append(title.childNodes[0].nodeValue)
    # Generate the user profile
    self.generate('user.html', template_values={'queried_user': wiki_user,
                                                'articles': articles,
                                                'titles': feed_titles})
Пример #9
0
    def get(self, user):
        """When requesting the URL, we find out that user's WikiUser information.
       We also retrieve articles written by the user
    """
        # Webob over quotes the request URI, so we have to unquote twice
        unescaped_user = urllib.unquote(urllib.unquote(user))

        # Query for the user information
        wiki_user_object = users.User(unescaped_user)
        wiki_user = WikiUser.gql('WHERE wiki_user = :1',
                                 wiki_user_object).get()

        # Retrieve the unique set of articles the user has revised
        # Please note that this doesn't gaurentee that user's revision is
        # live on the wiki page
        article_list = []
        for article in wiki_user.wikirevision_set:
            article_list.append(article.wiki_page.title)
        articles = set(article_list)

        # Generate the user profile
        self.generate('user.html',
                      template_values={
                          'queried_user': wiki_user,
                          'articles': articles
                      })
Пример #10
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)
Пример #11
0
  def get(self, user):
    # Get the user information
    unescaped_user = urllib.unquote(user)
    wiki_user_object = users.User(unescaped_user)
    # Only that user can edit his or her profile
    if users.get_current_user() != wiki_user_object:
      self.redirect('/view/StartPage')

    wiki_user = WikiUser.gql('WHERE wiki_user = :1', wiki_user_object).get()
    if not wiki_user:
      wiki_user = WikiUser(wiki_user=wiki_user_object)
      wiki_user.put()

    article_list = []
    for article in wiki_user.wikirevision_set:
        article_list.append(article.wiki_page.title)
    articles = set(article_list)
    self.generate('edit_user.html', template_values={'queried_user': wiki_user,
                                                     'articles': articles})
Пример #12
0
  def get(self):
    self.acl.check_edit_settings()

    users = [{
      'name': user.wiki_user.nickname(),
      'email': user.wiki_user.email(),
      'md5': md5.new(user.wiki_user.email()).hexdigest(),
      'joined': user.joined,
      } for user in WikiUser.gql('ORDER BY wiki_user').fetch(1000)]

    self.generate('users.html', template_values = { 'users': users })
Пример #13
0
  def get(self, user):
    unescaped_user = urllib.unquote(user)
    wiki_user_object = users.User(unescaped_user)
    # Only that user can edit his or her profile
    if users.get_current_user() != wiki_user_object:
      self.redirect('/view/StartPage')

    wiki_user = WikiUser.gql('WHERE wiki_user = :1', wiki_user_object).get()
    
    if wiki_user.wiki_user_picture:
      self.response.headers['Content-Type'] = 'image/jpg'
      self.response.out.write(wiki_user.wiki_user_picture)
Пример #14
0
    def get(self, user):
        unescaped_user = urllib.unquote(user)
        wiki_user_object = users.User(unescaped_user)
        # Only that user can edit his or her profile
        if users.get_current_user() != wiki_user_object:
            self.redirect('/view/StartPage')

        wiki_user = WikiUser.gql('WHERE wiki_user = :1',
                                 wiki_user_object).get()

        if wiki_user.wiki_user_picture:
            self.response.headers['Content-Type'] = 'image/jpg'
            self.response.out.write(wiki_user.wiki_user_picture)
Пример #15
0
    def get(self, user):
        # Get the user information
        unescaped_user = urllib.unquote(user)
        wiki_user_object = users.User(unescaped_user)
        # Only that user can edit his or her profile
        if users.get_current_user() != wiki_user_object:
            self.redirect('/view/StartPage')

        wiki_user = WikiUser.gql('WHERE wiki_user = :1',
                                 wiki_user_object).get()
        if not wiki_user:
            wiki_user = WikiUser(wiki_user=wiki_user_object)
            wiki_user.put()

        article_list = []
        for article in wiki_user.wikirevision_set:
            article_list.append(article.wiki_page.title)
        articles = set(article_list)
        self.generate('edit_user.html',
                      template_values={
                          'queried_user': wiki_user,
                          'articles': articles
                      })
Пример #16
0
 def can_edit_pages(self):
   """
   Returns True if the user can edit pages, otherwise throws an exception."
   """
   if self.can_edit_settings():
     return True
   cu = users.get_current_user()
   if not cu:
     raise UnauthorizedException()
   return True
   wu = WikiUser.gql('WHERE wiki_user = :1', cu).get()
   if not wu:
     raise ForbiddenException()
   return True
Пример #17
0
  def get(self, user):
    unescaped_user = urllib.unquote(user)
    wiki_user_object = users.User(unescaped_user)
    # Only that user can edit his or her profile
    if users.get_current_user() != wiki_user_object:
      self.redirect('/view/StartPage')

    wiki_user = WikiUser.gql('WHERE wiki_user = :1', wiki_user_object).get()

    self.response.headers['Content-Type'] = 'image/jpg'    
    if wiki_user.wiki_user_picture:
      self.response.out.write(wiki_user.wiki_user_picture)
    else:
      directory = os.path.dirname(__file__)
      path = os.path.join(directory, 'static', 'noimage')
      self.response.out.write(path)
Пример #18
0
    def get(self, user):
        unescaped_user = urllib.unquote(user)
        wiki_user_object = users.User(unescaped_user)
        # Only that user can edit his or her profile
        if users.get_current_user() != wiki_user_object:
            self.redirect('/view/StartPage')

        wiki_user = WikiUser.gql('WHERE wiki_user = :1',
                                 wiki_user_object).get()

        self.response.headers['Content-Type'] = 'image/jpg'
        if wiki_user.wiki_user_picture:
            self.response.out.write(wiki_user.wiki_user_picture)
        else:
            directory = os.path.dirname(__file__)
            path = os.path.join(directory, 'static', 'noimage')
            self.response.out.write(path)
Пример #19
0
  def post(self, user):
    # Get the user information
    unescaped_user = urllib.unquote(user)
    wiki_user_object = users.User(unescaped_user)
    # Only that user can edit his or her profile
    if users.get_current_user() != wiki_user_object:
      self.redirect('/view/StartPage')

    wiki_user = WikiUser.gql('WHERE wiki_user = :1', wiki_user_object).get()

    user_photo = self.request.get('user_picture')
    if user_photo:
      raw_photo = images.Image(user_photo)
      raw_photo.resize(width=256, height=256)
      raw_photo.im_feeling_lucky()
      wiki_user.wiki_user_picture = raw_photo.execute_transforms(output_encoding=images.PNG)
    wiki_user.put()

    self.redirect('/user/%s' % user)
Пример #20
0
  def get(self, user):
    """When requesting the URL, we find out that user's WikiUser information.
       We also retrieve articles written by the user
    """
    # Webob over quotes the request URI, so we have to unquote twice
    unescaped_user = urllib.unquote(urllib.unquote(user))

    # Query for the user information
    wiki_user_object = users.User(unescaped_user)
    wiki_user = WikiUser.gql('WHERE wiki_user = :1', wiki_user_object).get()

    # Retrieve the unique set of articles the user has revised
    # Please note that this doesn't gaurentee that user's revision is
    # live on the wiki page
    article_list = []
    for article in wiki_user.wikirevision_set:
      article_list.append(article.wiki_page.title)
    articles = set(article_list)

    # Generate the user profile
    self.generate('user.html', template_values={'queried_user': wiki_user,
                                                'articles': articles})
Пример #21
0
    def get(self, user):
        """When requesting the URL, we find out that user's WikiUser information.
       We also retrieve articles written by the user
    """
        # Webob over quotes the request URI, so we have to unquote twice
        unescaped_user = urllib.unquote(urllib.unquote(user))

        # Query for the user information
        wiki_user_object = users.User(unescaped_user)
        wiki_user = WikiUser.gql('WHERE wiki_user = :1',
                                 wiki_user_object).get()

        # Retrieve the unique set of articles the user has revised
        # Please note that this doesn't gaurentee that user's revision is
        # live on the wiki page
        article_list = []
        for article in wiki_user.wikirevision_set:
            article_list.append(article.wiki_page.title)
        articles = set(article_list)

        # If the user has specified a feed, fetch it
        feed_content = ''
        feed_titles = []
        if wiki_user.user_feed:
            feed = urlfetch.fetch(wiki_user.user_feed)
            # If the fetch is a success, get the blog article titles
            if feed.status_code == 200:
                feed_content = feed.content
                xml_content = xml.dom.minidom.parseString(feed_content)
                for title in xml_content.getElementsByTagName('title'):
                    feed_titles.append(title.childNodes[0].nodeValue)
        # Generate the user profile
        self.generate('user.html',
                      template_values={
                          'queried_user': wiki_user,
                          'articles': articles,
                          'titles': feed_titles
                      })