import traceback from geruecht.exceptions import DatabaseExecption class Base: def getJobInvite(self, from_user, to_user, date, id=None): try: cursor = self.db.connection.cursor() if id: cursor.execute("select * from job_invites where id={}".format(id)) else: cursor.execute("select * from job_invites where from_user={} and to_user={} and on_date='{}'".format(from_user['id'], to_user['id'], date)) retVal = cursor.fetchone() retVal['to_user'] = self.getUserById(retVal['to_user']).toJSON() retVal['from_user'] = self.getUserById(retVal['from_user']).toJSON() retVal['on_date'] = {'year': retVal['on_date'].year, 'month': retVal['on_date'].month, 'day': retVal['on_date'].day} return retVal except Exception as err: traceback.print_exc() self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def getJobInvitesFromUser(self, from_user, date): try: cursor = self.db.connection.cursor() cursor.execute("select * from job_invites where from_user={} and on_date>='{}'".format(from_user['id'], date)) retVal = cursor.fetchall() for item in retVal: item['from_user'] = from_user item['to_user'] = self.getUserById(item['to_user']).toJSON() item['on_date'] = {'year': item['on_date'].year, 'month': item['on_date'].month, 'day': item['on_date'].day} return retVal except Exception as err: traceback.print_exc() self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def getJobInvitesToUser(self, to_user, date): try: cursor = self.db.connection.cursor() cursor.execute("select * from job_invites where to_user={} and on_date>='{}'".format(to_user['id'], date)) retVal = cursor.fetchall() for item in retVal: item['from_user'] = self.getUserById(item['from_user']).toJSON() item['to_user'] = to_user item['on_date'] = {'year': item['on_date'].year, 'month': item['on_date'].month, 'day': item['on_date'].day} return retVal except Exception as err: traceback.print_exc() self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def setJobInvite(self, from_user, to_user, date): try: cursor = self.db.connection.cursor() cursor.execute("insert into job_invites (from_user, to_user, on_date) values ({}, {}, '{}')".format(from_user['id'], to_user['id'], date)) self.db.connection.commit() return self.getJobInvite(from_user, to_user, date) except Exception as err: traceback.print_exc() self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def updateJobInvite(self, jobinvite): try: cursor = self.db.connection.cursor() cursor.execute("update job_invites set watched={} where id={}".format(jobinvite['watched'], jobinvite['id'])) self.db.connection.commit() return self.getJobInvite(None, None, None, jobinvite['id']) except Exception as err: traceback.print_exc() self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) def deleteJobInvite(self, jobinvite): try: cursor = self.db.connection.cursor() cursor.execute("delete from job_invites where id={}".format(jobinvite['id'])) self.db.connection.commit() except Exception as err: traceback.print_exc() self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))