How to use the nbgrader.utils.parse_utc function in nbgrader

To help you get started, we’ve selected a few nbgrader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyter / nbgrader / nbgrader / api.py View on Github external
additional keyword arguments for :class:`~nbgrader.api.SubmittedAssignment`

        Returns
        -------
        submission : :class:`~nbgrader.api.SubmittedAssignment`

        """

        try:
            submission = self.find_submission(assignment, student)
        except MissingEntry:
            submission = self.add_submission(assignment, student, **kwargs)
        else:
            for attr in kwargs:
                if attr == 'timestamp':
                    setattr(submission, attr, utils.parse_utc(kwargs[attr]))
                else:
                    setattr(submission, attr, kwargs[attr])
            try:
                self.db.commit()
            except (IntegrityError, FlushError) as e:
                self.db.rollback()
                raise InvalidEntry(*e.args)

        return submission
github jupyter / nbgrader / nbgrader / api.py View on Github external
"""Add a new assignment to the gradebook.

        Parameters
        ----------
        name : string
            the unique name of the new assignment
        `**kwargs`
            additional keyword arguments for the :class:`~nbgrader.api.Assignment` object

        Returns
        -------
        assignment : :class:`~nbgrader.api.Assignment`

        """
        if 'duedate' in kwargs:
            kwargs['duedate'] = utils.parse_utc(kwargs['duedate'])
        assignment = Assignment(name=name, **kwargs)
        self.db.add(assignment)
        try:
            self.db.commit()
        except (IntegrityError, FlushError) as e:
            self.db.rollback()
            raise InvalidEntry(*e.args)
        return assignment
github jupyter / nbgrader / nbgrader / exchange / default / collect.py View on Github external
def _path_to_record(self, path):
        filename = os.path.split(path)[1]
        # Only split twice on +, giving three components. This allows usernames with +.
        filename_list = filename.rsplit('+', 3)
        if len(filename_list) < 3:
            self.fail("Invalid filename: {}".format(filename))
        username = filename_list[0]
        timestamp = parse_utc(filename_list[2])
        return {'username': username, 'filename': filename, 'timestamp': timestamp}
github jupyter / nbgrader / nbgrader / api.py View on Github external
additional keyword arguments for the :class:`~nbgrader.api.Assignment` object

        Returns
        -------
        assignment : :class:`~nbgrader.api.Assignment`

        """

        try:
            assignment = self.find_assignment(name)
        except MissingEntry:
            assignment = self.add_assignment(name, **kwargs)
        else:
            for attr in kwargs:
                if attr == 'duedate':
                    setattr(assignment, attr, utils.parse_utc(kwargs[attr]))
                else:
                    setattr(assignment, attr, kwargs[attr])
            try:
                self.db.commit()
            except (IntegrityError, FlushError) as e:
                self.db.rollback()
                raise InvalidEntry(*e.args)

        return assignment
github jupyter / nbgrader / nbgrader / apps / zipcollectapp.py View on Github external
"Invalid submission notebook name '{}'".format(submission))

            submitted_path = self.coursedir.format_path(
                self.coursedir.submitted_directory, info['student_id'], self.coursedir.assignment_id)
            dest_path = os.path.join(submitted_path, submission)

            timestamp = None
            if 'timestamp' in info.keys():
                timestamp = info['timestamp']

            if isinstance(timestamp, str):
                if not timestamp:
                    self.log.warning("Empty timestamp string provided.")
                    timestamp = None
                try:
                    timestamp = parse_utc(timestamp)
                except ValueError:
                    self.fail(
                        "Invalid timestamp string: {}".format(timestamp))

            student_id = info['student_id']

            # new student id record
            if student_id not in data.keys():
                data[student_id] = dict(
                    src_files=[_file],
                    dest_files=[dest_path],
                    file_ids=[submission],
                    timestamp=timestamp,
                )

            # existing student id record, new submission file
github jupyter / nbgrader / nbgrader / api.py View on Github external
----------
        assignment : string
            the name of an existing assignment
        student : string
            the name of an existing student
        `**kwargs`
            additional keyword arguments for :class:`~nbgrader.api.SubmittedAssignment`

        Returns
        -------
        submission : :class:`~nbgrader.api.SubmittedAssignment`

        """

        if 'timestamp' in kwargs:
            kwargs['timestamp'] = utils.parse_utc(kwargs['timestamp'])

        try:
            submission = SubmittedAssignment(
                assignment=self.find_assignment(assignment),
                student=self.find_student(student),
                **kwargs)

            for notebook in submission.assignment.notebooks:
                nb = SubmittedNotebook(notebook=notebook, assignment=submission)

                for grade_cell in notebook.grade_cells:
                    Grade(cell=grade_cell, notebook=nb)

                for solution_cell in notebook.solution_cells:
                    Comment(cell=solution_cell, notebook=nb)