Esempio n. 1
0
def branch_cancel(branch_id, course_id, course_label=None):
    if not mcourses.Courses.exists(course_id):
        abort(404)
    course = mcourses.Courses(course_id)
    cuser = muser.getCurrentUser()
    if course.getLabel() != course_label and request.method != "POST":
        return redirect(
            url_for("branch_submit",
                    branch_id=branch_id,
                    course_id=course_id,
                    course_label=course.getLabel()))
    if not mpull_requests.Branch.exists(branch_id):
        abort(404)
    branch = mpull_requests.Branch(branch_id)

    if branch.getDetail("pull_request") or branch.isAbandoned(): abort(404)

    if request.method == "POST":
        branch.setDetail("abandoned", 1)
        branch.setDetail("abandoned_date", time.time())
        return jsonify({
            "url":
            url_for("course_single_branch",
                    id=branch.id,
                    course_id=course.id,
                    course_label=course.getLabel())
        })
    else:
        return render_template('courses/pull-requests/cancel.html',
                               title="Verwerfen: Branch #" + str(branch.id) +
                               " für " + course.getTitle(),
                               thispage="courses",
                               course=course,
                               branch=branch)
Esempio n. 2
0
def course_single_branch(id, course_id, course_label=None):
    if not mcourses.Courses.exists(course_id):
        abort(404)
    course = mcourses.Courses(course_id)
    cuser = muser.getCurrentUser()
    if course.getLabel() != course_label and request.method != "POST":
        return redirect(
            url_for("course_single_branch",
                    id=id,
                    course_id=course_id,
                    course_label=course.getLabel()))
    if not mpull_requests.Branch.exists(id):
        abort(404)
    branch = mpull_requests.Branch(id)

    if not (branch.getDetail("author") == cuser.id or cuser.isMod(
    )) or cuser.isDisabled() or branch.getDetail("course_id") != course.id:
        abort(404)

    return render_template('courses/pull-requests/branch.html',
                           title="Branch #" + str(branch.id) + " für " +
                           course.getTitle(),
                           thispage="courses",
                           course=course,
                           branch=branch)
Esempio n. 3
0
def branch_revert_override(override_id,
                           branch_id,
                           course_id,
                           course_label=None):
    if not mcourses.Courses.exists(course_id):
        abort(404)
    course = mcourses.Courses(course_id)
    cuser = muser.getCurrentUser()
    if course.getLabel() != course_label and request.method != "POST":
        return redirect(
            url_for("branch_revert_override",
                    branch_id=branch_id,
                    course_id=course_id,
                    course_label=course.getLabel(),
                    override_id=override_id))
    if not mpull_requests.Branch.exists(branch_id):
        abort(404)
    branch = mpull_requests.Branch(branch_id)

    if branch.getDetail("pull_request") or branch.isAbandoned(): abort(404)

    if not (branch.getDetail("author") == cuser.id or cuser.isMod(
    )) or cuser.isDisabled() or branch.getDetail("course_id") != course.id:
        abort(404)

    override = branch.getSingleOverride(override_id)
    if not override or override["branch"] != branch_id:
        abort(404)
    branch.removeOverride(override_id)

    return redirect(
        url_for("course_single_branch",
                id=branch_id,
                course_id=course_id,
                course_label=course.getLabel()))
Esempio n. 4
0
def branch_item(unit_id, override_id, branch_id, course_id, course_label=None):
    if not mcourses.Courses.exists(course_id):
        abort(404)
    course = mcourses.Courses(course_id)
    cuser = muser.getCurrentUser()
    if course.getLabel() != course_label and request.method != "POST":
        return redirect(
            url_for("branch_item",
                    branch_id=branch_id,
                    course_id=course_id,
                    course_label=course.getLabel(),
                    unit_id=unit_id,
                    override_id=override_id))
    if not mpull_requests.Branch.exists(branch_id):
        abort(404)
    branch = mpull_requests.Branch(branch_id)

    if not (branch.getDetail("author") == cuser.id or cuser.isMod(
    )) or cuser.isDisabled() or branch.getDetail("course_id") != course.id:
        abort(404)

    data = _mkdata(unit_id, override_id, course_id, branch)

    if branch.getDetail("pull_request") or branch.isAbandoned():
        return render_template(
            'courses/pull-requests/item.static/' + data["type"] + '.html',
            title="Branch #" + str(branch.id) + " für " + course.getTitle(),
            thispage="courses",
            course=course,
            branch=branch,
            data=data,
            unit_id=unit_id,
            override_id=override_id,
            int=int)
    else:
        return render_template(
            'courses/pull-requests/item/' + data["type"] + '.html',
            title="Branch #" + str(branch.id) + " für " + course.getTitle(),
            thispage="courses",
            course=course,
            branch=branch,
            data=data,
            unit_id=unit_id,
            override_id=override_id)
Esempio n. 5
0
def branch_submit(branch_id, course_id, course_label=None):
    if not mcourses.Courses.exists(course_id):
        abort(404)
    course = mcourses.Courses(course_id)
    cuser = muser.getCurrentUser()
    if course.getLabel() != course_label and request.method != "POST":
        return redirect(
            url_for("branch_submit",
                    branch_id=branch_id,
                    course_id=course_id,
                    course_label=course.getLabel()))
    if not mpull_requests.Branch.exists(branch_id):
        abort(404)
    branch = mpull_requests.Branch(branch_id)

    if branch.getDetail("pull_request") or branch.isAbandoned(): abort(404)

    if request.method == "POST":
        if course.getCourseRole(cuser) < 3:
            branch.calculateRepDelta()
        else:
            branch.setDetail("delta_factor", 0)
        pr = mpull_requests.PullRequest.new(course.id, branch.id, cuser.id,
                                            request.json["title"],
                                            request.json["description"])
        branch.setDetail("pull_request", pr.id)
        return jsonify({
            "url":
            url_for("course_single_pr",
                    id=pr.id,
                    course_id=course.id,
                    course_label=course.getLabel())
        })
    else:
        return render_template('courses/pull-requests/submit.html',
                               title="Neues Pull Request zu Branch #" +
                               str(branch.id) + " für " + course.getTitle(),
                               thispage="courses",
                               course=course,
                               branch=branch)
Esempio n. 6
0
def branch_new_item(branch_id, course_id, course_label=None):
    if not mcourses.Courses.exists(course_id):
        abort(404)
    course = mcourses.Courses(course_id)
    cuser = muser.getCurrentUser()
    if course.getLabel() != course_label and request.method != "POST":
        return redirect(
            url_for("branch_new_item",
                    branch_id=branch_id,
                    course_id=course_id,
                    course_label=course.getLabel()))
    if not mpull_requests.Branch.exists(branch_id):
        abort(404)
    branch = mpull_requests.Branch(branch_id)

    if branch.getDetail("pull_request") or branch.isAbandoned(): abort(404)

    if not (branch.getDetail("author") == cuser.id or cuser.isMod(
    )) or cuser.isDisabled() or branch.getDetail("course_id") != course.id:
        abort(404)

    empty_set = {
        "info": "[]",
        "quiz": "[]",
        "extvideo": '{"platform":"youtube", "embedcode": ""}',
        "syllabus": ''
    }

    x = branch.newUnitOverride("Neue Seite", empty_set[request.json["type"]],
                               request.json["type"])

    return url_for("branch_item",
                   branch_id=branch_id,
                   course_id=course_id,
                   course_label=course.getLabel(),
                   unit_id="-",
                   override_id=x)
Esempio n. 7
0
def branch_update_item(unit_id,
                       override_id,
                       branch_id,
                       course_id,
                       course_label=None):
    if not mcourses.Courses.exists(course_id):
        abort(404)
    course = mcourses.Courses(course_id)
    cuser = muser.getCurrentUser()
    if course.getLabel() != course_label and request.method != "POST":
        return redirect(
            url_for("branch_update_item",
                    branch_id=branch_id,
                    course_id=course_id,
                    course_label=course.getLabel(),
                    unit_id=unit_id,
                    override_id=override_id))
    if not mpull_requests.Branch.exists(branch_id):
        abort(404)
    branch = mpull_requests.Branch(branch_id)

    if branch.getDetail("pull_request") or branch.isAbandoned(): abort(404)

    if not (branch.getDetail("author") == cuser.id or cuser.isMod(
    )) or cuser.isDisabled() or branch.getDetail("course_id") != course.id:
        abort(404)

    data = _mkdata(unit_id, override_id, course_id, branch)

    data["title"] = request.json["title"]
    data["content"] = json.dumps(request.json["content"])

    result = branch.updateOrMakeOverride(unit_id, override_id, data)
    if type(result) == bool: abort(500)

    return jsonify({"override_id": result})
Esempio n. 8
0
def branch_unit_reorder(branch_id, course_id, course_label=None):
    if not mcourses.Courses.exists(course_id):
        abort(404)
    course = mcourses.Courses(course_id)
    cuser = muser.getCurrentUser()
    if course.getLabel() != course_label and request.method != "POST":
        return redirect(
            url_for("branch_unit_reorder",
                    branch_id=branch_id,
                    course_id=course_id,
                    course_label=course.getLabel()))
    if not mpull_requests.Branch.exists(branch_id):
        abort(404)
    branch = mpull_requests.Branch(branch_id)

    if branch.getDetail("pull_request") or branch.isAbandoned(): abort(404)

    if request.method == "POST":
        datar = (request.json)
        for item in datar:
            unit_id, override_id = item["id"].split("/")

            data = _mkdata(unit_id, override_id, course_id, branch)

            unit_id = int(unit_id) if unit_id != "-" else 0
            if data["parent_unit"] != 0 or data["parent_override"] != 0 or data[
                    "unit_order"] != item["order"]:
                data["parent_unit"] = 0
                data["parent_override"] = 0
                data["unit_order"] = item["order"]

                data["content"] = json.dumps(data["content"])
                branch.updateOrMakeOverride(unit_id, override_id, data)

            for subitem in item["subitems"]:
                sub_unit_id, sub_override_id = subitem["id"].split("/")
                data = _mkdata(sub_unit_id, sub_override_id, course_id, branch)

                sub_unit_id = int(sub_unit_id) if sub_unit_id != "-" else 0
                parent_unit, parent_override = unit_id, int(
                    override_id) if override_id != "-" else 0

                if data["parent_unit"] != parent_unit or data[
                        "parent_override"] != parent_override or data[
                            "unit_order"] != subitem["order"]:
                    data["parent_unit"] = parent_unit
                    data["parent_override"] = parent_override
                    data["unit_order"] = subitem["order"]

                    data["content"] = json.dumps(data["content"])
                    branch.updateOrMakeOverride(sub_unit_id, sub_override_id,
                                                data)

        return "ok"
    else:
        return render_template('courses/pull-requests/reorder.html',
                               title="Branch #" + str(branch.id) + " für " +
                               course.getTitle(),
                               thispage="courses",
                               course=course,
                               branch=branch)