diff --git a/dojo_plugin/models/__init__.py b/dojo_plugin/models/__init__.py index dea746680..8cf200c1e 100644 --- a/dojo_plugin/models/__init__.py +++ b/dojo_plugin/models/__init__.py @@ -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)] diff --git a/dojo_plugin/pages/dojo.py b/dojo_plugin/pages/dojo.py index aeb97249f..5129150d7 100644 --- a/dojo_plugin/pages/dojo.py +++ b/dojo_plugin/pages/dojo.py @@ -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__) @@ -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, @@ -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, ) diff --git a/dojo_theme/static/css/custom.css b/dojo_theme/static/css/custom.css index 9e9edbe61..a531ee4fa 100644 --- a/dojo_theme/static/css/custom.css +++ b/dojo_theme/static/css/custom.css @@ -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; +} + diff --git a/dojo_theme/templates/module.html b/dojo_theme/templates/module.html index f2acc3062..786b0de10 100644 --- a/dojo_theme/templates/module.html +++ b/dojo_theme/templates/module.html @@ -7,6 +7,12 @@

{{ module.name }}


{{ dojo.name }}

+ {% if due_info.checkpoint and due_info.checkpoint.show %} +

Checkpoint due in {{due_info.checkpoint.delta.days}} days {{due_info.checkpoint.delta.seconds//3600}} hours

+ {% endif %} + {% if due_info.due and due_info.due.show %} +

Module due in {{due_info.due.delta.days}} days {{due_info.due.delta.seconds//3600}} hours

+ {% endif %}