|
10 | 10 | from arca import Task |
11 | 11 |
|
12 | 12 | 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 |
15 | 15 | from naucse.converters import KeyAttrDictConverter, ModelConverter |
16 | 16 | from naucse.converters import dump, load, get_converter, get_schema |
17 | 17 | from naucse import sanitize |
@@ -476,6 +476,21 @@ class Session(Model): |
476 | 476 | DateConverter(), optional=True, |
477 | 477 | doc="The date when this session occurs (if it has a set time)", |
478 | 478 | ) |
| 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 | + }) |
479 | 494 |
|
480 | 495 | description = Field( |
481 | 496 | HTMLFragmentConverter(), optional=True, |
@@ -683,6 +698,11 @@ def _sessions_after_load(self, context): |
683 | 698 | if material.lesson_slug: |
684 | 699 | self._requested_lessons.add(material.lesson_slug) |
685 | 700 |
|
| 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 | + |
686 | 706 | source_file = source_file_field |
687 | 707 |
|
688 | 708 | start_date = Field( |
|
0 commit comments