def get_case_by_id(self, id):
     conn = psycopg2.connect(dbname=self.name,
                             user=self.user,
                             password=self.password,
                             host=self.host)
     with conn.cursor() as cursor:
         conn.autocommit = True
         cursor.execute('SELECT * FROM cases WHERE case_id = %s', (id, ))
         records = cursor.fetchall()
     conn.close()
     if len(records) > 0:
         case = Case(records[0])
         return case
 def get_all_cases(self):
     conn = psycopg2.connect(dbname=self.name,
                             user=self.user,
                             password=self.password,
                             host=self.host)
     records = []
     with conn.cursor() as cursor:
         cursor.execute('SELECT * FROM cases')
         records = cursor.fetchall()
     conn.close()
     cases = []
     if len(records) > 0:
         for rec in records:
             case = Case(rec)
             cases.append(case)
         return cases
 def get_all_cases_waiting_for_appointment(self):
     conn = psycopg2.connect(dbname=self.name,
                             user=self.user,
                             password=self.password,
                             host=self.host)
     records = []
     with conn.cursor() as cursor:
         cursor.execute('SELECT * FROM cases WHERE status = %s',
                        ('ожидает назначения ответственных', ))
         records = cursor.fetchall()
     conn.close()
     cases = []
     if len(records) > 0:
         for rec in records:
             case = Case(rec)
             cases.append(case)
         return cases
 def get_teacher_completed_cases(self, teacher_id):
     conn = psycopg2.connect(dbname=self.name,
                             user=self.user,
                             password=self.password,
                             host=self.host)
     records = []
     with conn.cursor() as cursor:
         cursor.execute(
             'SELECT * FROM cases WHERE (status = %s) AND (t_id = %s) ORDER BY title',
             ('завершено', teacher_id))
         records = cursor.fetchall()
     conn.close()
     cases = []
     if len(records) > 0:
         for rec in records:
             case = Case(rec)
             cases.append(case)
         return cases
 def get_cases_which_need_teacher_editing(self, teacher_id):
     conn = psycopg2.connect(dbname=self.name,
                             user=self.user,
                             password=self.password,
                             host=self.host)
     records = []
     with conn.cursor() as cursor:
         cursor.execute(
             'SELECT * FROM cases WHERE (status = %s OR status = %s) AND (t_id = %s) ORDER BY title',
             ('ожидается проверка правок плана консультации',
              'ожидается проверка правок резолюции', teacher_id))
         records = cursor.fetchall()
     conn.close()
     cases = []
     if len(records) > 0:
         for rec in records:
             case = Case(rec)
             cases.append(case)
         return cases
 def get_cases_by_teacher_id(self, teacher_id):
     conn = psycopg2.connect(dbname=self.name,
                             user=self.user,
                             password=self.password,
                             host=self.host)
     records = []
     with conn.cursor() as cursor:
         conn.autocommit = True
         cursor.execute('SELECT * FROM cases WHERE t_id = %s',
                        (teacher_id, ))
         records = cursor.fetchall()
     conn.close()
     cases = []
     if len(records) > 0:
         for rec in records:
             cs = Case(rec)
             cases.append(cs)
         return cases
     else:
         return None