Skip to content

Commit

Permalink
Add markdown option for assignment descriptions (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 authored May 8, 2024
1 parent a4edf32 commit a732091
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 52 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ requests = "~=2.31"
psutil = "~=5.9"
celery = "~=5.3.5" # Celery v5.4 may stop supporting Python 3.8
django-celery-results = "~=2.5"
django-markdownify = "~=0.9" # includes the markdown package
psycopg = "~=3.1"
virtualenv = "~=20.26"
redis = "~=5.0"
Expand Down
137 changes: 97 additions & 40 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tin/apps/assignments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Meta:
fields = [
"name",
"description",
"markdown",
"folder",
"language",
"filename",
Expand All @@ -44,6 +45,7 @@ class Meta:
"submission_limit_cooldown",
]
labels = {
"markdown": "Use markdown?",
"venv": "Virtual environment",
"hidden": "Hide assignment from students?",
"enable_grader_timeout": "Set a timeout for the grader?",
Expand All @@ -59,6 +61,7 @@ class Meta:
"filename": "Clarify which file students need to upload (including the file "
"extension). For Java assignments, this also sets the name of the "
"saved submission file.",
"markdown": "This allows adding images, code blocks, or hyperlinks to the assignment description.",
"venv": "If set, Tin will run the student's code in this virtual environment.",
"grader_has_network_access": 'If unset, this effectively disables "Give submissions '
'internet access" below. If set, it increases the amount '
Expand Down
18 changes: 18 additions & 0 deletions tin/apps/assignments/migrations/0029_assignment_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-05-05 00:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("assignments", "0028_assignment_venv"),
]

operations = [
migrations.AddField(
model_name="assignment",
name="markdown",
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions tin/apps/assignments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Assignment(models.Model):
related_name="assignments",
)
description = models.CharField(max_length=4096)
markdown = models.BooleanField(default=False)

LANGUAGES = (
("P", "Python 3"),
Expand Down
36 changes: 36 additions & 0 deletions tin/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"django_extensions",
"django_celery_results",
"debug_toolbar",
"markdownify.apps.MarkdownifyConfig",
"tin.apps",
"tin.apps.users",
"tin.apps.auth",
Expand Down Expand Up @@ -236,6 +237,41 @@
CELERY_BROKER_URL = "redis://localhost:6379/1"


# Markdown
MARKDOWNIFY = {
"default": {
"MARKDOWN_EXTENSIONS": [
"fenced_code",
],
"WHITELIST_ATTRS": ["class", "href", "src", "alt"],
"WHITELIST_TAGS": [
"a",
"abbr",
"acronym",
"b",
"blockquote",
"code",
"em",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"i",
"img",
"li",
"ol",
"p",
"pre",
"span",
"strong",
"ul",
],
}
}


# Django debug toolbar settings

_enabled_panels = {
Expand Down
2 changes: 1 addition & 1 deletion tin/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ body {
text-align: right;
}

ul:not(.standard) {
ul.no-list {
list-style-type: none;
padding-left: 0px;
}
Expand Down
7 changes: 6 additions & 1 deletion tin/templates/assignments/show.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load static %}
{% load markdownify %}

{% block title %}
Turn-In: {{ course.name }}: {% if assignment.is_quiz %}[QUIZ] {% endif %}{{ assignment.name }}
Expand Down Expand Up @@ -50,7 +51,11 @@ <h2 class="left">{% if assignment.is_quiz %}[QUIZ] {% endif %}{{ assignment.name
<a class="right tin-btn" href="{% url 'assignments:submit' assignment.id %}">Submit</a>
{% endif %}
</div>
{{ assignment.description | linebreaks }}
{% if assignment.markdown %}
{{ assignment.description | markdownify }}
{% else %}
{{ assignment.description | linebreaks }}
{% endif %}

<table id="assignment-info">
<tr>
Expand Down
2 changes: 1 addition & 1 deletion tin/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<body>

<div id="nav">
<ul>
<ul class="no-list">
<li><a href="{% url 'auth:index' %}"><h1><span class="logo"></span>Turn-In</h1></a></li>
{% if request.user.is_authenticated %}
{% if course %}
Expand Down
Loading

0 comments on commit a732091

Please sign in to comment.