예제 #1
0
  def get(self, section):
    """Retrieve a feed"""
    user = None
    if section == 'recent':    
      quotes, next = models.get_quotes_newest()
    elif section == 'popular':
      quotes, next = models.get_quotes()
    else:
      self.response.set_status(404, 'Not Found')
      return      

    template_values = create_template_dict(user, quotes, section.capitalize())
    template_file = os.path.join(os.path.dirname(__file__), 'templates/atom_feed.xml')    
    self.response.headers['Content-Type'] = 'application/atom+xml; charset=utf-8'
    self.response.out.write(template.render(template_file, template_values))
예제 #2
0
  def get(self, section):
    """Retrieve a feed"""
    user = None
    if section == 'recent':    
      quotes, next = models.get_quotes_newest()
    elif section == 'popular':
      quotes, next = models.get_quotes()
    else:
      self.response.set_status(404, 'Not Found')
      return      

    template_values = create_template_dict(user, quotes, section.capitalize())
    template_file = os.path.join(os.path.dirname(__file__), 'templates/atom_feed.xml')    
    self.response.headers['Content-Type'] = 'application/atom+xml; charset=utf-8'
    self.response.out.write(template.render(template_file, template_values))
예제 #3
0
  def get(self):
    """The most popular quotes in order, broken into pages, 
       served as HTML."""
    user = users.get_current_user()
    page = int(self.request.get('p', '0'))
    quotes, next = models.get_quotes(page)
    if next:
      nexturi = '/?p=%d' % (page + 1)
    else:
      nexturi = None
    if page > 1:
      prevuri = '/?p=%d' % (page - 1)
    elif page == 1:
      prevuri = '/'
    else:
      prevuri = None

    template_values = create_template_dict(
        user, quotes, 'Popular', nexturi, prevuri, page
      )    
    template_file = os.path.join(os.path.dirname(__file__), 'templates/index.html')    
    self.response.out.write(template.render(template_file, template_values))
예제 #4
0
  def get(self):
    """The most popular quotes in order, broken into pages, 
       served as HTML."""
    user = users.get_current_user()
    page = int(self.request.get('p', '0'))
    quotes, next = models.get_quotes(page)
    if next:
      nexturi = '/?p=%d' % (page + 1)
    else:
      nexturi = None
    if page > 1:
      prevuri = '/?p=%d' % (page - 1)
    elif page == 1:
      prevuri = '/'
    else:
      prevuri = None

    template_values = create_template_dict(
        user, quotes, 'Popular', nexturi, prevuri, page
      )    
    template_file = os.path.join(os.path.dirname(__file__), 'templates/index.html')    
    self.response.out.write(template.render(template_file, template_values))
예제 #5
0
    def test_voting(self):
        """
    Test the voting system behaves as defined in the 
    design document.
    """
        user = users.User('*****@*****.**')
        user2 = users.User('*****@*****.**')

        # Day 1 -  [quote 0 and 1 are added on Day 1 and
        #            get 5 and 3 votes respectively. Rank is q0, q1.]
        # q0 (5) = 1 * 4 + 5 = 9
        # q1 (3) = 1 * 4 + 3 = 7

        quoteid0 = models.add_quote('This is a test.', user, _created=1)
        quoteid1 = models.add_quote('This is a test.', user, _created=1)
        models.set_vote(quoteid0, user, 1)
        models.set_vote(quoteid1, user, 3)
        quotes, next = models.get_quotes()

        self.assertEqual(models.voted(quotes[1], user), 1)
        self.assertEqual(models.voted(quotes[0], user), 3)

        self.assertEqual(quotes[0].key().id(), quoteid1)
        self.assertEqual(quotes[1].key().id(), quoteid0)

        models.set_vote(quoteid0, user, 5)
        quotes, next = models.get_quotes()
        self.assertEqual(quotes[0].key().id(), quoteid0)
        self.assertEqual(quotes[1].key().id(), quoteid1)

        # q0 (5) + (3) = 1 * 4 + 8 = 12
        # q1 (3) + (0) = 1 * 4 + 3 = 7
        # q2       (3) = 2 * 4 + 3 = 11
        quoteid2 = models.add_quote('This is a test.', user, _created=2)

        models.set_vote(quoteid0, user, 8)
        models.set_vote(quoteid1, user, 3)
        models.set_vote(quoteid2, user, 3)
        quotes, next = models.get_quotes()

        self.assertEqual(quotes[0].key().id(), quoteid0)
        self.assertEqual(quotes[1].key().id(), quoteid2)
        self.assertEqual(quotes[2].key().id(), quoteid1)

        # q0 (5) + (3)       = 1 * 4 + 8 = 12
        # q1 (3) + (0)       = 1 * 4 + 3 = 7
        # q2       (3) + (2) = 2 * 5 + 4 = 14
        # q3             (5) = 3 * 4 + 5 = 17

        quoteid3 = models.add_quote('This is a test.', user, _created=3)

        models.set_vote(quoteid0, user, 8)
        models.set_vote(quoteid1, user, 3)
        models.set_vote(quoteid2, user, 5)
        models.set_vote(quoteid3, user, 5)
        quotes, next = models.get_quotes()

        self.assertEqual(quotes[0].key().id(), quoteid3)
        self.assertEqual(quotes[1].key().id(), quoteid2)
        self.assertEqual(quotes[2].key().id(), quoteid0)
        self.assertEqual(quotes[3].key().id(), quoteid1)

        # q0 (5) + (3) + (1) = 1 * 4 + 9 = 13
        # q1 (3) + (0)       = 1 * 4 + 3 = 7
        # q2       (3) + (2) = 2 * 5 + 4 = 14
        # q3             (0) = 3 * 4 + 0 = 12

        models.set_vote(quoteid0, user, 9)
        models.set_vote(quoteid3, user, 0)
        quotes, next = models.get_quotes()

        self.assertEqual(quotes[0].key().id(), quoteid2)
        self.assertEqual(quotes[1].key().id(), quoteid0)
        self.assertEqual(quotes[2].key().id(), quoteid3)
        self.assertEqual(quotes[3].key().id(), quoteid1)

        models.del_quote(quoteid0, user)
        models.del_quote(quoteid1, user)
        models.del_quote(quoteid2, user)
        models.del_quote(quoteid3, user)
예제 #6
0
  def test_voting(self):
    """
    Test the voting system behaves as defined in the 
    design document.
    """
    user = users.User('*****@*****.**')
    user2 = users.User('*****@*****.**')
    
    # Day 1 -  [quote 0 and 1 are added on Day 1 and
    #            get 5 and 3 votes respectively. Rank is q0, q1.]
    # q0 (5) = 1 * 4 + 5 = 9 
    # q1 (3) = 1 * 4 + 3 = 7 

    quoteid0 = models.add_quote('This is a test.', user, _created=1)
    quoteid1 = models.add_quote('This is a test.', user, _created=1)    
    models.set_vote(quoteid0, user, 1)
    models.set_vote(quoteid1, user, 3)
    quotes, next = models.get_quotes()

    self.assertEqual(models.voted(quotes[1], user), 1)
    self.assertEqual(models.voted(quotes[0], user), 3)

    self.assertEqual(quotes[0].key().id(), quoteid1)
    self.assertEqual(quotes[1].key().id(), quoteid0)
    
    models.set_vote(quoteid0, user, 5)
    quotes, next = models.get_quotes()
    self.assertEqual(quotes[0].key().id(), quoteid0)
    self.assertEqual(quotes[1].key().id(), quoteid1)

    # q0 (5) + (3) = 1 * 4 + 8 = 12
    # q1 (3) + (0) = 1 * 4 + 3 = 7 
    # q2       (3) = 2 * 4 + 3 = 11
    quoteid2 = models.add_quote('This is a test.', user, _created=2)

    models.set_vote(quoteid0, user, 8)
    models.set_vote(quoteid1, user, 3)
    models.set_vote(quoteid2, user, 3)
    quotes, next = models.get_quotes()

    self.assertEqual(quotes[0].key().id(), quoteid0)
    self.assertEqual(quotes[1].key().id(), quoteid2)
    self.assertEqual(quotes[2].key().id(), quoteid1)


    # q0 (5) + (3)       = 1 * 4 + 8 = 12 
    # q1 (3) + (0)       = 1 * 4 + 3 = 7
    # q2       (3) + (2) = 2 * 5 + 4 = 14
    # q3             (5) = 3 * 4 + 5 = 17      

    quoteid3 = models.add_quote('This is a test.', user, _created=3)

    models.set_vote(quoteid0, user, 8)
    models.set_vote(quoteid1, user, 3)
    models.set_vote(quoteid2, user, 5)
    models.set_vote(quoteid3, user, 5)
    quotes, next = models.get_quotes()
    
    self.assertEqual(quotes[0].key().id(), quoteid3)
    self.assertEqual(quotes[1].key().id(), quoteid2)
    self.assertEqual(quotes[2].key().id(), quoteid0)
    self.assertEqual(quotes[3].key().id(), quoteid1)


    # q0 (5) + (3) + (1) = 1 * 4 + 9 = 13
    # q1 (3) + (0)       = 1 * 4 + 3 = 7 
    # q2       (3) + (2) = 2 * 5 + 4 = 14
    # q3             (0) = 3 * 4 + 0 = 12      

    models.set_vote(quoteid0, user, 9)
    models.set_vote(quoteid3, user, 0)
    quotes, next = models.get_quotes()

    self.assertEqual(quotes[0].key().id(), quoteid2)
    self.assertEqual(quotes[1].key().id(), quoteid0)
    self.assertEqual(quotes[2].key().id(), quoteid3)
    self.assertEqual(quotes[3].key().id(), quoteid1)

    models.del_quote(quoteid0, user)
    models.del_quote(quoteid1, user)
    models.del_quote(quoteid2, user)
    models.del_quote(quoteid3, user)