Work on native gui code
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import MySQLdb.cursors
|
||||
|
||||
class User(object):
|
||||
|
||||
def __init__(self, dbconn, user_id=None):
|
||||
self.conn = dbconn
|
||||
self.cur = dbconn.cursor(MySQLdb.cursors.DictCursor)
|
||||
if user_id:
|
||||
self.user_id = int(user_id)
|
||||
self.load()
|
||||
else:
|
||||
self.login = None
|
||||
self.displayname = None
|
||||
self.language = 'en'
|
||||
self.role = 'undef'
|
||||
self.flags = ''
|
||||
|
||||
def load(self):
|
||||
sql = (
|
||||
"SELECT login, displayname, language, role, flags "
|
||||
"FROM user "
|
||||
"WHERE user_id=%s")
|
||||
self.cur.execute(sql, (self.user_id, ))
|
||||
row = self.cur.fetchone()
|
||||
if row:
|
||||
self.data = row
|
||||
self.login = row['login']
|
||||
self.displayname = row['displayname']
|
||||
self.language = row['language']
|
||||
self.role = row['role']
|
||||
self.flags = row['flags']
|
||||
else:
|
||||
self.data = None
|
||||
|
||||
def save(self):
|
||||
"""
|
||||
Speichern eines Benutzers ist momentan nicht vorgesehen
|
||||
"""
|
||||
pass
|
||||
|
||||
""" unused at the moment
|
||||
def mark_login(self):
|
||||
sql = "UPDATE user SET last_login=NOW() WHERE username=%s"
|
||||
self.cur.execute(sql, (self.username, ))
|
||||
self.conn.commit()
|
||||
|
||||
def mark_logout(self):
|
||||
sql = "UPDATE user SET last_logout=NOW() WHERE username=%s"
|
||||
self.cur.execute(sql, (self.username, ))
|
||||
self.conn.commit()
|
||||
"""
|
||||
|
||||
def __repr__(self):
|
||||
# Unique description
|
||||
out = "User(%d)" % self.user_id
|
||||
return out
|
||||
|
||||
def __str__(self):
|
||||
# Prettyprint
|
||||
out = "User(%d) - %s\n" % (self.user_id, self.displayname)
|
||||
out += " F: %s\n" % self.flags
|
||||
out += " R: %s\n" % self.role
|
||||
out += " L: %s\n" % self.language
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user