コード例 #1
0
ファイル: app.py プロジェクト: flywind2/ohms
def grades():
    user = validate_user()

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

    update_hw_grades(user, homeworks)
    session.commit()

    gradebook, max_scores = get_gradebook()

    grades = [entry for entry in gradebook if entry[0] == user]

    if grades:
        grades = grades[0][1]
    else:
        grades = {hw.id: get_grade(user.stuid, hw.id) for hw in homeworks}

    return render_template("grades.html",
                           homeworks=homeworks,
                           grades=grades,
                           max_scores=max_scores,
                           options=options,
                           user=user,
                           categories=categories)
コード例 #2
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)
コード例 #3
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)
コード例 #4
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'))
コード例 #5
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
コード例 #6
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'))
コード例 #7
0
ファイル: app.py プロジェクト: dlsun/ohms
def refresh_grades():
    """
    This updates all students' grades on all homeworks.
    """
    homeworks = get_homework()
    students = get_students()
    for student in students:
        update_hw_grades(student, homeworks)
        print student.name
    session.commit()
    return "Successfully updated all students' grades."
コード例 #8
0
ファイル: app.py プロジェクト: flywind2/ohms
def refresh_grades():
    """
    This updates all students' grades on all homeworks.
    """
    homeworks = get_homework()
    students = get_students()
    for student in students:
        update_hw_grades(student, homeworks)
        print student.name
    session.commit()
    return "Successfully updated all students' grades."
コード例 #9
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
コード例 #10
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
コード例 #11
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
コード例 #12
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)
コード例 #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
def validate_admin():

    stuid, name = auth()

    user = get_user(stuid)
    if not user.type == "admin":
        if user.stuid in options.admins:
            session.query(User).filter_by(stuid=user.stuid).update(
                {"type": "admin"})
            session.commit()
        else:
            raise Exception("You are not authorized to view this page.")
    return user
コード例 #15
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)
コード例 #16
0
ファイル: app.py プロジェクト: dlsun/ohms
def hw_list():
    user = validate_user()
    homeworks = get_homework()
    categories = session.query(Category).all()

    to_do = update_hw_grades(user, homeworks)
    session.commit()

    return render_template("list.html", homeworks=homeworks, categories=categories,
                           user=user,
                           options=options,
                           current_time=pdt_now(),
                           to_do=to_do)
コード例 #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 プロジェクト: 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
コード例 #19
0
ファイル: auth.py プロジェクト: dlsun/ohms
def validate_admin():

    stuid, name = auth()

    user = get_user(stuid)
    if not user.type == "admin":
        if user.stuid in options.admins:
            session.query(User).filter_by(stuid=user.stuid).update({
                "type": "admin"
            })
            session.commit()
        else:
            raise Exception("You are not authorized to view this page.")
    return user
コード例 #20
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
コード例 #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 プロジェクト: flywind2/ohms
def hw_list():
    user = validate_user()
    homeworks = get_homework()
    categories = session.query(Category).all()

    to_do = update_hw_grades(user, homeworks)
    session.commit()

    return render_template("list.html",
                           homeworks=homeworks,
                           categories=categories,
                           user=user,
                           options=options,
                           current_time=pdt_now(),
                           to_do=to_do)
コード例 #23
0
def validate_user():

    stuid, name = auth()

    try:
        user = get_user(stuid)
    except:
        type = "admin" if stuid in options.admins else "student"
        user = User(stuid=stuid, name=name, type=type)
        session.add(user)
        session.commit()

    if user.type == "admin" and user.proxy:
        user = session.query(User).get(user.proxy)

    return user
コード例 #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 プロジェクト: 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!"
コード例 #26
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
コード例 #27
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
コード例 #28
0
ファイル: auth.py プロジェクト: dlsun/ohms
def validate_user():

    stuid, name = auth()

    try:
        user = get_user(stuid)
    except:
        type = "admin" if stuid in options.admins else "student"
        user = User(stuid=stuid,
                    name=name,
                    type=type)
        session.add(user)
        session.commit()

    if user.type == "admin" and user.proxy:
        user = session.query(User).get(user.proxy)

    return user
コード例 #29
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
コード例 #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 プロジェクト: dlsun/ohms
def grades():
    user = validate_user()

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

    update_hw_grades(user, homeworks)
    session.commit()

    gradebook, max_scores = get_gradebook()

    grades = [entry for entry in gradebook if entry[0] == user]

    if grades:
        grades = grades[0][1]
    else:
        grades = {hw.id: get_grade(user.stuid, hw.id) for hw in homeworks}
    
    return render_template("grades.html", homeworks=homeworks, 
                           grades=grades, max_scores=max_scores,
                           options=options, user=user,
                           categories=categories)
コード例 #32
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!"
コード例 #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 プロジェクト: dlsun/ohms
def rate_submit():
    user = validate_user()
    task = get_grading_task(request.form.get('task_id'))
    task.rating = int(request.form.get('rating'))
    session.commit()
    return ""
コード例 #36
0
ファイル: app.py プロジェクト: flywind2/ohms
def rate_submit():
    user = validate_user()
    task = get_grading_task(request.form.get('task_id'))
    task.rating = int(request.form.get('rating'))
    session.commit()
    return ""