Пример #1
0
def home():
    departments = []
    deps = db_session.query(Department.idDepartment, Department.name,
                            func.count(Exam.Department_idDepartment)).join(
                                Department, Exam.department).group_by(
                                    Exam.Department_idDepartment).order_by(
                                        Department.name).all()
    for dep in deps:
        cours = db_session.query(Course.name, func.count(
            Exam.Course_idCourse)).join(Course, Exam.course).filter(
                Course.Department_idDepartment == dep.idDepartment).group_by(
                    Exam.Course_idCourse).order_by(Course.name).all()
        courses = []
        for cour in cours:
            courses.append({'name': cour.name, 'count': cour[1]})
        departments.append({
            'name': dep.name,
            'count': dep[2],
            'courses': courses
        })

    return render_template('index.html',
                           title='Home Page',
                           showing='Dokumente',
                           departments=departments)
Пример #2
0
def getDoc():
    data = request.args
    if data.get("docID"):
        exam = db_session.query(Exam).filter(
            Exam.idExam == data.get("docID")).first()
        if exam:
            filePath = os.path.join(app.config['DOCUMENT_PATH'], exam.filePath)
            if os.path.exists(filePath):
                return send_file(filePath)

    return "<h2>Error 404: File not Found!</h2>"
Пример #3
0
def zip_list(docIDs):
    toZip = db_session.query(
        func.concat(app.config['DOCUMENT_PATH'], Exam.filePath)).filter(
            Exam.idExam.in_(json.loads(docIDs))).all()
    outputFile = os.path.join(app.config['DOCUMENT_PATH'], 'Zips/',
                              'filename' + '.zip')

    zip_file = zipfile.ZipFile(outputFile, 'w')
    with zip_file:
        for file in toZip:
            zip_file.write(file[0])
    return outputFile
Пример #4
0
def getExam():
    data = request.args
    exams_query = db_session.query(Exam)
    has_filter = False
    filter_condition = None
    #filterung
    if data.get("filter[0]"):  #Fachbereich
        exams_query = exams_query.join(Department, Exam.department)
        if not has_filter:
            filter_condition = Department.name.like("%" +
                                                    data.get("filter[0]") +
                                                    "%")
        has_filter = True

    if data.get("filter[1]"):  #Fach
        exams_query = exams_query.join(Course, Exam.course)
        cond = Course.name.like("%" + data.get("filter[1]") + "%")
        if not has_filter:
            filter_condition = cond
        else:
            filter_condition = and_(filter_condition, cond)
        has_filter = True

    if data.get("filter[2]"):  #Typ
        exams_query = exams_query.join(ExamType, Exam.examType)
        cond = ExamType.name.like("%" + data.get("filter[2]") + "%")
        if not has_filter:
            filter_condition = cond
        else:
            filter_condition = and_(filter_condition, cond)
        has_filter = True

    if data.get("filter[3]"):  #Dozent
        exams_query = exams_query.join(Professor, Exam.professor)
        cond = func.concat(
            Professor.firstName, ' ',
            Professor.lastName).like("%" + data.get("filter[3]") + "%")
        if not has_filter:
            filter_condition = cond
        else:
            filter_condition = and_(filter_condition, cond)
        has_filter = True

    if data.get("filter[4]"):  #Semester
        cond = func.concat(Exam.year, ' ',
                           Exam.semester).like("%" + data.get("filter[4]") +
                                               "%")
        if not has_filter:
            filter_condition = cond
        else:
            filter_condition = and_(filter_condition, cond)
        has_filter = True

    if has_filter:
        exams_query = exams_query.filter(filter_condition)

    #sortiertung
    exams_query = sort_exams(exams_query, data)

    #pagination
    page, per_page = pager(data)

    ret = {"total_rows": exams_query.count(), "rows": []}

    for doc in to_serializable_dict(
            Paginator(exams_query, per_page).page(page).object_list):
        ret["rows"].append({
            "Fachbereich":
            doc["department"]["name"],
            "Fach":
            doc["course"]["name"],
            "Typ":
            doc["examType"]["name"],
            "Dozent":
            doc["professor"]["lastName"] + ", " +
            doc["professor"]["firstName"],
            "Semester": ("%d " + doc["semester"]) % doc["year"],
            "ID":
            doc["idExam"]
        })

    return jsonify(ret)