Repository: fedora-infra/bodhi

Issue:
Modify the Web UI to handle multiple content types
We will need to alter the web interface to handle multiple content types.


Discussion:
@ryanlerch @ralphbean I don't have many ideas for this, other than to slap some text in the right hand info box that says what kind of update it is. For a second I considered trying to come up with icons for each update type, but I can't imagine what an icon for an RPM or a module might look like.

Do either of you think more than just displaying text about the type is needed?

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -1408,9 +1408,12 @@ def content_type(self):
         """ Return the ContentType associated with this Update.
 
         If the update has no builds, this evaluates to `None`.
+
+        Returns:
+            ContentType or None: The content type of this Update or None.
         """
         if self.builds:
-            return self.builds[0].type.value
+            return self.builds[0].type
 
     def obsolete_older_updates(self, db):
         """Obsolete any older pending/testing updates.
@@ -2414,7 +2417,7 @@ def __json__(self, request=None, anonymize=False):
         # Include the karma total in the results
         result['karma'] = self.karma
         # Also, the Update content_type (derived from the builds content_types)
-        result['content_type'] = self.content_type
+        result['content_type'] = self.content_type.value if self.content_type else None
 
         # For https://github.com/fedora-infra/bodhi/issues/270, throw the JSON
         # of the test cases in our output as well but take extra care to


Test patch:
diff --git a/bodhi/tests/server/services/test_updates.py b/bodhi/tests/server/services/test_updates.py
--- a/bodhi/tests/server/services/test_updates.py
+++ b/bodhi/tests/server/services/test_updates.py
@@ -530,6 +530,23 @@ def test_edit_not_loggedin(self):
 
 class TestUpdatesService(bodhi.tests.server.functional.base.BaseWSGICase):
 
+    def test_content_type(self):
+        """Assert that the content type is displayed in the update template."""
+        res = self.app.get('/updates/bodhi-2.0-1.fc17', status=200, headers={'Accept': 'text/html'})
+
+        self.assertTrue(
+            ('<strong>Content Type</strong>\n                </div>\n                <div>\n'
+             '                  RPM') in res.text)
+
+    def test_content_type_none(self):
+        """Assert that the content type being None doesn't blow up the update template."""
+        u = Update.query.filter(Update.title == u'bodhi-2.0-1.fc17').one()
+        u.builds = []
+        self.db.commit()
+        res = self.app.get('/updates/bodhi-2.0-1.fc17', status=200, headers={'Accept': 'text/html'})
+
+        self.assertTrue('RPM' not in res.text)
+
     def test_home_html(self):
         resp = self.app.get('/', headers={'Accept': 'text/html'})
         self.assertIn('Fedora Updates System', resp)
diff --git a/bodhi/tests/server/test_models.py b/bodhi/tests/server/test_models.py
--- a/bodhi/tests/server/test_models.py
+++ b/bodhi/tests/server/test_models.py
@@ -607,6 +607,12 @@ def get_update(self, name=u'TurboGears-1.0.8-3.fc11'):
             release=rel))
         return self.klass(**attrs)
 
+    def test___json___with_no_builds(self):
+        """Test the __json__() method when there are no Builds."""
+        self.obj.builds = []
+
+        eq_(self.obj.__json__()['content_type'], None)
+
     def test_autokarma_not_nullable(self):
         """Assert that the autokarma column does not allow NULL values.
 
@@ -622,7 +628,7 @@ def test_builds(self):
         eq_(self.obj.builds[0].package.name, u'TurboGears')
 
     def test_content_type(self):
-        eq_(self.obj.content_type, 'rpm')
+        eq_(self.obj.content_type, model.ContentType.rpm)
 
     def test_mandatory_days_in_testing_critpath(self):
         """