示例#1
0
文件: app.py 项目: dlsun/ohms
def download_grades():
    admin = validate_admin()

    homeworks = get_homework()
    categories = session.query(Category).all()
    gradebook, max_scores = get_gradebook()

    csv = '"SUNet","Student","Overall",'
    csv += ','.join(('"' + c.name.replace('"', '""') + ' Total"') for c in categories) + ","
    csv += ','.join(('"' + hw.name.replace('"', '""') + '"') for hw in homeworks) + "\n"

    csv += ',"MAXIMUM",,' + ",".join("" for c in categories) + "," 
    csv += ",".join(str(max_scores[hw.id]) for hw in homeworks) + "\n"
    
    for student, grades in gradebook:
        row = [student.stuid, student.name, str(grades["overall"])]
        for category in categories:
            row.append(str(grades[category.name]))
        for hw in homeworks:
            if hw.id not in grades:
                row.append("")
            else:
                row.append("E" if grades[hw.id].excused else str(grades[hw.id].score))
        csv += ",".join(row) + "\n"
        
    response = make_response(csv)
    course = options.title.replace(" ", "")
    date = datetime.now().strftime("%m-%d-%Y")
    filename = "%sGrades%s.csv" % (course, date)
    response.headers["Content-Disposition"] = "attachment; filename=%s" % filename

    return response
示例#2
0
文件: app.py 项目: dlsun/ohms
def view_responses():
    admin = validate_admin()

    q_id = request.args.get('q')
    responses = get_all_responses_to_question(q_id)

    return render_template("admin/view_responses.html", responses=responses, options=options)
示例#3
0
文件: app.py 项目: flywind2/ohms
def download_peer_reviews():
    admin = validate_admin()

    tasks = session.query(GradingTask).all()
    csv = "grader,student,question,score,comments,rating\n"

    for t in tasks:
        row = []
        for item in [
                t.grader, t.student, t.question_id, t.score, t.comments,
                t.rating
        ]:
            if item is not None:
                row.append('"' + str(item).replace('"', '""') + '"')
            else:
                row.append('""')
        csv += ",".join(row) + "\n"

    response = make_response(csv)
    course = options.title.replace(" ", "")
    filename = "%sPeerAssessments.csv" % course
    response.headers[
        "Content-Disposition"] = "attachment; filename=%s" % filename

    return response
示例#4
0
文件: app.py 项目: flywind2/ohms
def admin():
    admin = validate_admin()

    # change back to admin view
    admin.proxy = admin.stuid
    session.commit()

    homeworks = get_homework()
    categories = session.query(Category).all()

    users = get_users()
    guests = []
    admins = []
    for user in users:
        if user.type == "guest":
            guests.append(user)
        elif user.type == "admin":
            admins.append(user)

    gradebook, max_scores = get_gradebook()

    return render_template("admin/index.html",
                           homeworks=homeworks,
                           guests=guests,
                           admins=admins,
                           categories=categories,
                           gradebook=gradebook,
                           max_scores=max_scores,
                           options=options)
示例#5
0
文件: app.py 项目: flywind2/ohms
def view_responses():
    admin = validate_admin()

    q_id = request.args.get('q')
    responses = get_all_responses_to_question(q_id)

    return render_template("admin/view_responses.html",
                           responses=responses,
                           options=options)
示例#6
0
文件: app.py 项目: flywind2/ohms
def change_user_type():
    admin = validate_admin()

    stuid = request.form['user']
    user_type = request.form['type']

    session.query(User).filter_by(stuid=stuid).update({"type": user_type})
    session.commit()

    return "Successfully changed user %s to %s." % (stuid, user_type)
示例#7
0
文件: app.py 项目: dlsun/ohms
def update_max_score():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    max_score = request.form['max_score'].strip()

    homework = get_homework(hw_id)
    homework.max_score = None if max_score == "" else float(max_score)
    session.commit()

    return "The maximum score for %s has been successfully updated!" % homework.name
示例#8
0
文件: app.py 项目: flywind2/ohms
def update_hw_name():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    hw_name = request.form['hw_name']

    homework = get_homework(hw_id)
    homework.name = hw_name
    session.commit()

    return '''The homework name was successfully updated to "%s"!''' % homework.name
示例#9
0
文件: app.py 项目: dlsun/ohms
def update_hw_name():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    hw_name = request.form['hw_name']

    homework = get_homework(hw_id)
    homework.name = hw_name
    session.commit()

    return '''The homework name was successfully updated to "%s"!''' % homework.name
示例#10
0
文件: app.py 项目: flywind2/ohms
def change_user():
    admin = validate_admin()
    student = request.args['user']

    if not session.query(User).get(student):
        raise Exception("No user exists with the given ID.")

    admin.proxy = student
    session.commit()

    return redirect(url_for('hw_list'))
示例#11
0
文件: app.py 项目: dlsun/ohms
def change_user():
    admin = validate_admin()
    student = request.args['user']

    if not session.query(User).get(student):
        raise Exception("No user exists with the given ID.")

    admin.proxy = student
    session.commit()

    return redirect(url_for('hw_list'))
示例#12
0
文件: app.py 项目: flywind2/ohms
def update_max_score():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    max_score = request.form['max_score'].strip()

    homework = get_homework(hw_id)
    homework.max_score = None if max_score == "" else float(max_score)
    session.commit()

    return "The maximum score for %s has been successfully updated!" % homework.name
示例#13
0
文件: app.py 项目: dlsun/ohms
def change_user_type():
    admin = validate_admin()

    stuid = request.form['user']
    user_type = request.form['type']

    session.query(User).filter_by(stuid=stuid).update({
        "type": user_type
    })
    session.commit()

    return "Successfully changed user %s to %s." % (stuid, user_type)
示例#14
0
文件: app.py 项目: dlsun/ohms
def update_response():
    admin = validate_admin()

    response_id = request.form["response_id"]
    response = get_question_response(response_id)
    score = request.form["score"]
    response.score = float(score) if score else None
    response.comments = request.form["comments"]
    calculate_grade(response.user, response.question.homework)
    session.commit()

    return "Updated score for student %s to %f." % (response.stuid, response.score)
示例#15
0
文件: app.py 项目: flywind2/ohms
def update_question():
    admin = validate_admin()

    q_id = request.form['q_id']
    xml_new = request.form['xml']
    node = ET.fromstring(xml_new)
    node.attrib['id'] = q_id
    question = Question.from_xml(node)
    return json.dumps({
        "xml": question.xml,
        "html": question.to_html(),
    })
示例#16
0
文件: app.py 项目: dlsun/ohms
def update_question():
    admin = validate_admin()
    
    q_id = request.form['q_id']
    xml_new = request.form['xml']
    node = ET.fromstring(xml_new)
    node.attrib['id'] = q_id
    question = Question.from_xml(node)
    return json.dumps({
        "xml": question.xml,
        "html": question.to_html(),
    })
示例#17
0
文件: app.py 项目: flywind2/ohms
def update_due_date():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    start_date = datetime.strptime(request.form['start_date'],
                                   "%m/%d/%Y %H:%M:%S")
    due_date = datetime.strptime(request.form['due_date'], "%m/%d/%Y %H:%M:%S")
    homework = get_homework(hw_id)
    homework.start_date = start_date
    homework.due_date = due_date
    session.commit()

    return "Due date for %s updated successfully!" % homework.name
示例#18
0
文件: app.py 项目: flywind2/ohms
def update_response():
    admin = validate_admin()

    response_id = request.form["response_id"]
    response = get_question_response(response_id)
    score = request.form["score"]
    response.score = float(score) if score else None
    response.comments = request.form["comments"]
    calculate_grade(response.user, response.question.homework)
    session.commit()

    return "Updated score for student %s to %f." % (response.stuid,
                                                    response.score)
示例#19
0
文件: app.py 项目: dlsun/ohms
def update_due_date():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    start_date = datetime.strptime(request.form['start_date'],
                                   "%m/%d/%Y %H:%M:%S")
    due_date = datetime.strptime(request.form['due_date'],
                                 "%m/%d/%Y %H:%M:%S")
    homework = get_homework(hw_id)
    homework.start_date = start_date
    homework.due_date = due_date
    session.commit()

    return "Due date for %s updated successfully!" % homework.name
示例#20
0
文件: app.py 项目: dlsun/ohms
def move_question():
    admin = validate_admin()

    q_id = int(request.form['q_id'])
    hw_id = int(request.form['hw_id'])

    question = get_question(q_id)
    question.hw_id = hw_id if hw_id else None
    session.commit()

    if hw_id:
        return "Question ID %d moved to <a href=hw?id=%d>%s</a>." % (q_id, question.homework.id, question.homework.name)
    else:
        return "Question ID %d has been deleted!" % q_id
示例#21
0
文件: app.py 项目: flywind2/ohms
def move_question():
    admin = validate_admin()

    q_id = int(request.form['q_id'])
    hw_id = int(request.form['hw_id'])

    question = get_question(q_id)
    question.hw_id = hw_id if hw_id else None
    session.commit()

    if hw_id:
        return "Question ID %d moved to <a href=hw?id=%d>%s</a>." % (
            q_id, question.homework.id, question.homework.name)
    else:
        return "Question ID %d has been deleted!" % q_id
示例#22
0
文件: app.py 项目: dlsun/ohms
def add_question():
    admin = validate_admin()

    xml = request.form['xml']
    node = ET.fromstring(xml)

    # remove any ID tags
    for e in node.iter():
        if "id" in e.attrib: e.attrib.pop("id")

    question = Question.from_xml(node)
    question.homework = get_homework(request.form['hw_id'])

    session.commit()

    return "Question added successfully!"
示例#23
0
文件: app.py 项目: dlsun/ohms
def import_homework():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    hw = get_homework(hw_id)

    xml = request.files['xml'].read()
    if not xml:
        return "Empty file uploaded."

    try:
        hw.update_from_xml(xml)
    except:
        return "Invalid XML uploaded"

    return "Homework updated successfully from XML."
示例#24
0
文件: app.py 项目: flywind2/ohms
def add_question():
    admin = validate_admin()

    xml = request.form['xml']
    node = ET.fromstring(xml)

    # remove any ID tags
    for e in node.iter():
        if "id" in e.attrib: e.attrib.pop("id")

    question = Question.from_xml(node)
    question.homework = get_homework(request.form['hw_id'])

    session.commit()

    return "Question added successfully!"
示例#25
0
文件: app.py 项目: flywind2/ohms
def import_homework():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    hw = get_homework(hw_id)

    xml = request.files['xml'].read()
    if not xml:
        return "Empty file uploaded."

    try:
        hw.update_from_xml(xml)
    except:
        return "Invalid XML uploaded"

    return "Homework updated successfully from XML."
示例#26
0
文件: app.py 项目: flywind2/ohms
def export_homework():
    admin = validate_admin()

    hw_id = request.args['id']
    hw = get_homework(hw_id)

    # get XML for questions, wrap in <homework> tags
    xml = "\n\n".join(q.xml for q in hw.questions)
    xml = "<homework>\n" + xml + "\n</homework>"

    # get tree, remove any ID tags, convert back to string
    node = ET.fromstring(xml)
    for e in node.iter():
        if "id" in e.attrib: e.attrib.pop("id")
    xml = ET.tostring(node)

    return Response(xml, content_type='text')
示例#27
0
文件: app.py 项目: flywind2/ohms
def add_homework():
    admin = validate_admin()

    name = request.form['name']
    start_date = datetime.strptime(request.form['start_date'],
                                   "%m/%d/%Y %H:%M:%S")
    due_date = datetime.strptime(request.form['due_date'], "%m/%d/%Y %H:%M:%S")
    category_id = request.form['category_id']

    homework = Homework(name=name,
                        start_date=start_date,
                        due_date=due_date,
                        category_id=category_id)
    session.add(homework)
    session.commit()

    return "%s added successfully!" % name
示例#28
0
文件: app.py 项目: dlsun/ohms
def export_homework():
    admin = validate_admin()

    hw_id = request.args['id']
    hw = get_homework(hw_id)

    # get XML for questions, wrap in <homework> tags
    xml = "\n\n".join(q.xml for q in hw.questions)
    xml = "<homework>\n" + xml + "\n</homework>"

    # get tree, remove any ID tags, convert back to string
    node = ET.fromstring(xml)
    for e in node.iter():
        if "id" in e.attrib: e.attrib.pop("id")
    xml = ET.tostring(node)

    return Response(xml, content_type='text')
示例#29
0
文件: app.py 项目: dlsun/ohms
def add_homework():
    admin = validate_admin()

    name = request.form['name']
    start_date = datetime.strptime(request.form['start_date'],
                                   "%m/%d/%Y %H:%M:%S")
    due_date = datetime.strptime(request.form['due_date'],
                                 "%m/%d/%Y %H:%M:%S")
    category_id = request.form['category_id']

    homework = Homework(name=name,
                        start_date=start_date,
                        due_date=due_date,
                        category_id=category_id)
    session.add(homework)
    session.commit()

    return "%s added successfully!" % name
示例#30
0
文件: app.py 项目: dlsun/ohms
def update_category():
    admin = validate_admin()

    name = request.form['name']
    weight = float(request.form['weight'])
    drops = int(request.form['drops'])

    try:
        category_id = int(request.form['id'])
        category = session.query(Category).get(category_id)
        category.name = name
        category.weight = weight
        category.drops = drops
    except:
        session.add(Category(name=name, weight=weight, drops=drops))

    session.commit()

    return "Category %s successfully added/updated." % name
示例#31
0
文件: app.py 项目: flywind2/ohms
def update_category():
    admin = validate_admin()

    name = request.form['name']
    weight = float(request.form['weight'])
    drops = int(request.form['drops'])

    try:
        category_id = int(request.form['id'])
        category = session.query(Category).get(category_id)
        category.name = name
        category.weight = weight
        category.drops = drops
    except:
        session.add(Category(name=name, weight=weight, drops=drops))

    session.commit()

    return "Category %s successfully added/updated." % name
示例#32
0
文件: app.py 项目: dlsun/ohms
def download_peer_reviews():
    admin = validate_admin()

    tasks = session.query(GradingTask).all()
    csv = "grader,student,question,score,comments,rating\n"

    for t in tasks:
        row = []
        for item in [t.grader, t.student, t.question_id, t.score, t.comments, t.rating]:
            if item is not None:
                row.append('"' + str(item).replace('"', '""') + '"')
            else:
                row.append('""')
        csv += ",".join(row) + "\n"

    response = make_response(csv)
    course = options.title.replace(" ", "")
    filename = "%sPeerAssessments.csv" % course
    response.headers["Content-Disposition"] = "attachment; filename=%s" % filename

    return response
示例#33
0
文件: app.py 项目: dlsun/ohms
def admin():
    admin = validate_admin()

    # change back to admin view
    admin.proxy = admin.stuid
    session.commit()

    homeworks = get_homework()
    categories = session.query(Category).all()

    users = get_users()
    guests = []
    admins = []
    for user in users:
        if user.type == "guest":
            guests.append(user)
        elif user.type == "admin":
            admins.append(user)

    gradebook, max_scores = get_gradebook()
    
    return render_template("admin/index.html", homeworks=homeworks, 
                           guests=guests, admins=admins, categories=categories,
                           gradebook=gradebook, max_scores=max_scores, options=options)
示例#34
0
文件: app.py 项目: dlsun/ohms
def update_grade():
    admin = validate_admin()

    stuid = request.form['stuid']
    hw_id = request.form['hw_id']
    score = request.form['score'].strip()
    excused = 1 if request.form['excused'] == "true" else 0

    # check that score is valid
    try:
        float(score)
    except:
        assert(score in ["", "E"])

    # fill in grades
    grade = get_grade(stuid, hw_id)
    if not grade:
        add_grade(get_user(stuid), get_homework(hw_id), score, excused)
    else:
        grade.score = score
        grade.excused = excused
    session.commit()

    return "Grade update successful!"
示例#35
0
文件: app.py 项目: flywind2/ohms
def update_grade():
    admin = validate_admin()

    stuid = request.form['stuid']
    hw_id = request.form['hw_id']
    score = request.form['score'].strip()
    excused = 1 if request.form['excused'] == "true" else 0

    # check that score is valid
    try:
        float(score)
    except:
        assert (score in ["", "E"])

    # fill in grades
    grade = get_grade(stuid, hw_id)
    if not grade:
        add_grade(get_user(stuid), get_homework(hw_id), score, excused)
    else:
        grade.score = score
        grade.excused = excused
    session.commit()

    return "Grade update successful!"
示例#36
0
文件: app.py 项目: flywind2/ohms
def download_grades():
    admin = validate_admin()

    homeworks = get_homework()
    categories = session.query(Category).all()
    gradebook, max_scores = get_gradebook()

    csv = '"SUNet","Student","Overall",'
    csv += ','.join(('"' + c.name.replace('"', '""') + ' Total"')
                    for c in categories) + ","
    csv += ','.join(
        ('"' + hw.name.replace('"', '""') + '"') for hw in homeworks) + "\n"

    csv += ',"MAXIMUM",,' + ",".join("" for c in categories) + ","
    csv += ",".join(str(max_scores[hw.id]) for hw in homeworks) + "\n"

    for student, grades in gradebook:
        row = [student.stuid, student.name, str(grades["overall"])]
        for category in categories:
            row.append(str(grades[category.name]))
        for hw in homeworks:
            if hw.id not in grades:
                row.append("")
            else:
                row.append(
                    "E" if grades[hw.id].excused else str(grades[hw.id].score))
        csv += ",".join(row) + "\n"

    response = make_response(csv)
    course = options.title.replace(" ", "")
    date = datetime.now().strftime("%m-%d-%Y")
    filename = "%sGrades%s.csv" % (course, date)
    response.headers[
        "Content-Disposition"] = "attachment; filename=%s" % filename

    return response