# HG changeset patch # User casties # Date 1372347988 -7200 # Node ID 31b28f369fd348e5ac96fd9dbe3b953c5eb02d41 # Parent 2b27332c95459f8f2b13bc4e53e34b01280c93ee more flexible getMemberList() diff -r 2b27332c9545 -r 31b28f369fd3 MPIWGStaff.py --- a/MPIWGStaff.py Thu Jun 27 16:14:19 2013 +0200 +++ b/MPIWGStaff.py Thu Jun 27 17:46:28 2013 +0200 @@ -99,37 +99,48 @@ return len(res) > 0 - def getMemberList(self, department=None, sortBy='last_name', onlyCurrent=False, arrivedWithin=None, limit=0,withEmail=True): + def getMemberList(self, department=None, sortBy='last_name', onlyCurrent=False, arrivedWithin=None, + onlyPublished=True, onlyWithEmail=True, onlyScholar=True, limit=0): """Return the list of members. Returns a list of MPIWGStaffMember objects. """ members = [] + args = [] + wheres = [] - if withEmail: - query = "select * from personal_www_list where publish_the_data = 'yes' and is_scholar='yes' and e_mail <> '' " - else: - query = "select * from personal_www_list where publish_the_data = 'yes' and is_scholar='yes'" - args = [] - + if onlyPublished: + wheres.append("publish_the_data = 'yes'") + + if onlyWithEmail: + wheres.append("e_mail <> ''") + + if onlyScholar: + wheres.append("is_scholar = 'yes'") + if department is not None: - query += " and department ilike %s" + wheres.append("department ilike %s") args.append('%%%s%%'%department) if onlyCurrent: - query += " and date_from < CURRENT_DATE" + wheres.append("date_from < CURRENT_DATE") if arrivedWithin is not None: - query += " and date_from > CURRENT_DATE - interval %s" + wheres.append("date_from > CURRENT_DATE - interval %s") args.append(arrivedWithin) + + # assemble query + query = "SELECT * FROM personal_www_list" + if len(wheres) > 0: + query += " WHERE " + " AND ".join(wheres) if sortBy == 'last_name': - query += " order by lower(last_name)" + query += " ORDER BY lower(last_name)" elif sortBy == 'date_from': - query += " order by date_from DESC" + query += " ORDER BY date_from DESC" if limit > 0: - query += " limit %s"%int(limit) + query += " LIMIT %s"%int(limit) result = self.executeZSQL(query, args) for res in result: