Ejemplo n.º 1
0
    def list_submissions(self, assignment, **kwargs):
        """
        Get all existing submissions for an assignment.

        .. warning::
            .. deprecated:: 0.9.0
                Use :func:`canvasapi.assignment.Assignment.get_submissions` instead.

        :calls: `GET /api/v1/sections/:section_id/assignments/:assignment_id/submissions  \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.index>`_

        :param assignment: The object or ID of the assignment.
        :type assignment: :class:`canvasapi.assignment.Assignment` or int

        :rtype: :class:`canvasapi.paginated_list.PaginatedList` of
            :class:`canvasapi.submission.Submission`
        """
        from canvasapi.assignment import Assignment

        warnings.warn(
            'Section.list_submissions() is deprecated and will be removed '
            'in the future. Use Assignment.get_submissions() instead.',
            DeprecationWarning
        )

        assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
        assignment = Assignment(self._requester, {
            'course_id': self.course_id,
            'section_id': self.id,
            'id': assignment_id
        })

        return assignment.get_submissions(**kwargs)
Ejemplo n.º 2
0
    def get_submission(self, assignment, user, **kwargs):
        """
        Get a single submission, based on user id.

        .. warning::
            .. deprecated:: 0.9.0
                Use :func:`canvasapi.assignment.Assignment.get_submission` instead.

        :calls: `GET /api/v1/sections/:section_id/assignments/:assignment_id/submissions/:user_id \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.show>`_

        :param assignment: The object or ID of the assignment.
        :type assignment: :class:`canvasapi.assignment.Assignment` or int
        :param user: The object or ID of the user.
        :type user: :class:`canvasapi.user.User` or int or str

        :rtype: :class:`canvasapi.submission.Submission`
        """
        from canvasapi.assignment import Assignment

        warnings.warn(
            'Section.get_submission() is deprecated and will be removed '
            'in the future. Use Assignment.get_submission() instead.',
            DeprecationWarning
        )

        assignment_id = obj_or_id(assignment, "assignment", (Assignment,))

        assignment = Assignment(self._requester, {
            'course_id': self.course_id,
            'section_id': self.id,
            'id': assignment_id
        })

        return assignment.get_submission(user, **kwargs)
Ejemplo n.º 3
0
    def submit_assignment(self, assignment, submission, **kwargs):
        """
        Makes a submission for an assignment.

        .. warning::
            .. deprecated:: 0.9.0
                Use :func:`canvasapi.assignment.Assignment.submit` instead.

        :calls: `POST /api/v1/sections/:section_id/assignments/:assignment_id/submissions \
        <https://canvas.instructure.com/doc/api/submissions.html#method.submissions.create>`_

        :param assignment: The object or ID of the assignment.
        :type assignment: :class:`canvasapi.assignment.Assignment` or int
        :param submission: The attributes of the submission.
        :type submission: dict

        :rtype: :class:`canvasapi.submission.Submission`
        """
        from canvasapi.assignment import Assignment

        warnings.warn(
            'Section.submit_assignment() is deprecated and will be removed '
            'in the future. Use Assignment.submit() instead.',
            DeprecationWarning
        )

        assignment_id = obj_or_id(assignment, "assignment", (Assignment,))
        assignment = Assignment(self._requester, {
            'course_id': self.course_id,
            'section_id': self.id,
            'id': assignment_id
        })
        return assignment.submit(submission, **kwargs)
Ejemplo n.º 4
0
def load_submissions(assignment: Assignment,
                     submissions: List[Dict]) -> List[Submission]:
    """
    Load a list of submissions for an assignment via the Canvas API.

    Parameters
    ----------
    assignment: Assignment
        An Assignment SDK object
    submissions: List[Dict]
        A list of JSON-like submission object in a form suitable for submission to the
        Canvas submission creation endpoint.

    Returns
    -------
    List[Submission]
        A list of Canvas SDK Submission objects representing the created submissions
    """
    logger.info("Creating %s submissions via Canvas API", len(submissions))

    result: List[Submission] = []
    for submission in submissions:
        result.append(assignment.submit(submission))

    logger.info("Successfully created %s submissions", len(submissions))

    return result
Ejemplo n.º 5
0
    def create_assignment(self, assignment, **kwargs):
        """
        Create a new assignment for this course.

        Note: The assignment is created in the active state.

        :calls: `POST /api/v1/courses/:course_id/assignments \
        <https://canvas.instructure.com/doc/api/assignments.html#method.assignments_api.create>`_

        :param assignment: The attributes of the assignment
        :type assignment: dict
        :rtype: :class:`canvasapi.assignment.Assignment`
        """
        from canvasapi.assignment import Assignment

        if isinstance(assignment, dict) and 'name' in assignment:
            kwargs['assignment'] = assignment
        else:
            raise RequiredFieldMissing(
                "Dictionary with key 'name' is required.")

        response = self._requester.request(
            'POST', 'courses/%s/assignments' % (self.id),
            **combine_kwargs(**kwargs))

        return Assignment(self._requester, response.json())
def submit_assignment(assignment: Assignment):
    """Submit the supplied assignment

    :param assignment: assignment to be submitted
    :return: nothing return
    """
    # Begin submissions
    repo = Repo(".")
    logging.info("Repo Untracked Files: ")
    logging.info(repo.untracked_files)
    url = "https://github.com/devfulcrum/{}/commit/{}".format(
        os.path.basename(repo.working_dir), repo.head.commit.hexsha)
    # url = repo.remotes.origin.url[:-4] + "/commit/{}".format(
    #     repo.head.commit.hexsha
    # )  # you MUST push to the classroom org, even if CI/CD runs
    # elsewhere (you can push anytime before peer review begins)
    assignment.submit(
        dict(
            submission_type="online_url",
            url=url,
        ),
        comment=dict(text_comment=json.dumps(get_submission_comments(repo))),
    )
Ejemplo n.º 7
0
    def get_assignment(self, assignment_id, **kwargs):
        """
        Return the assignment with the given ID.

        :calls: `GET /api/v1/courses/:course_id/assignments/:id \
        <https://canvas.instructure.com/doc/api/assignments.html#method.assignments_api.show>`_

        :param assignment_id: The ID of the assignment to retrieve.
        :type assignment_id: int
        :rtype: :class:`canvasapi.assignment.Assignment`
        """
        from canvasapi.assignment import Assignment

        response = self._requester.request(
            'GET', 'courses/%s/assignments/%s' % (self.id, assignment_id),
            **combine_kwargs(**kwargs))
        return Assignment(self._requester, response.json())
 def bulk_update(self, assignment: Assignment):
     assignment.submissions_bulk_update(
         grade_data=self.grade_book[assignment.id])
     return
FILE = "submission.zip"
### Everything below is unlikely to change

# Canvas API URL
API_URL = "https://canvas.upenn.edu/api/v1/"
# Canvas API key
API_KEY = config.API_KEY
#596 course id
COURSE_ID = 1488863

# Initialize a new Requester
requester = Requester(API_URL, API_KEY)

# Make an Assignment for this course and this assignment
assignment = Assignment(requester, {
    'course_id': COURSE_ID,
    'id': ASSIGNMENT_ID
})
# print(assignment.to_json())

#if you go into the plain REST api, you'll see the python library is combining two steps:
#   1) upload a file named whatever you named yours
#   2) submit the assignment using the id of canvas id for the uploaded file in 1
response = assignment.submit({
    'submission_type': 'online_upload',
}, filename)

print(response)
print("\n\n\nNothing eventful happened but you should always check the site")
canvas_page = "https://canvas.upenn.edu/courses/" + str(
    COURSE_ID) + "/assignments/" + str(ASSIGNMENT_ID)
print("Please check your submission at: \n" + canvas_page)