Institution: page is dynamic, query based on user.parent_authority
authorLoic Baron <loic.baron@lip6.fr>
Thu, 27 Feb 2014 10:41:00 +0000 (11:41 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Thu, 27 Feb 2014 10:41:00 +0000 (11:41 +0100)
portal/institution.py
portal/templates/institution.html

index b984c7a..70d88dd 100644 (file)
@@ -1,18 +1,19 @@
-# this somehow is not used anymore - should it not be ?
 from django.core.context_processors import csrf
-from django.http import HttpResponseRedirect
-from django.contrib.auth import authenticate, login, logout
-from django.template import RequestContext
-from django.shortcuts import render_to_response
-from django.shortcuts import render
+from django.http                    import HttpResponseRedirect
+from django.contrib.auth            import authenticate, login, logout
+from django.template                import RequestContext
+from django.shortcuts               import render_to_response
+from django.shortcuts               import render
 
-from unfold.loginrequired import FreeAccessView
+from unfold.loginrequired           import FreeAccessView
 
-from manifoldapi.manifoldresult import ManifoldResult
-from ui.topmenu import topmenu_items, the_user
-from myslice.configengine import ConfigEngine
+from manifold.core.query            import Query
+from manifoldapi.manifoldapi        import execute_query
+from manifoldapi.manifoldresult     import ManifoldResult
+from ui.topmenu                     import topmenu_items, the_user
+from myslice.configengine           import ConfigEngine
 
-from theme import ThemeView
+from theme                          import ThemeView
 
 class InstitutionView (FreeAccessView, ThemeView):
     template_name = 'institution.html'
@@ -33,12 +34,14 @@ class InstitutionView (FreeAccessView, ThemeView):
 
         if request.user.is_authenticated(): 
             env['person'] = self.request.user
+            user_query  = Query().get('user').select('user_hrn','parent_authority').filter_by('user_hrn','==','$user_hrn')
+            user_details = execute_query(self.request, user_query)
+            env['user_details'] = user_details[0]
         else: 
             env['person'] = None
     
         env['theme'] = self.theme
     
-
         env['username']=the_user(request)
         env['topmenu_items'] = topmenu_items(None, request)
         if state: env['state'] = state
index 6026b71..e4003b4 100644 (file)
     <div class="home-panel" id="institution">
         <h1><img src="{{ STATIC_URL }}img/icon_authority_color_small.png" alt="" /> Affiliation to an Institution</h1>
         <br>
-        <div style="float:left; width:30%;">
-            
-            <img src="{{ STATIC_URL }}img/onelab-logo.png" alt="" /><br>
-            <b>Membership:</b> Governor
-        </div>
-        <div style="float:right; width:70%;">
-            <img src="http://www.upmc.fr/skins/UPMC/templates/index/resources/img/upmc-logotype.gif" alt="" /><br>
-            <br>
-            <b>authority:</b> onelab.upmc<br>
-            <br>
-            <b>Université Pierre et Marie Curie</b><br>
-            <br>
-            <b>Address:</b> 4 Place Jussieu, 75005 Paris<br>
-            <br>
-            <b>Country:</b> France<br>
-            <br>
-            <br>
-            <h2>Contacts</h2>
-            <b>Legal:</b> Président Jean Chambaz<br>
-            <br>
-            <b>Scientific:</b> Dr Timur Friedman, Prof Serge Fdida
+        <div id="authority-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Authority" /></div>
+        <div id="authority-tab-loaded" style="display:none;">
+            <div id="onelab_membership" style="float:left; width:30%;">
+                <img src="{{ STATIC_URL }}img/onelab-logo.png" alt="" /><br>
+                <div id="onelab-data"></div>
+            </div>
+            <div id="authority-data" style="float:right; width:70%;">
+            </div>
         </div>
     </div>
     <div class="home-panel" id="users" style="display:none;">
                <br>
-        <h1>Users: onelab.upmc</button></h1>
+        <h1>Users: {{user_details.parent_authority}}</button></h1>
         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
         <div id="user-tab-loaded" style="display:none;">
             <table id="user-tab">
@@ -55,7 +42,7 @@
        </div>
     <div class="home-panel" id="slices" style="display:none;">
         <br>
-        <h1>Slices: onelab.upmc <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create a Slice</button></h1>
+        <h1>Slices: {{user_details.parent_authority}} <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create a Slice</button></h1>
         <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
         <div id="slice-tab-loaded" style="display:none;">
             <table id="slice-tab">
             */
         });
         {% if person %}
-        $.post("/rest/slice/",{'filters':{'parent_authority':'ple.upmc'}}, function( data ) {
+        {% if user_details.parent_authority %}
+        $.post("/rest/authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
+            var authority_data = [];
+            var onelab_data = [];
+                       /* 'city','enabled','legal','longitude','onelab_membership','address','parent_authority','slice','user','country',
+            'tech','abbreviated_name','url','postcode','description','scientific','authority_hrn','latitude','name'    */
+            $.each( data, function( key, val ) {
+                authority_row = "<img src='http://www.upmc.fr/skins/UPMC/templates/index/resources/img/upmc-logotype.gif' alt='' /><br>";
+                authority_row += "<br>";
+                authority_row += "<b>authority:</b> "+val.authority_hrn+"<br>";
+                authority_row += "<br>";
+                authority_row += "<b>"+val.name+"</b><br>";
+                authority_row += "<br>";
+                authority_row += "<b>Address:</b> "+val.address+"<br>";
+                authority_row += "<b>City:</b> "+val.postcode+" "+val.city+"<br>";
+                authority_row += "<br>";
+                authority_row += "<b>Country:</b> "+val.country+"<br>";
+                authority_row += "<br>";
+                authority_row += "<br>";
+                authority_row += "<h2>Contacts</h2>";
+                authority_row += "<b>Legal:</b> ";
+                /*
+
+                TODO: find a way to express JSON correctly given the constrains: CSV / JSON
+
+                legal = jQuery.parseJSON(val.legal);
+                if($.isArray(legal)){
+                    $.each(legal, function(k,v){
+                        authority_row += k+" "+v+"<br>";
+                    });
+                }else{
+                */
+                    authority_row += val.legal+"<br>";
+                //}
+                authority_row += "<br>";
+                authority_row += "<b>Scientific:</b> ";
+                /*
+                scientific = jQuery.parseJSON(val.scientific);
+                if($.isArray(scientific)){
+                    $.each(scientific, function(v){
+                        authority_row += v+", ";
+                    });
+                }else{
+                */
+                    authority_row += val.scientific+"<br>";
+                //}
+                onelab_membership = "<b>Membership:</b> "+val.onelab_membership;
+                onelab_data.push(onelab_membership);
+                authority_data.push(authority_row);
+            });
+            $("div#authority-data").html(authority_data.join( "" ));
+            $("div#onelab-data").html(onelab_data.join( "" ));
+            $("div#authority-tab-loaded").css("display","block");
+            $("div#authority-tab-loading").css("display","none");
+         });
+
+        $.post("/rest/slice/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
             var list_slices = [];
             var table_slices = [];
             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "user", "slice_urn", "slice_expires" */
             $("table#slice-tab tr:last").after(table_slices.join( "" ));
             $("div#slice-tab-loaded").css("display","block");
             $("div#slice-tab-loading").css("display","none");
-         });
-         {% endif %}
-               {% if person %}
-        $.getJSON("/rest/user/", function( data ) {
+        });
+
+        $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
             var list_users = [];
             var table_users = [];
                        /*
                        */
             $.each( data, function( key, val ) {
                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
-                /*if(val.nodes=="undefined" || val.nodes==null){
-                    nodes_length=0;
-                }else{
-                    nodes_length=val.nodes.length;
-                }
-
-                if(val.user=="undefined" || val.user==null){
-                    user_length=0;
-                }else{
-                    user_length=val.user.length;
-                }
-
-                if(val.slice_url=="undefined" || val.slice_url==null){
-                    slice_url="";
-                }else{
-                    slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
-                }*/
-                
                 user_row = "<tr>";
                 user_row += "<td><input type='checkbox'></td>";
                 user_row += "<td>"+val.user_email+"</td>";
                 table_users.push(user_row);
                 
             });
-           
-            /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
             $("table#user-tab tr:last").after(table_users.join( "" ));
             $("div#user-tab-loaded").css("display","block");
             $("div#user-tab-loading").css("display","none");
          });
          {% endif %}
+         {% endif %}
     });
 </script>
 {% endblock unfold_main %}