login/logout stuff working
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 10 Dec 2012 20:27:21 +0000 (21:27 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 10 Dec 2012 20:27:21 +0000 (21:27 +0100)
auth/backend.py
auth/views.py
engine/plugin.py
engine/views.py
myslice/viewutils.py
plugins/simplelist.py
static/css/logout.css [new file with mode: 0644]
templates/widget-logout.html
templates/widget-simplelist.html [new file with mode: 0644]

index a09ef60..25114e7 100644 (file)
@@ -26,8 +26,11 @@ class MyCustomBackend:
             # Check if the user exists in Django's local database
             user = User.objects.get(email=username)
         except User.DoesNotExist:
+            print 'creating django user',username
             # Create a user in Django's local database
-            user = User.objects.create_user(time.time(), username, 'passworddoesntmatter')
+            # warning: the trick here is pass current time as an id, and name as email
+            # create_user(username, email=None, password=None)
+            user = User.objects.create_user(time.time(), username, 'password-doesnt-matter')
 
         return user
 
index 9d71850..d1e78b5 100644 (file)
@@ -7,6 +7,8 @@ from django.http import HttpResponseRedirect
 
 from auth.backend import MyCustomBackend
 
+from myslice.viewutils import the_user
+
 def login_user(request):
     state = "Please log in below..."
     username = password = ''
@@ -30,7 +32,8 @@ def login_user(request):
             return render_to_response('view-login.html',env, context_instance=RequestContext(request))
     else:
         state='Welcome to MySlice'
-        env['state']=state; env['username']=''
+        env['state']=state
+        env['username']=the_user(request)
         return render_to_response('view-login.html',env, context_instance=RequestContext(request))
 
 # hard question : where should we redirect requests to logout if user is not logged in ?
@@ -38,7 +41,8 @@ def logout_user (request):
     # xxx check that we're indeed logged in
     if not request.user.is_authenticated():
         return HttpResponseRedirect ('/')
-    return render_to_response('view-logout.html',{},context_instance=RequestContext(request))
+    return render_to_response('view-logout.html',{'username':the_user(request)},
+                              context_instance=RequestContext(request))
 
 def do_logout_user (request):
     # xxx check that we're indeed logged in
index a76881a..7a8e7ec 100644 (file)
@@ -28,10 +28,10 @@ class Plugin:
 
     # returns the html code for that plugin
     # in essence, wraps the results of self.render_content ()
-    def render (self):
+    def render (self, request):
         uuid = self.uuid
         title = self.get_class()
-        plugin_content = self.render_content ()
+        plugin_content = self.render_content (request)
 
         # xxx missing from the php version
         # compute an 'optionstr' from the set of available settings/options as a json string
@@ -48,3 +48,7 @@ class Plugin:
 
         return result
         
+    ### abstract interface
+    def render_content (self, request):
+        """Should return an HTML fragment"""
+        return "Your plugin needs to redefine 'render_content(self, request)'"
index 6d73a47..d5020a9 100644 (file)
@@ -12,7 +12,7 @@ from myslice.viewutils import menu_items, the_user
 def test_plugin_view (request):
     
     test_plugin = SimpleList (visible=True, hidable=True)
-    plugin_content = test_plugin.render ()
+    plugin_content = test_plugin.render (request)
 
     print '--------------------'
     print plugin_content
index 5360af5..fa3a603 100644 (file)
@@ -8,8 +8,8 @@ standard_menu_items = [ { 'label':'Slice view',  'href': '/slice/'},
                         { 'label':'Mini plugin', 'href': '/plugin/'},
                         ]
 
-login_out_items = { False: { 'label':'Login', 'href':'/login/'},
-                    True:  { 'label':'Logout', 'href':'/logout/'}}
+#login_out_items = { False: { 'label':'Login', 'href':'/login/'},
+#                    True:  { 'label':'Logout', 'href':'/logout/'}}
 
 def menu_items (current,request=None):
     result=deepcopy(standard_menu_items)
@@ -17,15 +17,16 @@ def menu_items (current,request=None):
         if d['label'].lower().find(current)>=0: d['active']=True
     if not request: return result
     has_user=request.user.is_authenticated()
-    result.append (login_out_items [ has_user] )
+#    result.append (login_out_items [ has_user] )
     return result
 
 def the_user (request):
     "This code below is broken"
-    return 'user-xxx-name'
-    if not request.user.is_authenticated (): return ''
-    else: return request.user.username
-
+    if not request.user.is_authenticated (): 
+        print 'void'
+        return ''
+    else: 
+        return request.user.email
 
 # temporary for sample views
 lorem="""
index 202dc1b..2e06f4e 100644 (file)
@@ -1,17 +1,8 @@
+from django.template.loader import render_to_string
+
 from engine.plugin import Plugin
 
 class SimpleList (Plugin) :
     
-    def render_content (self):
-        return """<ul><li>this hard-wired list</li>
-<li>is defined</li>
-<li>in plugins.simplelist.py</li>
-<li>while it should of course</li>
-<li>instead issue a query</li>
-<li>and fill the DOM in js from there</li>
-<li>it would however maybe make sense</li>
-<li>to offer the option to 'datatablify'</li>
-<li>the list from the python code</li>
-<li>just like a standard plugin can be set as visible or not</li>
-<li>IMHO there should be explicit subclasses of SimpleList for slices or testbeds</li>
-</ul>"""
+    def render_content (self, request):
+        return render_to_string ("widget-simplelist.html",{})
diff --git a/static/css/logout.css b/static/css/logout.css
new file mode 100644 (file)
index 0000000..c786996
--- /dev/null
@@ -0,0 +1,5 @@
+a.logout {
+    font-size: 32;
+    margin:20px;
+    background-color: #fac;
+}
index 97e7a0a..28e91bc 100644 (file)
@@ -1 +1,3 @@
-<a href='/logout/confirm/'>Confirm logout</a>
+{% insert_str prelude "css/logout.css" %}
+<p> xxx This needs a bit of ironing out </p>
+<a class='logout' href='/logout/confirm/'>Confirm logout</a>
diff --git a/templates/widget-simplelist.html b/templates/widget-simplelist.html
new file mode 100644 (file)
index 0000000..40ad0c1
--- /dev/null
@@ -0,0 +1,16 @@
+<ul>
+<li>this hard-wired list</li>
+<li>is defined</li>
+<li>in <code>plugins.simplelist.py</code></li>
+<li>which in turn relies on</li>
+<li>template <code>widget-template.html</code></li>
+<li>while it should of course</li>
+<li>instead issue a query</li>
+<li>and fill the DOM in js from there</li>
+<li>it would however maybe make sense</li>
+<li>to offer the option to 'datatablify'</li>
+<li>the list from the python code</li>
+<li>just like a standard plugin can be set as visible or not</li>
+<li />
+<li>OTOH and IMHO, there should be two separate and explicit subclasses of SimpleList for slices or testbeds</li>
+</ul>