Commits

Anonymous committed 6756272

fixed tags view

Comments (0)

Files changed (3)

newsmeme/models.py

         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)

newsmeme/views/frontend.py

 @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>/")

tests/test_views.py

     
 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)