Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[unfold.git] / portal / homeview.py
index 00b279d..1fe1d2a 100644 (file)
@@ -1,24 +1,27 @@
 # 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.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
 
-import json
 
-from unfold.loginrequired import FreeAccessView
+from unfold.loginrequired               import FreeAccessView
 
 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 manifoldapi.manifoldresult         import ManifoldResult
+from ui.topmenu                         import topmenu_items, the_user
+from myslice.configengine               import ConfigEngine
 
-from myslice.theme import ThemeView
+from myslice.theme                      import ThemeView
+from portal.account                     import Account, get_expiration
+from portal.models                      import PendingSlice
+from portal.actions                     import authority_check_pis
 
+import json, time
 import activity.user
 
 class HomeView (FreeAccessView, ThemeView):
@@ -87,18 +90,29 @@ class HomeView (FreeAccessView, ThemeView):
                                             acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
                                             acc_user_cred = account_config.get('delegated_user_credential','N/A')
                     # assigning values
-                    if acc_auth_cred=={} or acc_auth_cred=='N/A':
-                        pi = "is_not_pi"
-                    else:
-                        pi = "is_pi"
+                    #if acc_auth_cred=={} or acc_auth_cred=='N/A':
+                    #    pi = "is_not_pi"
+                    #else:
+                    #    pi = "is_pi"
+                    user_email = str(self.request.user)                   
+                    pi = authority_check_pis(self.request, user_email)
 
                     # check if the user has creds or not
                     if acc_user_cred == {} or acc_user_cred == 'N/A':
                         user_cred = 'no_creds'
                     else:
-                        user_cred = 'has_creds'
-
-
+                        exp_date = get_expiration(acc_user_cred, 'timestamp')
+                        if exp_date < time.time():
+                            user_cred = 'creds_expired'
+                        else:
+                            user_cred = 'has_creds'
+
+                    # list the pending slices of this user
+                    pending_slices = []
+                    for slices in PendingSlice.objects.filter(type_of_nodes__iexact=self.request.user).all():
+                        pending_slices.append(slices.slice_name)
+
+                    env['pending_slices'] = pending_slices
                     env['pi'] = pi
                     env['user_cred'] = user_cred                
                 else: 
@@ -145,18 +159,28 @@ class HomeView (FreeAccessView, ThemeView):
                                         acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
                                         acc_user_cred = account_config.get('delegated_user_credential','N/A')
             # assigning values
-            if acc_auth_cred=={} or acc_auth_cred=='N/A':
-                pi = "is_not_pi"
-            else:
-                pi = "is_pi"
-
+            #if acc_auth_cred=={} or acc_auth_cred=='N/A':
+            #    pi = "is_not_pi"
+            #else:
+            #    pi = "is_pi"
+            user_email = str(self.request.user) 
+            pi = authority_check_pis(self.request, user_email)
             # check if the user has creds or not
             if acc_user_cred == {} or acc_user_cred == 'N/A':
                 user_cred = 'no_creds'
             else:
-                user_cred = 'has_creds'
-           
-
+                exp_date = get_expiration(acc_user_cred, 'timestamp')
+                if exp_date < time.time():
+                    user_cred = 'creds_expired'
+                else:
+                    user_cred = 'has_creds'
+
+            # list the pending slices of this user
+            pending_slices = []
+            for slices in PendingSlice.objects.filter(type_of_nodes__iexact=self.request.user).all():
+                pending_slices.append(slices.slice_name)
+        
+            env['pending_slices'] = pending_slices
             env['pi'] = pi
             env['user_cred'] = user_cred                
             env['person'] = self.request.user