Merge branch 'master' of ssh://git.onelab.eu/git/myslice
authorCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Thu, 24 Oct 2013 15:09:24 +0000 (17:09 +0200)
committerCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Thu, 24 Oct 2013 15:09:24 +0000 (17:09 +0200)
18 files changed:
apache/myslice.conf
debian/unfold.install
manifold/manifoldapi.py
myslice/config.py
myslice/myslice.ini.localhost [moved from myslice/myslice.ini with 100% similarity]
myslice/wsgi.py [moved from apache/myslice.wsgi with 100% similarity]
portal/contactview.py
portal/homeview.py
portal/resourceview.py
portal/sliceview.py
portal/templates/contact.html
portal/templates/registration_view.html
portal/templates/slice-request-view.html
setup.py
ui/templates/widget-topmenu.html
ui/topmenu.py
unfold/loginrequired.py
unfold/page.py

index 9e8a155..b782452 100644 (file)
@@ -1,7 +1,7 @@
 <VirtualHost *:80>
-        WSGIScriptAlias / /usr/share/unfold/apache/myslice.wsgi
-        <Directory /usr/share/unfold/apache>
-        <Files myslice.wsgi>
+        WSGIScriptAlias / /usr/share/unfold/myslice/wsgi.py
+        <Directory /usr/share/unfold/myslice>
+        <Files wsgi.py>
         Order deny,allow
         Allow from all
         </Files>
index 4f3996e..a86e983 100644 (file)
@@ -12,4 +12,3 @@ usr/share/unfold/trash
 usr/share/unfold/debug_platform
 manage.py usr/share/unfold/
 apache/myslice.conf /etc/apache2/sites-available
-apache/myslice.wsgi usr/share/unfold/apache
index c00882a..e7c6ce9 100644 (file)
@@ -20,13 +20,13 @@ class ManifoldAPI:
 
     def __init__(self, auth=None, cainfo=None):
         
-        config = Config()
         self.auth = auth
         self.cainfo = cainfo
         self.errors = []
         self.trace = []
         self.calls = {}
         self.multicall = False
+        config = Config()
         self.url = config.manifold_url()
         self.server = xmlrpclib.Server(self.url, verbose=False, allow_none=True)
 
index 31dc7e3..61c2281 100644 (file)
@@ -2,15 +2,19 @@ import os.path
 from ConfigParser import RawConfigParser
 from myslice.settings import ROOT
 
-# myslice/myslice.ini
-# as this code suggests, you have the option to write myslice/myslice.ini
+# as this code suggests, you have the option to override these defaults
+# by writing a file myslice/myslice.ini
 # that looks like this
 #[manifold]
 #url = http://manifold.pl.sophia.inria.fr:7080/
 #admin_user = admin
 #admin_password = admin
 
-class Config:
+# use a singleton instead of staticmethods
+from manifold.util.singleton    import Singleton
+
+class Config(object):
+    __metaclass__ = Singleton
 
     # the OpenLab-wide backend as managed by UPMC
     # xxx production should probably use https of course
@@ -20,40 +24,25 @@ class Config:
     # the INRIA setup is with "http://manifold.pl.sophia.inria.fr:7080/"
 
     default_manifold_admin_user     = 'admin'
-    default_manifold_admin_password = None
-
-    _config_parser = None
-
-    # having grown tired of screwing up with git stashes 
-    # taking away my local config, we now more properly use
-    # an external config file to override teh default
-    # XXX we might use support from manifold util classes --jordan
-    @staticmethod
-    def manifold_url ():
-        if Config._config_parser: 
-            return Config._config_parser.get('manifold','url')
-        config = RawConfigParser ()
-        config.add_section('manifold')
-        config.set ('manifold', 'url', Config.default_manifold_url)
-        config.read (os.path.join(ROOT,'myslice/myslice.ini'))
-        Config._config_parser=config
-        return Config.manifold_url()
-
-    @staticmethod
-    def manifold_admin_user_password():
-        if Config._config_parser: 
-            admin_user = Config._config_parser.get('manifold','admin_user')
-            admin_password = Config._config_parser.get('manifold','admin_password')
-            return (admin_user, admin_password)
-        config = RawConfigParser ()
-        config.add_section('manifold')
-        config.set ('manifold', 'admin_user', Config.default_manifold_admin_user)
-        config.set ('manifold', 'admin_password', Config.default_manifold_admin_password)
-        config.read (os.path.join(ROOT,'myslice/myslice.ini'))
-        Config._config_parser=config
-        return Config.manifold_admin_user_password()
+    default_manifold_admin_password = 'admin'
+
+
+    def __init__ (self):
+        parser = RawConfigParser ()
+        parser.add_section('manifold')
+        parser.set ('manifold', 'url', Config.default_manifold_url)
+        parser.set ('manifold', 'admin_user', Config.default_manifold_admin_user)
+        parser.set ('manifold', 'admin_password', Config.default_manifold_admin_password)
+        parser.read (os.path.join(ROOT,'myslice/myslice.ini'))
+        self.config_parser=parser
+
+    def manifold_url (self):
+        return self.config_parser.get('manifold','url')
+
+    def manifold_admin_user_password(self):
+        return (self.config_parser.get('manifold','admin_user'),
+                self.config_parser.get('manifold','admin_password'))
 
     # exporting these details to js
-    @staticmethod
-    def manifold_js_export ():
-        return "var MANIFOLD_URL = '%s';\n"%Config.manifold_url();
+    def manifold_js_export (self):
+        return "var MANIFOLD_URL = '%s';\n"%self.manifold_url();
similarity index 100%
rename from apache/myslice.wsgi
rename to myslice/wsgi.py
index 0f2e401..c07f397 100644 (file)
@@ -40,6 +40,6 @@ class ContactView (View):
     def _display (self, request, form):
         return render(request, 'contact.html', {
                 'form': form,
-                'topmenu_items': topmenu_items('Contact Us', request),
+                'topmenu_items': topmenu_items('Contact', request),
                 'username': the_user (request)
                 })
index b9d039a..960c8f0 100644 (file)
@@ -14,8 +14,9 @@ class HomeView (View):
 
     # expose this so we can mention the backend URL on the welcome page
     def default_env (self):
+        config=Config()
         return { 
-                 'MANIFOLD_URL':Config.manifold_url(),
+                 'MANIFOLD_URL':config.manifold_url(),
                  }
 
     def post (self,request):
@@ -56,7 +57,7 @@ class HomeView (View):
     def get (self, request, state=None):
         env = self.default_env()
         env['username']=the_user(request)
-        env['topmenu_items'] = topmenu_items('', request)
+        env['topmenu_items'] = topmenu_items(None, request)
         if state: env['state'] = state
         elif not env['username']: env['state'] = "Please sign in"
         return render_to_response('home-view.html',env, context_instance=RequestContext(request))
index 7e08fe8..1191b6f 100644 (file)
@@ -84,7 +84,7 @@ class ResourceView(TemplateView):
         # more general variables expected in the template
         context['title'] = 'Information about a resource'
         # the menu items on the top
-        context['topmenu_items'] = topmenu_items('Dashboard', self.request)
+        context['topmenu_items'] = topmenu_items(None, self.request)
         # so we can sho who is logged
         context['username'] = the_user(self.request)
 
index 9d335f4..efceec4 100644 (file)
@@ -37,7 +37,8 @@ class SliceView (LoginRequiredAutoLogoutView):
         page.add_js_files  ( [ "js/common.functions.js" ] )
         page.add_js_chunks ('$(function() { messages.debug("sliceview: jQuery version " + $.fn.jquery); });')
         page.add_js_chunks ('$(function() { messages.debug("sliceview: users turned %s"); });'%("on" if do_query_users else "off"))
-        page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(Config.manifold_url()))
+        config=Config()
+        page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(config.manifold_url()))
         page.expose_js_metadata()
     
         metadata = page.get_metadata()
index 5161971..2652647 100644 (file)
@@ -22,9 +22,7 @@
       <div class="col-xs-4"> {{ field.errors }} {{ field }} <p class="form-hint">{{ field.help_text }}</p> </div>
     </div>
     {% endfor %}
-    <div class="col-xs-offset-4 col-xs-4">
-      <button class="submit btn btn-default" type="submit">Submit</button>
-    </div>
+    <button class="submit btn btn-default col-md-offset-4 col-xs-4" type="submit">Send to Support</button>
   </fieldset>
   </form>
 </div>
index d7788d0..6f709f4 100644 (file)
@@ -91,9 +91,8 @@
       <div class="col-xs-4"><p class="form-hint">Account Delegation: Manual (Advanced Users)</p></div>
     </div>
     <div class="form-group" id="register">
-      <div class="col-xs-offset-4 col-xs-4">
-       <button class="submit btn btn-default" type="submit">Register</button>
-      </div>
+      <button class="submit btn btn-default col-md-offset-4 col-xs-4" type="submit">Register</button>
+    </div>
     </div>
   </fieldset>
   </form>  
index f437ae0..6aede04 100644 (file)
@@ -25,9 +25,7 @@
       <div class="col-xs-4"> <p class="form-hint">{{ field.help_text }}</p> </div>
     </div>
     {% endfor %}
-    <div class="col-xs-offset-4 col-xs-4">
-      <button class="submit btn btn-default" type="submit">Submit</button>
-    </div>
+    <button class="submit btn btn-default col-md-offset-4 col-xs-4" type="submit">Request Slice</button>
   </fieldset>
   </form>
 </div>
index 98d1368..157641a 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -20,5 +20,5 @@ setup(packages = packages,
         ( 'static/img', glob ('static/img/*')),
         ( 'static/fonts', glob ('static/fonts/*')),
         ( 'templates', glob ('templates/*')),
-        ( 'apache', [ 'apache/myslice.conf', 'apache/myslice.wsgi' ]),
+        ( 'apache', [ 'apache/myslice.conf' ]),
         ])
index f5308de..b31b133 100644 (file)
@@ -23,7 +23,7 @@
          <ul class="dropdown-menu">
            {% for dd in d.contents %}
            {% if dd.is_active %}<li class='active'>{% else %}<li class='other'>{% endif %}
-           <a class="dropdown-toggle" href="{{ dd.href }}"> {{ dd.label }} </a> </li>
+           <a href="{{ dd.href }}"> {{ dd.label }} </a> </li>
            {% endfor %}
          </ul>
         </li>
index 72904f9..bdee674 100644 (file)
@@ -7,33 +7,35 @@
 # ### a dropdown
 # { 'label': ..., 'href'=..., 'dropdown':True, 'contents': [ { 'label':.., 'href'} ] }
 # , ..]
+
+# current: the beginning of the label in the menu that you want to outline
 def topmenu_items (current,request=None):
     has_user=request.user.is_authenticated()
     result=[]
     if has_user:
         result.append({'label':'Dashboard', 'href': '/portal/dashboard/'})
         result.append({'label':'Request a slice', 'href': '/portal/slice_request/'})
-        result.append({'label':'My Account', 'href': '/portal/account/'})
-        result.append({'label':'Contact Support', 'href': '/portal/contact/'})
-# Not really useful at this point, is it ?
-# This should probably go into dashboard at some point
-#        result.append({'label':'Platforms', 'href': '/portal/platforms/'})
-# the code for building a dropdown instead - but somehow this is broken
-#        dropdown = [ {'label':'..', 'href': '..'}, ...]
-#        result.append({'label': 'More', 'href':"#", 'dropdown':True, 'contents':dropdown})
+        dropdown = []
+        dropdown.append({'label':'My Account', 'href': '/portal/account/'})
+        dropdown.append({'label':'Contact Support', 'href': '/portal/contact/'})
+        result.append({'label': 'More', 'href':"#", 'dropdown':True, 'contents':dropdown})
     else:
         result.append({'label':'Home', 'href': '/login'})
         # looks like this is accessible to non-logged users
         result.append({'label':'Platforms', 'href': '/portal/platforms/'})
         result.append({'label':'Register', 'href': '/portal/register/'})
         result.append({'label':'Contact Support', 'href': '/portal/contact/'})
-    # mark active
-    for d in result:
-        if 'dropdown' in d:
-            for dd in d['contents']:
-                if dd['label'] == current: dd['is_active']=True
-        else:
-            if d['label'] == current: d['is_active']=True
+    # mark active if the provided 'current', even if shorter, matches the beginning of d['label']
+    
+    if current is not None:
+        current=current.lower()
+        curlen=len(current)
+        def mark_active(d):
+            if d['label'][:curlen].lower() == current: d['is_active']=True
+        for d in result:
+            mark_active(d)
+            if 'dropdown' in d:
+                for dd in d['contents']: mark_active(dd)
     return result
 
 def the_user (request):
index 0f46ff7..ebe33d5 100644 (file)
@@ -32,7 +32,9 @@ def logout_on_manifold_exception (fun_that_returns_httpresponse):
         except ManifoldException, manifold_result:
             # xxx we need a means to display this message to user...
             from django.contrib.auth import logout
-            logout(request)
+            # in some unusual cases, this might fail
+            try: logout(request)
+            except: pass
             return HttpResponseRedirect ('/')
         except Exception, e:
             # xxx we need to sugarcoat this error message in some error template...
index 07879e7..3627e16 100644 (file)
@@ -140,7 +140,8 @@ class Page:
         self.add_js_chunks("var MANIFOLD_METADATA =" + self.get_metadata().to_json() + ";")
 
     def expose_js_manifold_config (self):
-        self.add_js_chunks(Config.manifold_js_export())
+        config=Config()
+        self.add_js_chunks(config.manifold_js_export())
 
     #################### requirements/prelude management
     # just forward to self.prelude - see decorator above