Beispiel #1
0
 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
Beispiel #3
0
 def getAllConvs(self):
     session = makeSession()
     res = session.query(Conv).options(
         joinedload(Conv.participants).joinedload(
             Participant.userObj)).all()
     session.close()
     return res
Beispiel #4
0
 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
Beispiel #6
0
 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
Beispiel #9
0
 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
Beispiel #10
0
 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
Beispiel #11
0
 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
Beispiel #12
0
 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
Beispiel #13
0
 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
Beispiel #14
0
 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
Beispiel #15
0
 def getParticipantsForConv(self,convId):
     session=makeSession()
     participantsInConversation=session.query(Participant).options(joinedload(Participant.userObj)).filter(Participant.conv==convId).all()
     session.close()
     return participantsInConversation
Beispiel #16
0
 def getAllUsers(self):
     session = makeSession()
     allUsers = session.query(User).all()
     session.close()
     return allUsers
Beispiel #17
0
 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
Beispiel #18
0
 def getUserByEmail(self, email):
     session = makeSession()
     users = session.query(User).filter(User.email == email).first()
     session.close()
     return users
Beispiel #19
0
 def getUserById(self, id):
     session = makeSession()
     user = session.query(User).filter(User.id == id).first()
     session.close()
     return user
Beispiel #20
0
 def getAllUsersNoAdmin(self):
     session = makeSession()
     allUsers = session.query(User).filter(User.admin == False).all()
     session.close()
     return allUsers