Skip to content

Commit 52a5b4e

Browse files
committed
models: Add Session.serial to the API
1 parent 3845203 commit 52a5b4e

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

naucse/models.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from arca import Task
1111

1212
from naucse.edit_info import get_local_repo_info, get_repo_info
13-
from naucse.converters import Field, register_model, BaseConverter
14-
from naucse.converters import ListConverter, DictConverter
13+
from naucse.converters import Field, VersionField, register_model
14+
from naucse.converters import BaseConverter, ListConverter, DictConverter
1515
from naucse.converters import KeyAttrDictConverter, ModelConverter
1616
from naucse.converters import dump, load, get_converter, get_schema
1717
from naucse import sanitize
@@ -476,6 +476,21 @@ class Session(Model):
476476
DateConverter(), optional=True,
477477
doc="The date when this session occurs (if it has a set time)",
478478
)
479+
serial = VersionField({
480+
(0, 1): Field(
481+
str,
482+
optional=True,
483+
doc="""
484+
Human-readable string identifying the session's position
485+
in the course.
486+
The serial is usually numeric: `1`, `2`, `3`, ...,
487+
but, for example, i, ii, iii... can be used for appendices.
488+
Some courses start numbering sessions from 0.
489+
"""
490+
),
491+
# For API version 0.0, serial is generated in
492+
# Course._sessions_after_load.
493+
})
479494

480495
description = Field(
481496
HTMLFragmentConverter(), optional=True,
@@ -683,6 +698,11 @@ def _sessions_after_load(self, context):
683698
if material.lesson_slug:
684699
self._requested_lessons.add(material.lesson_slug)
685700

701+
if context.version < (0, 1) and len(self.sessions) > 1:
702+
# Assign serials to sessions (numbering from 1)
703+
for serial, session in enumerate(self.sessions.values(), start=1):
704+
session.serial = str(serial)
705+
686706
source_file = source_file_field
687707

688708
start_date = Field(

naucse/templates/course.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ <h2>{{ course.subtitle }}</h2>
2525

2626
<div class="section{{ loop.index }}">
2727
<h4>
28-
{% if course.sessions|length > 1 %}
29-
Lekce {{ loop.index }} –
28+
{% if session.serial != None %}
29+
Lekce {{ session.serial }} –
3030
{% endif %}
3131
<a href="{{ session.get_url() }}">
3232
{{ session.title }}

0 commit comments

Comments
 (0)