Source code for lib_openmolar.client.db_orm.client_staff_members
#! /usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
## ##
## Copyright 2010, Neil Wallace <rowinggolfer@googlemail.com> ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
###############################################################################
'''
gets records from the staff table
'''
from PyQt4 import QtCore, QtGui, QtSql, QtSvg
[docs]class StaffObject(QtSql.QSqlRecord):
[docs] def __init__(self, record):
QtSql.QSqlRecord.__init__(self, record)
self._avatar = None
@property
[docs] def full_name(self):
return u"%s %s"% (self.value("first_name").toString(),
self.value("last_name").toString())
@property
[docs] def qualifications(self):
return self.value("qualifications").toString()
@property
[docs] def role(self):
return self.value("role").toString()
@property
[docs] def toHtml(self):
return '''<html><body>%s %s <br />%s</body</html>'''% (
self.full_name, self.qualifications, self.role)
[docs]class StaffMembers(list):
[docs] def __init__(self):
self.get_records()
[docs] def get_records(self):
query = '''SELECT staff.ix, first_name, last_name, qualifications,
role, abbrv_name, svg_data
from staff left join avatars on avatar_id = avatars.ix'''
q_query = QtSql.QSqlQuery(query, SETTINGS.psql_conn)
while q_query.next():
record = q_query.record()
practitioner = StaffObject(record)
self.append(practitioner)
if __name__ == "__main__":
from lib_openmolar.client.connect import DemoClientConnection
cc = DemoClientConnection()
cc.connect()
staff_members = StaffMembers(cc)
for member in staff_members:
print member.toHtml()