Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option for submission history #121

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "canvaslms"
version = "2.23"
version = "3.0"
description = "Command-line interface to Canvas LMS"
authors = ["Daniel Bosk <dbosk@kth.se>"]
license = "MIT"
Expand Down
24 changes: 20 additions & 4 deletions src/canvaslms/cli/submissions.nw
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ submission_parser = subp.add_parser("submission",
"including submission and grading time, any text-based attachments.")
submission_parser.set_defaults(func=submission_command)
add_submission_options(submission_parser)
<<add options for printing a submission>>
@ We also need the corresponding function.
For now, we only print the most relevant data of a submission.
<<functions>>=
Expand All @@ -162,7 +163,7 @@ raw markdown.
<<get and print the submission data>>=
console = rich.console.Console()
for submission in submission_list:
output = format_submission(submission)
output = format_submission(submission, history=args.history)

if sys.stdout.isatty():
<<check if we should use styles>>
Expand All @@ -174,6 +175,16 @@ for submission in submission_list:
@ Note that we use the theme [[manni]] for the code, as this works in both dark
and light terminals.

Now, let's turn to that [[args.history]] argument.
We want to exclude it sometimes, for instance, when we want to get to the
comments only.
So we default to off, since it's only occasionally that we want to see the
history.
<<add options for printing a submission>>=
submission_parser.add_argument("-H", "--history", action="store_true",
help="Include submission history.")
@

\subsection{Check if we should use styles}

By default, [[rich.console.Console]] uses the [[pydoc.pager]], which uses the
Expand Down Expand Up @@ -347,8 +358,12 @@ IDs, instead, we add these as attributes when fetching the objects.
So [[submission.assignment]] is the assignment it came from, we don't need to
resolve the assignment from the assignmend ID.
<<functions>>=
def format_submission(submission):
"""Formats submission for printing to stdout"""
def format_submission(submission, history=False):
"""
Formats submission for printing to stdout. Returns a string.

If history is True, also include submission history.
"""
student = submission.assignment.course.get_user(submission.user_id)

formatted_submission = ""
Expand All @@ -359,7 +374,8 @@ def format_submission(submission):
<<add body to output>>
<<add quiz answers to output>>
<<add attachments to output>>
<<add submission history to output>>
if history:
<<add submission history to output>>

return formatted_submission
@
Expand Down