def _checkProposedScheduleValidity(self, proposedStartTS, req=''): proposedStartTS = int(proposedStartTS) logging.info(proposedStartTS) q = GqlQuery( "SELECT * FROM Repair where status=:astatus and isScheduled=:isTrue and scheduleStart<:psTS order by scheduleStart desc", psTS=proposedStartTS, astatus='INCOMPLETE', isTrue=True) isOk = True prevRepair = None for arepair in q.run(limit=1): prevRepair = arepair if proposedStartTS - arepair.scheduleStart < REPAIRSLOTTIME: isOk = False q = GqlQuery( "SELECT * FROM Repair where status=:astatus and isScheduled=:isTrue and scheduleStart>=:psTS order by scheduleStart asc", psTS=proposedStartTS, astatus='INCOMPLETE', isTrue=True) tuples = [] for arepair in q.run(limit=24): tuples.append(arepair) if len(tuples) > 0: if tuples[0].scheduleStart - proposedStartTS < REPAIRSLOTTIME: isOk = False logging.info(len(tuples)) if isOk: return 'OK' for k in range(1, len(tuples)): if tuples[k].scheduleStart - tuples[ k - 1].scheduleStart >= REPAIRSLOTTIME: nextSlot = self._getnextAvailableSlot(tuples[k - 1].scheduleStart) logging.info('in next poo') logging.info(nextSlot) return 'Next available slot is from ' + nextSlot if len(tuples) < 24 and len(tuples) > 0: nextSlot = self._getnextAvailableSlot(tuples[len(tuples) - 1].scheduleStart) logging.info('in next') logging.info(nextSlot) return 'Next available slot is from ' + nextSlot if len(tuples) == 0: nextSlot = self._getnextAvailableSlot(prevRepair.scheduleStart) logging.info('in prev') logging.info(nextSlot) return 'Next available slot is from ' + nextSlot return 'No available slot withing 24 hours from proposed slot'
def get(self, email, id=''): if email != '': q = GqlQuery("SELECT * FROM User where email=:emailid", emailid=email) for auser in q.run(limit=1): return auser return None return User.get_by_key_name(id)
def list(self, lmt=5, ofst=0): users = [] q = GqlQuery("SELECT * FROM User") for auser in q.run(limit=lmt, offset=ofst): users.append(auser) return users
def list(self, lmt=5, ofst=0, assignedTo='', status='', frDt='', frTm='', toDt='', toTm=''): ret = {'hasMore': 0} repairs = [] conditions = '' qry = "SELECT * FROM Repair" toTm = toTm.replace(':', '') if assignedTo != '': conditions = self._addcondition(' assignedTo=:assgnto ', conditions) datedfilterson = False if frDt != '': datedfilterson = True frDt = int(frDt.replace('-', '')) conditions = self._addcondition( ' scheduleDateINT>=:fD and scheduleDateINT!=1', conditions) if toDt != '': datedfilterson = True toDt = int(toDt.replace('-', '')) conditions = self._addcondition( ' scheduleDateINT<=:tD and scheduleDateINT!=1 ', conditions) if frTm != '' and not datedfilterson: frTm = int(frTm.replace(':', '')) conditions = self._addcondition( ' scheduleTimeINT>=:fT and scheduleTimeINT!=0 ', conditions) if toTm != '' and not datedfilterson: toTm = int(toTm.replace(':', '')) conditions = self._addcondition( ' scheduleTimeINT<=:tT and scheduleTimeINT!=0 ', conditions) if status != '' and status != 'ALL': conditions = self._addcondition(' status=:sT', conditions) if conditions != '': qry = qry + ' where ' + conditions logging.info(qry) q = GqlQuery(qry, assgnto=assignedTo, sT=status, fD=frDt, fT=frTm, tD=toDt, tT=toTm) index = 0 for arepair in q.run(limit=lmt + 1, offset=ofst): repairObj = self._tojson(arepair) index += 1 if index < 6: repairs.append(repairObj) ret['repairs'] = repairs if index == 6: ret['hasMore'] = 1 return ret