Exemplo n.º 1
0
def add_job(task, inputdata, debug=False):
    """ Add a job in the queue and returns a submission id.
        task is a Task instance and inputdata is the input as a dictionary
        If debug is true, more debug data will be saved
    """
    if not User.is_logged_in():
        raise Exception("A user must be logged in to submit an object")

    username = User.get_username()
    course = FrontendCourse(task.get_course_id())

    obj = {
        "courseid": task.get_course_id(),
        "taskid": task.get_id(),
        "input": get_gridfs().put(
            json.dumps(inputdata)),
        "status": "waiting",
        "submitted_on": datetime.now()}

    if course.is_group_course() and username not in course.get_staff(True):
        group = get_database().groups.find_one({"course_id": task.get_course_id(), "users": username})
        obj.update({"username": group["users"]})
    else:
        obj.update({"username": [username]})

    submissionid = get_database().submissions.insert(obj)

    PluginManager.get_instance().call_hook("new_submission", submissionid=submissionid, submission=obj, inputdata=inputdata)

    get_job_manager().new_job(task, inputdata, (lambda job: _job_done_callback(submissionid, task, job)), "Frontend - {}".format(username), debug)

    return submissionid
Exemplo n.º 2
0
def get_course_and_check_rights(courseid, taskid=None, allow_all_staff=True):
    """ Returns the course with id ```courseid``` and the task with id ```taskid```, and verify the rights of the user.
        Raise web.notfound() when there is no such course of if the users has not enough rights.

        :param courseid: the course on which to check rights
        :param taskid: If not None, returns also the task with id ```taskid```
        :param allow_all_staff: allow admins AND tutors to see the page. If false, all only admins.
        :returns (Course, Task)
    """

    try:
        if User.is_logged_in():
            course = FrontendCourse(courseid)
            if allow_all_staff:
                if User.get_username() not in course.get_staff():
                    raise web.notfound()
            else:
                if User.get_username() not in course.get_admins():
                    raise web.notfound()

            if taskid is None:
                return (course, None)
            else:
                return (course, course.get_task(taskid))
        else:
            raise web.notfound()
    except:
        raise web.notfound()