I have added a new function User() to Karrigell 4.3.6. With this
function one can get the name of the user who is currently logged in. I
use this to know who makes modification in the data of the web site.
Here are my modifications :
1) Add the folowing to SQLiteUsersDb class in admin_db.py
def get_user(self,**kw):
"""Return the role of user with session key skey"""
conn = sqlite3.connect(self.path)
cursor = conn.cursor()
args = []
for key in kw.keys():
value = kw[key]
if key=='password':
_hash = hashlib.md5()
_hash.update(value.encode('utf-8'))
value = _hash.digest()
args.append(value)
clause = ' AND '.join(key+'=?' for key in kw.keys())
cursor.execute('SELECT login FROM users WHERE '+clause,args)
result = cursor.fetchall()
if not result:
return None
else:
return result[0][0]
2) Add the following to RequestHandle class in Karrigell.py :
def user(self):
if self.users_db is None:
return None
if not self.skey_cookie in self.cookies:
return False
skey = self.cookies[self.skey_cookie].value
return self.users_db.get_user(skey=skey)
3) Add the following to self.namespace dict in run() method in
RequestHandler class (Karrigell.py) :
'User':self.user,
That's it.
Please add this to Karrigell 4.3.7 (after a check of course).
Cordialement,
Nicolas
I have recently discovered Nagare (www.nagare.org), another french web
framework. The programming model is very interesting but the management
of the whole thing is complicated. Just for curiosity, I suggest you
take a look at it. And, who knows, maybe it will give you good ideas for
Karrigell...
Cordialement,
Nicolas
>
> Cordialement,
> Pierre
> Nicolas,
>
> I know Nagare a little because the author, Alain Poirier, lives in
> Rennes like me, we've met a couple of times. The concept of
> "continuation" is interesting but as you say it's not easy to
> understand at first. He has the same approach as Karrigell for HTML :
> building a DOM with built-in classes (he uses<< where HTMLTags uses
> <= ), without a templating system
Cool !
So it will be easier for you to merge both frameworks to get best of both ;)
>
> The author of Nagare works for a local company, Net-ng, so the
> framework is used in production for many sites
I've tried it. This is why I know, it is complex to set up.
I like some of the concepts of Nagare. I don't like it's complexity.
Nicolas
>
> A+
> Pierre