Пример #1
0
    def get_section(self,
                    section_identity: SectionIdentity) -> Option[Section]:
        c = self.connection.cursor()
        term = (
            section_identity.course.course_code,
            section_identity.year,
            str(section_identity.semester.value),
            section_identity.section_code,
        )
        c.execute(
            "SELECT * FROM sections WHERE course=%s AND year=%s AND semester=%s AND "
            "section_code=%s",
            term,
        )
        section = None
        res = c.fetchone()
        if res:

            def get_inst(user_name):
                c.execute("SELECT * FROM instructors WHERE user_name=%s",
                          (str(user_name), ))
                res = c.fetchone()
                if res:
                    return Instructor(res[0], res[1], res[3])
                return None

            section = Section(
                Course(res[0]),
                res[1],
                Semester(int(res[2])),
                res[3],
                get_inst(res[4]),
                res[5],
            )
        return maybe(section)
Пример #2
0
    def query_sections(self, filters=None) -> List[Section]:
        c = self.connection.cursor()
        # TODO: filters
        c.execute("SELECT * FROM sections")
        sections = c.fetchall()
        if len(sections) > 0:

            def get_inst(user_name):
                c.execute("SELECT * FROM instructors WHERE user_name=%s",
                          (user_name))
                res = c.fetchone()
                if res:
                    return Instructor(res[0], res[1], res[3])
                return None

            sections = map(
                lambda res: Section(
                    Section(res[0]),
                    res[1],
                    Semester(int(res[2])),
                    res[3],
                    get_inst(res[4]),
                    res[5],
                ),
                sections,
            )
        return list(sections)
Пример #3
0
 def to_section_identity(id):
     params = id.split(";delimiter;")
     return SectionIdentity(
         Course(params[0]), int(params[1]), Semester(int(params[2])), params[3]
     )
Пример #4
0
    def query_sections(self, filters=None) -> List[Section]:
        c = self.connection.cursor()
        if filters is None:
            c.execute("SELECT * FROM sections")
        else:
            terms = []
            where_text = ""
            if "course_code" in filters:
                if where_text == "":
                    where_text += " WHERE"
                else:
                    where_text += " AND"
                where_text += " course=%s"
                terms.append(str(filters["course_code"]))
            if "year" in filters:
                if where_text == "":
                    where_text += " WHERE"
                else:
                    where_text += " AND"
                where_text += " year=%s"
                terms.append(str(filters["year"]))
            if "semester" in filters:
                if where_text == "":
                    where_text += " WHERE"
                else:
                    where_text += " AND"
                where_text += " semester=%s"
                terms.append(str(filters["semester"].value))
            if "section_code" in filters:
                if where_text == "":
                    where_text += " WHERE"
                else:
                    where_text += " AND"
                where_text += " section_code=%s"
                terms.append(filters["section_code"])
            if "taught_by" in filters:
                if where_text == "":
                    where_text += " WHERE"
                else:
                    where_text += " AND"
                where_text += " taught_by=%s"
                terms.append(filters["taught_by"])

            c.execute("SELECT * FROM sections" + where_text, tuple(terms))

        sections = c.fetchall()
        if len(sections) > 0:

            def get_inst(user_name):
                c.execute(f"SELECT * FROM instructors WHERE user_name='{user_name}'")
                res = c.fetchone()
                if res:
                    return Instructor(res[0], res[1], res[3])
                return None

            sections = map(
                lambda res: Section(
                    Course(res[0]),
                    res[1],
                    Semester(int(res[2])),
                    res[3],
                    get_inst(res[4]),
                    res[5],
                ),
                sections,
            )
        return list(sections)