From c6b9205db7bd29e842d3261304baadf144479fd0 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Sun, 29 Oct 2017 20:55:38 +0100 Subject: [PATCH] Add side card for the self-paced courses Helps with: https://github.com/pyvec/naucse.python.cz/issues/255 --- naucse/routes.py | 22 +++++++ naucse/static/css/nausce.css | 4 ++ naucse/templates/course.html | 123 +++++++++++++++++++++++++---------- 3 files changed, 113 insertions(+), 36 deletions(-) diff --git a/naucse/routes.py b/naucse/routes.py index b7a175dadf..6c19fbebad 100644 --- a/naucse/routes.py +++ b/naucse/routes.py @@ -117,6 +117,27 @@ def course(course): def lesson_url(lesson, *args, **kwargs): return url_for('course_page', course=course, lesson=lesson, *args, **kwargs) + recent_runs = [] + if not course.start_date: + # Build a list of "recent" runs based on this course. + # By recent we mean: haven't ended yet, or ended up to ~2 months ago + # (Note: even if naucse is hosted dynamically, + # it's still beneficial to show recently ended runs.) + today = datetime.date.today() + cutoff = today - datetime.timedelta(days=2*30) + this_year = today.year + for year, run_year in reversed(course.root.run_years.items()): + for run in run_year.runs.values(): + if run.base_course is course and run.end_date > cutoff: + recent_runs.append(run) + if year < this_year: + # Assume no run lasts for more than a year, + # e.g. if it's Jan 2018, some run that started in 2017 may + # be included, but don't even look through runs from 2016 + # or earlier. + break + recent_runs.sort(key=lambda r: r.start_date, reverse=True) + try: return render_template( 'course.html', @@ -124,6 +145,7 @@ def lesson_url(lesson, *args, **kwargs): plan=course.sessions, title=course.title, lesson_url=lesson_url, + recent_runs=recent_runs, **vars_functions(course.vars), edit_path=course.edit_path) except TemplateNotFound: diff --git a/naucse/static/css/nausce.css b/naucse/static/css/nausce.css index 29a3d47d69..c03f610f08 100644 --- a/naucse/static/css/nausce.css +++ b/naucse/static/css/nausce.css @@ -114,6 +114,10 @@ a:hover { margin-bottom: 1rem; } +.course-card .recent-runs li { + margin-top: 1em; +} + /*************************/ pre { diff --git a/naucse/templates/course.html b/naucse/templates/course.html index 50bab5751b..09948c7943 100644 --- a/naucse/templates/course.html +++ b/naucse/templates/course.html @@ -28,45 +28,16 @@
- {% if course.start_date %} -
-
- {% if course.vars['coach-present'] %} - Kurz s instruktorem - {% else %} - Termín kurzu - {% endif %} -
-
-
- {{ (course.start_date, course.end_date) | format_date_range }} -
-
- -
- {% endif %} - -

{{ course.title }}

+
+
+

{{ course.title }}

- {% if course.subtitle is defined and course.subtitle != None %} -

{{ course.subtitle }}

- {% endif%} + {% if course.subtitle is defined and course.subtitle != None %} +

{{ course.subtitle }}

+ {% endif%} - {{ course.long_description | markdown }} + {{ course.long_description | markdown }} -
-
{% for session in plan.values() %}

@@ -85,8 +56,88 @@

{% endfor %}

{% endfor %} + +
+
+ {% if course.start_date %} +
+
+ Toto jsou podklady pro kurz s instruktorem +
+
+
+ {{ (course.start_date, course.end_date) | format_date_range }} +
+
+ +
+ {% else %} +
+
+ Toto jsou materiály pro samouky +
+
+

+ Doufáme, že naše materiály jsou srozumitelné a přínosné. + Pokud ne, ozvěte se prosím: +

+ +

+ Případné nejasnosti rádi vysvětlíme, + ale musíme o nich vědět! +

+
+ {% if recent_runs %} + + {% endif %} +
+ {% endif %}
+