Skip to content

Commit

Permalink
Show the number of days and hours left until a deadline for future de…
Browse files Browse the repository at this point in the history
…adlines for students in the class. Fixes #294
  • Loading branch information
adamdoupe committed Jan 17, 2024
1 parent f0a17ad commit a2e28b7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions dojo_plugin/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ def resources(self, value):
def path(self):
return self.dojo.path / self.id

@property
def assessments(self):
course_assessments = (self.dojo.course or {}).get("assessments", [])
to_return = [assessment for assessment in course_assessments if assessment.get('id', None) == self.id]
return to_return


def visible_challenges(self, user=None):
return [challenge for challenge in self.challenges if challenge.visible() or self.dojo.is_admin(user=user)]

Expand Down
16 changes: 15 additions & 1 deletion dojo_plugin/pages/dojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from ..utils import render_markdown, module_visible, module_challenges_visible, is_dojo_admin
from ..utils.dojo import dojo_route, get_current_dojo_challenge
from ..models import Dojos, DojoUsers
from ..models import Dojos, DojoUsers, DojoStudents

dojo = Blueprint("pwncollege_dojo", __name__)

Expand Down Expand Up @@ -72,7 +72,20 @@ def view_module(dojo, module):
total_solves = dict(module.solves()
.group_by(Solves.challenge_id)
.with_entities(Solves.challenge_id, db.func.count()))

current_dojo_challenge = get_current_dojo_challenge()
requested_types = ['checkpoint', 'due']
due_info = {}
now = datetime.datetime.now().astimezone()
student = DojoStudents.query.filter_by(dojo=dojo, user=user).first()
if (student and student.official) or user.type == 'admin':
assessments = {assessment['type']: assessment for assessment in module.assessments}
for requested in requested_types:
if requested in assessments:
due_date = datetime.datetime.fromisoformat(assessments[requested]['date'])
delta = due_date - now
show = due_date > now
due_info[requested] = dict(due_date=due_date, delta=delta, show=show)
return render_template(
"module.html",
dojo=dojo,
Expand All @@ -81,5 +94,6 @@ def view_module(dojo, module):
user_solves=user_solves,
total_solves=total_solves,
user=user,
due_info=due_info,
current_dojo_challenge=current_dojo_challenge,
)
9 changes: 9 additions & 0 deletions dojo_theme/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,12 @@ hr {
.module-dojo a {
color: #b5e853 !important;
}

.module-checkpoint-due-date, .module-due-date {
font-size: 1.25em;
}

.module-checkpoint-due-date a, .module-due-date a {
color: rgb(234, 234, 234) !important;
}

6 changes: 6 additions & 0 deletions dojo_theme/templates/module.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<h1>{{ module.name }}<h1>
<br>
<h2 class="module-dojo"><a href="{{ url_for("pwncollege_dojos.view_dojo", dojo=dojo.reference_id) }}">{{ dojo.name }}</a></h2>
{% if due_info.checkpoint and due_info.checkpoint.show %}
<h3 class="module-checkpoint-due-date"><a href="https://www.timeanddate.com/worldclock/fixedtime.html?msg={{module.dojo.name }}+{{ module.name }}+Checkpoint+Due&iso={{ due_info.checkpoint.due_date.isoformat() }}">Checkpoint due in {{due_info.checkpoint.delta.days}} days {{due_info.checkpoint.delta.seconds//3600}} hours</a></h3>
{% endif %}
{% if due_info.due and due_info.due.show %}
<h3 class="module-due-date"><a href="https://www.timeanddate.com/worldclock/fixedtime.html?msg={{module.dojo.name }}+{{ module.name }}+Module+Due+Date&iso={{ due_info.due.due_date.isoformat() }}">Module due in {{due_info.due.delta.days}} days {{due_info.due.delta.seconds//3600}} hours</a></h3>
{% endif %}
</div>
</div>
<div class="container">
Expand Down

0 comments on commit a2e28b7

Please sign in to comment.