# 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
from auth.backend import MyCustomBackend
+from myslice.viewutils import the_user
+
def login_user(request):
state = "Please log in below..."
username = password = ''
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 ?
# 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
# 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
return result
+ ### abstract interface
+ def render_content (self, request):
+ """Should return an HTML fragment"""
+ return "Your plugin needs to redefine 'render_content(self, request)'"
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
{ '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)
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="""
+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",{})
--- /dev/null
+a.logout {
+ font-size: 32;
+ margin:20px;
+ background-color: #fac;
+}
-<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>
--- /dev/null
+<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>