def stopVoting(xid): #check number of clients voted #if equal to number of clients who uploaded photo then publish #else just change bring the start voting button back i = 0 for x in xid.split(delimiter): if i == 0: eventName = x i = i+1 elif i == 1: tid = x else: break try: masterUrl = dbMgr.getMaster(eventName) if masterUrl == None: lastTid = getLatestTidLocal (eventName, 0) else: lastTid = srvMgr.getLatestTid (eventName, masterUrl, 0) except KeyError: lastTid = '' x = int (tid) app.logger.debug ('stopVoting : incomingTid ' + tid + ' lastTid ' + str(lastTid)) if lastTid == -1: dbMgr.dontPublishEvent (eventName) x = srvMgr.dontPublishEvent (eventName) eventMgr.allowPublishResult (eventName) return jsonify (success=True) if x != lastTid: return jsonify(success=False) yesLocal = dbMgr.getYesCount(eventName) yesGlobal = srvMgr.getYesCount(eventName) yes = yesLocal + yesGlobal noLocal = dbMgr.getNoCount(eventName) noGlobal = srvMgr.getNoCount (eventName) no = noLocal + noGlobal totalLocal = dbMgr.getMemberCount(eventName) totalGlobal = srvMgr.getMemberCount (eventName) total = totalLocal + totalGlobal msg = 'stopVoting - yes : ' + str(yes) + ' no :' + str(no) + ' total : ' + str(total) app.logger.debug(msg) if (yes + no) < total: dbMgr.dontPublishEvent(eventName) x = srvMgr.dontPublishEvent(eventName) elif no == 0: dbMgr.publishEvent(eventName) x = srvMgr.publishEvent(eventName) else: dbMgr.dontPublishEvent(eventName) x = srvMgr.dontPublishEvent(eventName) #Waiting for all responses before publishing if x == 0 or x == -1: srvMgr.allowPublishResult (eventName) eventMgr.allowPublishResult(eventName) return jsonify(success=True)
def getYesCount (eventName): x = dbMgr.getYesCount (eventName) return jsonify (count = str(x))