Mercurial > avadmin
changeset 567:cbb4f395eb53 cleanup tip
use more python-like syntax
author | Josef "Jeff" Sipek <jeffpc@josefsipek.net> |
---|---|
date | Wed, 25 Oct 2006 02:23:45 -0400 |
parents | fa3f9399cb2b |
children | |
files | av_conn.py av_eq.py av_message.py av_room.py |
diffstat | 4 files changed, 14 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/av_conn.py Tue Oct 24 01:43:00 2006 -0400 +++ b/av_conn.py Wed Oct 25 02:23:45 2006 -0400 @@ -179,14 +179,14 @@ returns bool """ if (num and caps and lower and (not special)): if (self.regexp_Aa0.match(text)): - return 1 + return True if (num and caps and lower and special): if (self.regexp_Aa0s.match(text)): - return 1 + return True if (num and (not caps) and (not lower) and (not special)): if (self.regexp_0.match(text)): - return 1 - return 0 + return True + return False def makeURL(self,page,static=0,usesid=1,params={}): """ Return formated url @@ -200,18 +200,14 @@ url += page if (static): - url = url.replace("$THEME$",self.html.theme) - return url + return url.replace("$THEME$",self.html.theme) url += "?" if (usesid): - url += "sid=" + self.user.getSID() + "&" + params["sid"] = self.user.getSID() - for key in params.keys(): - url += key + "=" + params[key] + "&" - - return url + return url + "&".join(["%s=%s" % (k, v) for k,v in params.items()]) def parse(self,text): """ Changes certain keywords with other values @@ -230,9 +226,7 @@ """ Return yes if value, else return no returns string """ - if (value): - return "Yes" - return "No" + return value and "Yes" or "No" def flush(self): """ Sends all buffered output to the client
--- a/av_eq.py Tue Oct 24 01:43:00 2006 -0400 +++ b/av_eq.py Wed Oct 25 02:23:45 2006 -0400 @@ -115,14 +115,13 @@ res = self.db.execSQL("SELECT `id` FROM `leases` WHERE `enumber`=" + str(self.__ID) + " AND `sdate`<=" + str(self.conn.today()) + " AND `droped`=1 AND `picked`=0;") # FIXME: Error checking required else: res = self.db.execSQL("SELECT `id` FROM `leases` WHERE `enumber`=" + str(self.__ID) + " AND (`doroom`=" + str(room.getID()) + " OR `puroom`=" + str(room.getID()) + ") AND `sdate`<=" + str(self.conn.today()) + " AND `droped`=1 AND `picked`=0;") # FIXME: Error checking required - if (res.__len__() == 0): - return True - return False + + return res.__len__() == 0 def getLoc(self): """ Return tuple """ res = self.db.execSQL("SELECT `doroom`, `puroom` FROM `leases` WHERE `enumber`=" + str(self.__ID) + " AND `sdate`<=" + str(self.conn.today()) + " AND `droped`=1 AND `picked`=0;") # FIXME: Error checking required - return (res[0][0], res[0][1]) # FIXME: ugly looking + return res[0][0:2] def Add(self): """ Adds the variables into the DB, and sets the correct ID on success
--- a/av_message.py Tue Oct 24 01:43:00 2006 -0400 +++ b/av_message.py Wed Oct 25 02:23:45 2006 -0400 @@ -27,9 +27,7 @@ dbid = conn.db.newid() dbid.execute("SELECT count(`id`) AS `count` FROM `messages` WHERE `touser` = " + str(conn.user.getUID()) + " AND `read` = 0;") rec = dbid.fetchone() - if (rec[0]): - return True - return False + return rec[0] and True # otherwise it'd return actual data def totalMessages(conn): """ Returns the number of messages received
--- a/av_room.py Tue Oct 24 01:43:00 2006 -0400 +++ b/av_room.py Wed Oct 25 02:23:45 2006 -0400 @@ -76,9 +76,8 @@ self.__NAME = name def getFullName(self): - if (self.__NAME): - return self.__ROOM + " (" + self.__NAME + ")" - return self.__ROOM + return self.__ROOM + \ + (self.__NAME and "(%s)" % (self.__NAME,) or "") def getNote(self): return self.__NOTE