def getConvById(self, id): session = makeSession() res = session.query(Conv).options( joinedload(Conv.participants).joinedload( Participant.userObj)).filter(Conv.id == id).first() session.close() return res
def modParticipant(self,participant): session=makeSession() crrParticipant=session.query(Participant).filter(Participant.user==participant.user).filter(Participant.conv==participant.conv).first() if(not crrParticipant): return False check=True if(crrParticipant): crrParticipant.recieved=participant.recieved crrParticipant.seen=participant.seen crrParticipant.active=participant.active else: check=False try: session.commit() except Exception as e: session.rollback() session.flush() check=False finally: session.refresh(crrParticipant) session.close() if(check): return crrParticipant else: return None
def getAllConvs(self): session = makeSession() res = session.query(Conv).options( joinedload(Conv.participants).joinedload( Participant.userObj)).all() session.close() return res
def findUserByNameNoAdmin(self, name): session = makeSession() user = session.query(User).filter( User.name.like('%' + name + '%')).filter(User.admin == False).all() session.close() return user
def delParticipant(self,participant): session=makeSession() session.delete(participant) check=True try: session.commit() except Exception as e: session.rollback() session.flush() check=False finally: session.close() if(check): return True else: return None
def delConv(self, conv): session = makeSession() session.delete(conv) check = True try: session.commit() except Exception as e: session.rollback() session.flush() check = False finally: session.close() if (check): return True else: return None
def addParticipant(self,participant): session=makeSession() session.add(participant) check=True try: session.commit() except Exception as e: session.rollback() session.flush() check=False finally: session.refresh(participant) session.close() if(check): return participant else: return None
def delParticipantsFromConv(self,convId): session=makeSession() participants=session.query(Participant).filter(Participant.conv==convId).all() for participant in participants: session.delete(participant) check=True try: session.commit() except Exception as e: session.rollback() session.flush() check=False finally: session.close() if(check): return True else: return None
def addConv(self, conv): session = makeSession() session.add(conv) session.flush() session.refresh(conv) check = True try: session.commit() except Exception as e: session.rollback() session.flush() check = False finally: session.refresh(conv) session.close() if (check): return conv else: return None
def addUser(self, user): session = makeSession() session.add(user) session.flush() session.refresh(user) check = True try: session.commit() except Exception as e: session.rollback() session.flush() check = False finally: session.refresh(user) session.close() if (check): return user else: return None
def addParticipantsToConv(self,convId,participants): session=makeSession() for participant in participants: participant.conv=convId session.add(participant) check=True try: session.commit() except Exception as e: session.rollback() session.flush() check=False finally: for participant in participants: session.refresh(participant) session.close() if(check): return participants else: return None
def modConv(self, conv): session = makeSession() crrConv = session.query(Conv).filter(Conv.id == conv.id).first() check = True if (crrConv): crrConv.name = conv.name crrConv.msgs = conv.msgs else: check = False try: session.commit() except Exception as e: session.rollback() session.flush() check = False finally: session.refresh(crrConv) session.close() if (check): return crrConv else: return None
def modUser(self, user): session = makeSession() crrUser = session.query(User).filter(User.id == user.id).first() check = True if (crrUser): crrUser.name = user.name crrUser.email = user.email crrUser.admin = user.admin crrUser.passwd = user.passwd else: check = False try: session.commit() except Exception as e: session.rollback() session.flush() check = False finally: session.refresh(crrUser) session.close() if (check): return crrUser else: return None
def getConvsByUserId(self, id): session = makeSession() res = session.query(Conv).join(Conv.participants).filter( Participant.user == id).join(Participant.userObj).all() session.close() return res
def getParticipantsForConv(self,convId): session=makeSession() participantsInConversation=session.query(Participant).options(joinedload(Participant.userObj)).filter(Participant.conv==convId).all() session.close() return participantsInConversation
def getAllUsers(self): session = makeSession() allUsers = session.query(User).all() session.close() return allUsers
def getOneParticipantForConv(self,convId,userId): session=makeSession() participant=session.query(Participant).options(joinedload(Participant.userObj)).filter(Participant.user==userId).filter(Participant.conv==convId).first() session.close() return participant
def getUserByEmail(self, email): session = makeSession() users = session.query(User).filter(User.email == email).first() session.close() return users
def getUserById(self, id): session = makeSession() user = session.query(User).filter(User.id == id).first() session.close() return user
def getAllUsersNoAdmin(self): session = makeSession() allUsers = session.query(User).filter(User.admin == False).all() session.close() return allUsers