1. justin1989
  2. newsmeme

Commits

danjac  committed 6756272

fixed tags view

  • Participants
  • Parent commits a38b66b
  • Branches default

Comments (0)

Files changed (3)

File newsmeme/models.py

View file
         min_posts = min(t.num_posts for t in tags)
 
         diff = (max_posts - min_posts) / 5.0
+        if diff < 0.1:
+            diff = 0.1
 
         for tag in tags:
             tag.size = int(tag.num_posts / diff)

File newsmeme/views/frontend.py

View file
 @frontend.route("/tags/")
 @keep_login_url
 def tags():
-    return render_template("tags.html", tag_cloud=Tag.cloud())
+    tags = Tag.query.cloud()
+    return render_template("tags.html", tag_cloud=tags)
+
 
 @frontend.route("/tags/<slug>/")
 @frontend.route("/tags/<slug>/<int:page>/")

File tests/test_views.py

View file
     
 class TestFrontend(TestCase):
 
+    def test_tags(self):
+
+        user = User(username="tester",
+                    email="tester@example.com",
+                    password="test")
+
+        db.session.add(user)
+        db.session.commit()
+
+        for i in xrange(20):
+
+            post = Post(author=user,
+                        tags="IT Crowd, funny, TV",
+                        title="test")
+
+            db.session.add(post)
+            db.session.commit()
+        
+        response = self.client.get("/tags/")
+        self.assert_200(response)
+
     def test_rules(self):
         response = self.client.get("/rules/")
         self.assert_200(response)