commit 8f53cfa3884a0335f1c0f0737904295149b41193
Author: Kostas Papadimitriou <kpap@grnet.gr>
Date:   Tue Feb 12 16:35:28 2013 +0200

    Translate image owner uuid -> display name in UI
    
    UI uses the introduced /user_catalog api to translate uuids to display
    names when necessary.

diff --git a/snf-cyclades-app/synnefo/ui/static/snf/css/main.css b/snf-cyclades-app/synnefo/ui/static/snf/css/main.css
index b2a52c8..5177234 100644
--- a/snf-cyclades-app/synnefo/ui/static/snf/css/main.css
+++ b/snf-cyclades-app/synnefo/ui/static/snf/css/main.css
@@ -20,7 +20,7 @@ body {
     background: url("../images/body-bg.png") repeat-x #FFFFFF;
     text-align:center;
     font-size: 16px;
-    background-position: 0px 35px; 
+    background-position: 0px 34px; 
     overflow-y: scroll;
 }
 
diff --git a/snf-cyclades-app/synnefo/ui/static/snf/js/glance_models.js b/snf-cyclades-app/synnefo/ui/static/snf/js/glance_models.js
index 997e231..ee4f4e6 100644
--- a/snf-cyclades-app/synnefo/ui/static/snf/js/glance_models.js
+++ b/snf-cyclades-app/synnefo/ui/static/snf/js/glance_models.js
@@ -122,7 +122,7 @@
 
         get_personal_images: function() {
             return _.filter(this.active(), function(i) { 
-                return i.get_owner() == snf.user.username 
+                return i.get_owner_uuid() == snf.user.username;
             });
         },
 
@@ -134,7 +134,7 @@
             return _.filter(this.active(), function(i){ 
                 return !_.include(_.keys(snf.config.system_images_owners), 
                                   i.get_owner()) && 
-                               i.get_owner() != snf.user.username &&
+                               i.get_owner_uuid() != snf.user.username &&
                                !i.is_public();
             });
         }
diff --git a/snf-cyclades-app/synnefo/ui/static/snf/js/models.js b/snf-cyclades-app/synnefo/ui/static/snf/js/models.js
index 516cbe8..aa5dbc0 100644
--- a/snf-cyclades-app/synnefo/ui/static/snf/js/models.js
+++ b/snf-cyclades-app/synnefo/ui/static/snf/js/models.js
@@ -229,7 +229,7 @@
     // Image model
     models.Image = models.Model.extend({
         path: 'images',
-
+        
         get_size: function() {
             return parseInt(this.get('metadata') ? this.get('metadata').values.size : -1)
         },
@@ -261,6 +261,10 @@
             return this.get('owner') || _.keys(synnefo.config.system_images_owners)[0];
         },
 
+        get_owner_uuid: function() {
+            return this.get('owner_uuid');
+        },
+
         is_system_image: function() {
           var owner = this.get_owner();
           return _.include(_.keys(synnefo.config.system_images_owners), owner)
@@ -268,7 +272,7 @@
 
         owned_by: function(user) {
           if (!user) { user = synnefo.user }
-          return user.username == this.get_owner();
+          return user.username == this.get('owner_uuid');
         },
 
         display_owner: function() {
@@ -1740,8 +1744,48 @@
         },
 
         parse: function (resp, xhr) {
-            var data = _.map(resp.images.values, _.bind(this.parse_meta, this));
-            return resp.images.values;
+            var parsed = _.map(resp.images.values, _.bind(this.parse_meta, this));
+            parsed = this.fill_owners(parsed);
+            return parsed;
+        },
+
+        fill_owners: function(images) {
+            // do translate uuid->displayname if needed
+            // store display name in owner attribute for compatibility
+            var uuids = [];
+
+            var images = _.map(images, function(img, index) {
+                if (synnefo.config.translate_uuids) {
+                    uuids.push(img['owner']);
+                }
+                img['owner_uuid'] = img['owner'];
+                return img;
+            });
+            
+            if (uuids.length > 0) {
+                var handle_results = function(data) {
+                    _.each(images, function (img) {
+                        img['owner'] = data.uuid_catalog[img['owner_uuid']];
+                    });
+                }
+                // notice the async false
+                var uuid_map = this.translate_uuids(uuids, false, 
+                                                    handle_results)
+            }
+            return images;
+        },
+
+        translate_uuids: function(uuids, async, cb) {
+            var url = synnefo.config.user_catalog_url;
+            var data = JSON.stringify({'uuids': uuids});
+          
+            // post to user_catalogs api
+            snf.api.sync('create', undefined, {
+                url: url,
+                data: data,
+                async: async,
+                success:  cb
+            });
         },
 
         get_meta_key: function(img, key) {
diff --git a/snf-cyclades-app/synnefo/ui/templates/home.html b/snf-cyclades-app/synnefo/ui/templates/home.html
index a1daea9..33f7007 100644
--- a/snf-cyclades-app/synnefo/ui/templates/home.html
+++ b/snf-cyclades-app/synnefo/ui/templates/home.html
@@ -635,6 +635,9 @@
             synnefo.config.login_redirect = '{{ login_redirect }}';
             synnefo.config.auth_cookie_name = '{{ auth_cookie_name }}';
 
+            synnefo.config.translate_uuids = {{ translate_uuids|safe }};
+            synnefo.config.user_catalog_url = {{ user_catalog_url|safe }};
+
             synnefo.config.network_suggested_subnets = {{ network_suggested_subnets|safe }};
             synnefo.config.network_available_types = {{ network_available_types|safe }};
             synnefo.config.network_allow_duplicate_vm_nics = {{ network_allow_duplicate_vm_nics }};
diff --git a/snf-cyclades-app/synnefo/ui/views.py b/snf-cyclades-app/synnefo/ui/views.py
index 7196c77..47e6d58 100644
--- a/snf-cyclades-app/synnefo/ui/views.py
+++ b/snf-cyclades-app/synnefo/ui/views.py
@@ -150,6 +150,9 @@ AUTOMATIC_NETWORK_RANGE_FORMAT = getattr(settings,
 GROUP_PUBLIC_NETWORKS = getattr(settings, 'UI_GROUP_PUBLIC_NETWORKS', True)
 GROUPED_PUBLIC_NETWORK_NAME = getattr(settings, 'UI_GROUPED_PUBLIC_NETWORK_NAME', 'Internet')
 
+USER_CATALOG_URL = getattr(settings, 'UI_USER_CATALOG_URL', '/user_catalogs')
+TRANSLATE_UUIDS = not getattr(settings, 'TRANSLATE_UUIDS', False)
+
 def template(name, request, context):
     template_path = os.path.join(os.path.dirname(__file__), "templates/")
     current_template = template_path + name + '.html'
@@ -173,6 +176,8 @@ def home(request):
                'request': request,
                'current_lang': get_language() or 'en',
                'compute_api_url': json.dumps(COMPUTE_API_URL),
+               'user_catalog_url': json.dumps(USER_CATALOG_URL),
+               'translate_uuids': json.dumps(TRANSLATE_UUIDS),
                 # update interval settings
                'update_interval': UPDATE_INTERVAL,
                'update_interval_increase': UPDATE_INTERVAL_INCREASE,
