Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit a368700

Browse files
committed
Initial support for viewing attachments when grading
1 parent 02dd938 commit a368700

File tree

8 files changed

+124
-13
lines changed

8 files changed

+124
-13
lines changed

controllers/admin.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
# Third Party library
2424
# -------------------
25+
import boto3, botocore
2526
from dateutil.parser import parse
2627
from rs_grading import _get_assignment, send_lti_grades
2728
from runestone import cmap
@@ -1618,7 +1619,38 @@ def htmlsrc():
16181619
htmlsrc and htmlsrc[0:2] == "\\x"
16191620
): # Workaround Python3/Python2 SQLAlchemy/DAL incompatibility with text columns
16201621
htmlsrc = htmlsrc.decode("hex")
1621-
return json.dumps(htmlsrc)
1622+
1623+
result = {"htmlsrc": htmlsrc}
1624+
logger.debug("htmlsrc = {htmlsrc}")
1625+
if "data-attachment" in htmlsrc:
1626+
# get the URL for the attachment, but we need the course, the user and the divid
1627+
session = boto3.session.Session()
1628+
client = session.client(
1629+
"s3",
1630+
config=botocore.config.Config(s3={"addressing_style": "virtual"}),
1631+
region_name=settings.region,
1632+
endpoint_url="https://nyc3.digitaloceanspaces.com",
1633+
aws_access_key_id=settings.spaces_key,
1634+
aws_secret_access_key=settings.spaces_secret,
1635+
)
1636+
1637+
prepath = f"{auth.user.course_name}/{acid}/{studentId}"
1638+
logger.debug(f"checking path {prepath}")
1639+
response = client.list_objects(Bucket=settings.bucket, Prefix=prepath)
1640+
logger.debug(f"response = {response}")
1641+
if response and "Contents" in response:
1642+
obj = response["Contents"][0]
1643+
logger.debug("key = {obj['Key']}")
1644+
url = client.generate_presigned_url(
1645+
ClientMethod="get_object",
1646+
Params={"Bucket": settings.bucket, "Key": obj["Key"]},
1647+
ExpiresIn=300,
1648+
)
1649+
1650+
else:
1651+
url = ""
1652+
result["attach_url"] = url
1653+
return json.dumps(result)
16221654

16231655

16241656
@auth.requires(

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@ services:
5757
ADS_FILE: '${ADS_FILE}'
5858
QUICK_START: ${QUICK_START}
5959
WORKER_NAME: ${HOSTNAME}
60+
SPACES_KEY: ${SPACES_KEY}
61+
SPACES_SECRET: ${SPACES_SECRET}
6062
links:
6163
- jobe

docker/nginx/sites-available/runestone.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ server {
7777
#
7878
# _`gunicorn socket`: This matches the ``--bind`` parameter when `gunicorn is run <run_bookserver>`.
7979
proxy_pass http://unix:/run/fastapi.sock:/;
80+
# For file uploads we need a larger limit than 1M for whiteboard pictures and pdf uploads
81+
client_max_body_size 25M;
8082
}
8183

8284
location / {

poetry.lock

Lines changed: 75 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

production/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ services:
5151
LOGIN_URL: "/runestone/default/user"
5252
ADS_FILE: '${ADS_FILE}'
5353
WORKER_NAME: ${HOSTNAME}
54+
SPACES_KEY: ${SPACES_KEY}
55+
SPACES_SECRET: ${SPACES_SECRET}
56+
5457

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pretext = "^1.0.0"
6060

6161
# Development dependencies
6262
# ========================
63+
boto3 = "^1.26.30"
6364
[tool.poetry.dev-dependencies]
6465
black = "~= 22.0"
6566
bookserver = { path = "../BookServer", develop = true }

static/js/admin.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ function createGradingPanel(element, acid, studentId, multiGrader) {
355355
}
356356
}
357357
$.getJSON("/runestone/admin/htmlsrc", data, async function (result) {
358-
var htmlsrc = result;
358+
var htmlsrc = result.htmlsrc;
359+
const attachURL = result.attach_url;
359360
var enforceDeadline = $("#enforceDeadline").is(":checked");
360361
var dl = showDeadline();
361362
await renderRunestoneComponent(htmlsrc, elementID + ">#questiondisplay", {
@@ -367,6 +368,7 @@ function createGradingPanel(element, acid, studentId, multiGrader) {
367368
tzoff: new Date().getTimezoneOffset() / 60,
368369
multiGrader: multiGrader,
369370
gradingContainer: elementID,
371+
attachURL: attachURL,
370372
});
371373
});
372374

@@ -1816,14 +1818,17 @@ function create_question(formdata) {
18161818
}
18171819

18181820
// Given a question ID, preview it.
1821+
// This is NOT the function used to generate the grading panel on the grades page
1822+
// this is used in other places.
18191823
function preview_question_id(question_id, preview_div, sid, gradeit) {
18201824
if (arguments.length == 1) {
18211825
preview_div = "component-preview";
18221826
}
18231827
// Request the preview HTML from the server.
18241828
$.getJSON("/runestone/admin/htmlsrc", {
18251829
acid: question_id,
1826-
}).done(function (html_src) {
1830+
}).done(function (jsonData) {
1831+
html_src = jsonData.htmlsrc
18271832
// Render it.
18281833
data = { acid: question_id };
18291834
if (sid) {
@@ -2058,7 +2063,7 @@ async function renderRunestoneComponent(componentSrc, whereDiv, moreOpts) {
20582063
}
20592064
// $(`#${whereDiv}`).css("background-color", "white");
20602065
}
2061-
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
2066+
MathJax.typeset([document.querySelector(`#${whereDiv}`)])
20622067
}
20632068

20642069
// Called by the "Search" button in the "Search question bank" panel.

views/assignments/doAssignment.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ <h5 style='text-align:center;'>Not yet graded</h5>
217217
selfGrade({{=assignment['id']}})
218218
});
219219

220-
$(document).ready(function(){
221-
$('[data-toggle="tooltip"]').tooltip();
222-
});
223-
224220
</script>
225221
<script src="/runestone/static/js/selfgrade.js" type="text/javascript"></script>
226222
<script src="/runestone/static/js/markcomplete.js" type="text/javascript"></script>

0 commit comments

Comments
 (0)