Management About page reworked + cosmetic changes
authorCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Tue, 15 Jul 2014 13:46:13 +0000 (15:46 +0200)
committerCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Tue, 15 Jul 2014 13:46:13 +0000 (15:46 +0200)
myslice/urls.py
portal/managementtababout.py [new file with mode: 0644]
portal/managementtabrequests.py
portal/templates/institution-tab-info.html [deleted file]
portal/templates/management-tab-requests.html
portal/templates/onelab/onelab_institution.html
portal/templates/onelab/onelab_management-tab-about.html [new file with mode: 0644]
portal/templates/onelab/onelab_management-tab-requests.html
portal/templates/password_reset_confirm.html
portal/templatetags/portal_filters.py

index 68ec521..1d0248c 100644 (file)
@@ -31,6 +31,7 @@ import portal.slicetabtestbeds
 import portal.slicetabusers
 import portal.slicetabmeasurements 
 
+import portal.managementtababout
 import portal.managementtabrequests
 
 #### high level choices
@@ -94,6 +95,7 @@ urls = [
     (r'^experiment/(?P<slicename>[^/]+)/?$', portal.slicetabexperiment.ExperimentView.as_view()),
     #
     (r'^management/requests/?$', portal.managementtabrequests.ManagementRequestsView.as_view()),
+    (r'^management/about/?$', portal.managementtababout.ManagementAboutView.as_view()),
     #
     url(r'^register/?$', RegistrationView.as_view(), name='registration'),     
     url(r'^portal/', include('portal.urls')),
diff --git a/portal/managementtababout.py b/portal/managementtababout.py
new file mode 100644 (file)
index 0000000..8a5f97a
--- /dev/null
@@ -0,0 +1,50 @@
+# 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 unfold.loginrequired import FreeAccessView
+
+from manifold.core.query            import Query
+from manifoldapi.manifoldapi        import execute_query
+from manifoldapi.manifoldresult import ManifoldResult
+from myslice.configengine import ConfigEngine
+
+from myslice.theme import ThemeView
+import json
+
+class ManagementAboutView (FreeAccessView, ThemeView):
+    template_name = 'management-tab-about.html'
+
+    def get (self, request):
+        if request.user.is_authenticated(): 
+            user_query  = Query().get('user').select('user_hrn','parent_authority').filter_by('user_hrn','==','$user_hrn')
+            user_details = execute_query(self.request, user_query)
+            
+            user_local_query  = Query().get('local:user').select('config').filter_by('email','==',str(self.request.user))
+            user_local_details = execute_query(self.request, user_local_query)
+            user_authority = json.loads(user_local_details[0]['config']).get('authority')
+            
+            authority_query = Query().get('authority').select('description', 'authority_hrn', 'legal', 'address', 'abbreviated_name', 
+                                                              'scientific', 'city', 'name', 'url', 'country', 'enabled', 'longitude', 
+                                                              'tech', 'latitude', 'pi_users', 'parent_authority', 'onelab_membership', 
+                                                              'postcode').filter_by('authority_hrn','==',user_authority)
+            authority_details = execute_query(self.request, authority_query)
+            
+            authority_contacts = {}
+            authority_contacts['scientific'] = [ x.strip()[1:-1] for x in authority_details[0]['scientific'][1:-1].split(',') ]
+            authority_contacts['technical'] = [ x.strip()[1:-1] for x in authority_details[0]['tech'][1:-1].split(',') ]
+            
+            authority_contacts['legal'] = [ x.strip().replace('"','') for x in authority_details[0]['legal'][1:-1].split(',') ]
+            print authority_contacts['legal']
+            
+            
+            print "#######",authority_contacts
+            print "$$$$$$$",user_local_details
+            print "@@@@@@@",authority_details
+            
+        return render_to_response(self.template, { 'theme' : self.theme, 'authority' : authority_details[0], 'authority_contacts' : authority_contacts }, context_instance=RequestContext(request))
+
index 50801e9..850bbc6 100644 (file)
@@ -7,13 +7,13 @@ from manifoldapi.manifoldapi         import execute_query
 from django.views.generic.base      import TemplateView
 
 from unfold.loginrequired           import LoginRequiredView
-from django.http import HttpResponse
-from django.shortcuts import render
+from django.http                    import HttpResponse
+from django.shortcuts               import render
 
-from manifold.core.query             import Query, AnalyzedQuery
-from manifoldapi.manifoldapi         import execute_query
+from manifold.core.query            import Query, AnalyzedQuery
+from manifoldapi.manifoldapi        import execute_query
 
-from portal.actions             import get_requests
+from portal.actions                 import get_requests
 
 from myslice.theme import ThemeView
 
diff --git a/portal/templates/institution-tab-info.html b/portal/templates/institution-tab-info.html
deleted file mode 100644 (file)
index e69de29..0000000
index 3679796..d534915 100644 (file)
                <i>There is no pending request waiting for validation.</i>
        </div>
 {% endif %}
-
+<br />
 <div class="col-md-12">
        <h2>Sub-Authorities</h2>
 </div>
        <i>There is no pending request waiting for validation.</i>
 </div>
 {% endif %}
-
+<br />
 <div class="col-md-12">
        <h2>Authorities with delegation</h2>
 </div>
        <i>There is no pending request waiting for validation.</i>
 </div>
 {% endif %}
+<br />
 <div class="col-md-12">
        <button class="btn btn-onelab" type="button" id="portal__validate" onclick="on_click_event();"><span class="glyphicon glyphicon-ok"></span> Validate</button>
 </div>
index 6c35812..c8a668f 100644 (file)
@@ -18,7 +18,7 @@
        <div class="row">
                <div class="col-md-12">
                        <ul class="nav nav-tabs nav-section">
-                               <li class="active"><a href="#info">About</a></li>
+                               <li class="active"><a href="#about">About</a></li>
                                <li><a href="#users">Users</a></li>
                                <li><a href="#slices">Slices</a></li>
                                <li><a href="#requests">Requests</a></li>
        </div>
 </div>
 <div class="container tab-content">
-       <div class="tab-pane active row" id="info">
-               <div class="col-md-12 el">
-                       <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="authority-data" style="float:left; width:50%;"></div>
-                               <div id="onelab_membership" style="float:right; width:50%;">
-                                   <img src="{{ STATIC_URL }}img/onelab-logo.png" alt="" /><br>
-                               <div id="onelab-data"></div>
-                               </div>
-                   </div>
-          </div>
+       <div class="tab-pane active row" id="about">
        </div>
        
        <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
 
        <div class="tab-pane row" id="slices">
                <div class="col-md-12 el">
-               {% if 'is_pi'  in pi %}
-               <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create slice</button>
-               {% else %}
-               <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request slice</button>
-               {% endif %}
-               <br /><br />
            <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" class="table">
            </div>
        {% if 'is_pi'  in pi %}
         <div>
+               {% if 'is_pi'  in pi %}
+                       <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create slice</button>
+                       {% else %}
+                       <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request slice</button>
+                       {% endif %}
             <button id="renewslices" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
             <button id="deleteslices" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
         </div>
 $(document).ready(function() {
     {% if person %}
     {% 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_name').text(val.name);
-                authority_row = "<img src='{{ STATIC_URL }}img/institutions/{{user_details.parent_authority}}.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>Status: </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 = [];
@@ -236,12 +167,14 @@ $(document).ready(function() {
                e.preventDefault();
                $(this).tab('show');
        var id = $(this).attr('href').substr(1);
-       if (id == 'requests') 
+       if ((id == 'requests') || (id == 'about'))
                $("#" + id).load('/management/' + id);
        });
        var hash = window.location.hash;
        if (hash) {
                $('.nav-tabs a[href='+hash+']').click();
+       } else {
+               $('.nav-tabs a[href=#about]').click();
        }
 });
 </script>
diff --git a/portal/templates/onelab/onelab_management-tab-about.html b/portal/templates/onelab/onelab_management-tab-about.html
new file mode 100644 (file)
index 0000000..0c0a94f
--- /dev/null
@@ -0,0 +1,41 @@
+{% load portal_filters %}
+<div class="col-md-6">
+       <div>
+               <img src="{{ STATIC_URL|add:'img/institutions/'|add:authority.authority_hrn|add:'.gif'|file_exists }}" alt="{{authority.name}}">
+       </div>
+       <br />
+       <h3><a href="{{authority.url}}">{{authority.name}}</a></h3>
+       <p>
+               {{authority.address}} <br />
+               {{authority.postcode}} {{authority.city}} <br />
+               {{authority.country}}
+       </p>
+       <br />
+       <h4>Onelab membership</h4> 
+       <p>
+               {{ authority.onelab_membership }}
+       </p>
+</div>
+<div class="col-md-6">
+       <h4>Legal Contact:</h4>
+       <p>
+       {% for c in authority_contacts.legal %}
+                {{ c }} <br />
+       {% endfor %}
+       </p>
+       <br />
+       <h4>Scientific Contact:</h4>
+       <p>
+       {% for c in authority_contacts.scientific %}
+               {{ c }} <br />
+       {% endfor %}
+       </p>
+       <br />
+       <h4>Technical Contact:</h4>
+       <p>
+       {% for c in authority_contacts.technical %}
+               {{ c }} <br />
+       {% endfor %}
+       </p>
+</div>
+<script>$(document).ready(function() {$('#authority_name').text('{{authority.name}}')});</script>
\ No newline at end of file
index 3679796..488e63e 100644 (file)
@@ -14,9 +14,7 @@
                });
                if (ids.length > 0) {
                        var id_str = ids.join('/');
-
                        // XXX spinner
-
                        $.getJSON('/portal/validate_action/' + id_str,
                                function(status) {
                                        $.each(status, function(request_type__id, request_status) {
@@ -98,7 +96,6 @@
 
     {% endfor %}
        </table>
-       </div>
        {% endfor %}
 
 {% else %}
                <i>There is no pending request waiting for validation.</i>
        </div>
 {% endif %}
-
+<div>nnllknjkn<br /><br /></div>
 <div class="col-md-12">
        <h2>Sub-Authorities</h2>
 </div>
        
        {% for authority, requests in sub_authorities.items %}
        <div class="col-md-12">
-       <h3>{{authority}}</h3>
-           <table class="table">
+               <h2>{{authority}}</h2>
+       </div>
+       
+       <table class="table">
              <th>
                <td>Type</td>
                <td>Id</td>
            <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
                  </tr>
            {% endfor %}
-           </table>
-       </div>
+       </table>
        {% endfor %}
 {% else %}
 <div class="col-md-12">
        {% for authority, requests in delegation_authorities.items %}
        <div class="col-md-12">
                <h3>{{authority}}</h3>
-                   <table class="table">
+       </div>
+       <table class="table">
                      <th>
                        <td>Type</td>
                        <td>Id</td>
                    <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
                          </tr>
                    {% endfor %}
-                   </table>
-               </div>
+       </table>
                {% endfor %}
 {% else %}
 <div class="col-md-12">
index 868f818..eed94a0 100644 (file)
@@ -19,7 +19,7 @@
        <div class="col-md-3">
                <form action="" method="post">{% csrf_token %}
                {{ form.new_password1.errors }}
-               <label for="id_new_password1">{% trans 'New password:' %}</label>
+               <label for="id_new_password1">New password:</label>
        </div>
        <div class="col-md-3">
                {{ form.new_password1 }}
@@ -28,7 +28,7 @@
 <div class="row">
        <div class="col-md-3">
                {{ form.new_password2.errors }}
-               <label for="id_new_password2">{% trans 'Confirm password:' %}</label>
+               <label for="id_new_password2">Confirm password:</label>
        </div>
        <div class="col-md-3">  
                {{ form.new_password2 }}
index 9bd0175..74f113a 100644 (file)
@@ -1,5 +1,6 @@
 from django import template
 from django.template.loader_tags import do_include
+from django.core.files.storage import default_storage
 from myslice.settings import theme
 
 register = template.Library()
@@ -37,4 +38,13 @@ def widget(parser, token):
         raise template.TemplateSyntaxError, \
             "%r tag requires a single argument" % token.contents.split()[0]
 
-    return IncludeNode(template_name[1:-1])
\ No newline at end of file
+    return IncludeNode(template_name[1:-1])
+
+@register.filter(name='file_exists')
+def file_exists(filepath):
+    if default_storage.exists('portal' + filepath):
+        return filepath
+    else:
+        index = filepath.rfind('/')
+        new_filepath = filepath[:index] + '/image.png'
+        return new_filepath
\ No newline at end of file