Exemplo n.º 1
0
 def add(cls, name, pwd):
     id = db.execute(
         'insert into admin_user (name, password, status, create_time) '
         'values (%s, %s, %s, %s)',
         (name, pwd, ADMINUSER_STATUS.CREATED, datetime.now()))
     if id:
         db.commit()
         user = cls.get(id)
         return user
Exemplo n.º 2
0
 def delete(self):
     db.execute('delete from admin_user where id=%s', (self.id, ))
     db.commit()
Exemplo n.º 3
0
 def update(self, name):
     if self.name != name:
         db.execute('update admin_user set name=%s where id=%s',
                    (name, self.id))
         db.commit()
     return self.get(self.id)
Exemplo n.º 4
0
 def get_ids_by_status(cls, status):
     rs = db.execute(
         'select id from admin_user where '
         'status=%s order by create_time '
         'desc', (status, ))
     return [str(r[0]) for r in rs] if rs else []
Exemplo n.º 5
0
 def get_by_name(cls, name):
     r = db.execute(
         'select id, name, password, status, create_time '
         'from admin_user where name=%s', (name, ))
     if r:
         return cls(*r[0])
Exemplo n.º 6
0
 def get(cls, id):
     r = db.execute(
         'select id, name, password, status, create_time '
         'from admin_user where id=%s', (id, ))
     if r:
         return cls(*r[0])