Skip to content

comicbox.readinglists.schema ¶

The comicbox reading-list model: key constants and schemas.

A reading list is a header plus entries, and an entry is a comic reference in comicbox’s own vocabulary: its series, volume, issue, date and identifiers are the comicbox sub-schemas, so an entry is a valid fragment of a comicbox comic.

The value passed around the API is the inner mapping, the one under reading_list. Only serialized documents carry the root key.

EntryDateSchema ¶

Bases: _EntryDateFieldsSchema

An entry’s dates: comicbox’s, but whole or not at all.

Source code in comicbox/readinglists/schema.py
178
179
180
181
182
class EntryDateSchema(_EntryDateFieldsSchema):
    """An entry's dates: comicbox's, but whole or not at all."""

    cover_date = FullDateField(serialize_to_str=False)
    store_date = FullDateField(serialize_to_str=False)

EntrySchema ¶

Bases: IdentifiedSchema

One issue in a reading list.

Source code in comicbox/readinglists/schema.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
class EntrySchema(IdentifiedSchema):
    """One issue in a reading list."""

    TAG_ORDER = (
        SERIES_KEY,
        VOLUME_KEY,
        ISSUE_KEY,
        DATE_KEY,
        IDENTIFIERS_KEY,
        ENTRY_TYPE_KEY,
        NOTES_KEY,
    )

    # Declared as ComicboxSubSchemaMixin declares them: a plain name or
    # number is read as its object, and the read's warnings say so. Writes
    # are always the object, as the JSON Schema has them.
    series = SimpleNamedNestedField(schema=SeriesSchema)
    volume = SimpleNamedNestedField(
        schema=VolumeSchema,
        field=IntegerField(minimum=0),
        name_key=NUMBER_KEY,
    )
    issue = Nested(IssueSchema)
    date = Nested(EntryDateSchema)
    entry_type = EntryTypeField()
    notes = StringField()

EntryTypeField ¶

Bases: VocabularyField

An entry’s role in the list: prologue, core, tie-in, epilogue…

Source code in comicbox/readinglists/schema.py
139
140
141
142
class EntryTypeField(VocabularyField):
    """An entry's role in the list: prologue, core, tie-in, epilogue..."""

    SYNONYMS = MappingProxyType({"tiein": "tie-in", "oneshot": "one-shot"})

FullDateField ¶

Bases: DateField

A whole date, read as a comic’s date is: 2006-07-15, July 15, 2006.

A string that names no day is not one: _partial_dates reads its year and month before the field sees it, and a reading list never guesses a day. It is always written as ISO YYYY-MM-DD.

Source code in comicbox/readinglists/schema.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
class FullDateField(DateField):
    """
    A whole date, read as a comic's date is: ``2006-07-15``, ``July 15, 2006``.

    A string that names no day is not one: ``_partial_dates`` reads its year
    and month before the field sees it, and a reading list never guesses a
    day. It is always written as ISO ``YYYY-MM-DD``.
    """

    @override
    def _deserialize(self, value: Any, *args: Any, **kwargs: Any) -> date:
        if isinstance(value, datetime):
            return value.date()
        if isinstance(value, date):
            return value
        if (
            isinstance(value, str)
            and (parts := date_parts(value.strip())) is not None
            and parts.whole
        ):
            return date(parts.year, parts.month, parts.day)  # pyright: ignore[reportArgumentType], # ty: ignore[invalid-argument-type]
        reason = "Not a whole date."
        raise ValidationError(reason)

JsonEntryDateSchema ¶

Bases: _EntryDateFieldsSchema

An entry’s dates, written as strings for JSON.

Source code in comicbox/readinglists/schema.py
185
186
187
188
189
class JsonEntryDateSchema(_EntryDateFieldsSchema):
    """An entry's dates, written as strings for JSON."""

    cover_date = FullDateField()
    store_date = FullDateField()

JsonEntrySchema ¶

Bases: EntrySchema

An entry with its dates serialized as strings for JSON.

Source code in comicbox/readinglists/schema.py
250
251
252
253
class JsonEntrySchema(EntrySchema):
    """An entry with its dates serialized as strings for JSON."""

    date = Nested(JsonEntryDateSchema)

ListRefSchema ¶

Bases: BaseSubSchema

A reference to another list, such as the one before this in an order.

Source code in comicbox/readinglists/schema.py
212
213
214
215
216
217
218
219
class ListRefSchema(BaseSubSchema):
    """A reference to another list, such as the one before this in an order."""

    TAG_ORDER = (NAME_KEY, SOURCE_KIND_KEY, SOURCE_KEY_KEY)

    name = StringField()
    kind = StringField()
    key = StringField()

ListTypeField ¶

Bases: VocabularyField

A list’s type: event, story, characters, teams, master, creator…

Source code in comicbox/readinglists/schema.py
132
133
134
135
136
class ListTypeField(VocabularyField):
    """A list's type: event, story, characters, teams, master, creator..."""

    # Metron's plural spellings win.
    SYNONYMS = MappingProxyType({"character": "characters", "team": "teams"})

ReadingListJsonSchema ¶

Bases: JsonSchema

A reading list serialized as JSON.

Source code in comicbox/readinglists/schema.py
314
315
316
317
318
319
320
321
322
class ReadingListJsonSchema(JsonSchema):
    """A reading list serialized as JSON."""

    ROOT_TAG = READING_LIST_KEY
    ROOT_KEYPATH = READING_LIST_KEY
    TAG_ORDER = (READING_LIST_KEY, "schema")

    reading_list = Nested(ReadingListJsonSubSchema)
    schema = Constant(READING_LIST_SCHEMA_ID)

ReadingListJsonSubSchema ¶

Bases: ReadingListSubSchema

The list, with entry dates serialized as strings for JSON.

Source code in comicbox/readinglists/schema.py
292
293
294
295
class ReadingListJsonSubSchema(ReadingListSubSchema):
    """The list, with entry dates serialized as strings for JSON."""

    entries = ListField(Nested(JsonEntrySchema), sort=False)

ReadingListSubSchema ¶

Bases: BaseSubSchema

The list: a header, then its entries in reading order.

Source code in comicbox/readinglists/schema.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
class ReadingListSubSchema(BaseSubSchema):
    """The list: a header, then its entries in reading order."""

    TAG_ORDER = (
        NAME_KEY,
        DESCRIPTION_KEY,
        LIST_TYPE_KEY,
        ORDERED_KEY,
        START_YEAR_KEY,
        END_YEAR_KEY,
        PRIVATE_KEY,
        SOURCES_KEY,
        PREVIOUS_KEY,
        NEXT_KEY,
        TAGS_KEY,
        NOTES_KEY,
        ENTRIES_KEY,
    )

    name = StringField()
    description = StringField()
    list_type = ListTypeField()
    ordered = BooleanField()
    start_year = IntegerField()
    end_year = IntegerField()
    private = BooleanField()
    # Never sorted: sorting also de-duplicates, which would lose the rank
    # order of sources, the reading order of entries and any repeated issue.
    sources = ListField(Nested(SourceSchema), sort=False)
    previous = Nested(ListRefSchema)
    next = Nested(ListRefSchema)
    tags = StringSetField()
    notes = StringField()
    entries = ListField(Nested(EntrySchema), sort=False)

ReadingListYamlSchema ¶

Bases: YamlSchema

A reading list serialized as YAML. Also the in-memory model.

Source code in comicbox/readinglists/schema.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
class ReadingListYamlSchema(YamlSchema):
    """A reading list serialized as YAML. Also the in-memory model."""

    ROOT_TAG = READING_LIST_KEY
    ROOT_KEYPATH = READING_LIST_KEY

    reading_list = Nested(ReadingListSubSchema)

    class Meta(YamlSchema.Meta):
        """Schema options."""

        # Comicbox's YAML, written without aliases: reading lists refuse
        # them on read.
        render_module = YamlRenderModule

Meta ¶

Bases: Meta

Schema options.

Source code in comicbox/readinglists/schema.py
306
307
308
309
310
311
class Meta(YamlSchema.Meta):
    """Schema options."""

    # Comicbox's YAML, written without aliases: reading lists refuse
    # them on read.
    render_module = YamlRenderModule

SourceKind ¶

Bases: StrEnum

Where a list came from: the vocabulary of a source’s kind.

A source with a key and no revision is a pointer: the list is known to exist there and was not fetched from it.

Source code in comicbox/readinglists/schema.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
class SourceKind(StrEnum):
    """
    Where a list came from: the vocabulary of a source's ``kind``.

    A source with a ``key`` and no ``revision`` is a pointer: the list is
    known to exist there and was not fetched from it.
    """

    METRON_LIST = "metron-list"
    METRON_ARC = "metron-arc"
    COMICVINE_ARC = "comicvine-arc"
    # Keyed by the json-cbl file's UUID.
    JSON_CBL = "json-cbl"
    CATALOG = "catalog"
    URL = "url"
    FILE = "file"
    TAGS = "tags"

SourceSchema ¶

Bases: BaseSubSchema

One place a list came from.

Source code in comicbox/readinglists/schema.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
class SourceSchema(BaseSubSchema):
    """One place a list came from."""

    TAG_ORDER = (
        SOURCE_KIND_KEY,
        SOURCE_KEY_KEY,
        SOURCE_URL_KEY,
        SOURCE_REVISION_KEY,
        SOURCE_CURATOR_KEY,
        SOURCE_CURATOR_URL_KEY,
    )

    kind = StringField()
    key = StringField()
    url = StringField()
    revision = StringField()
    curator = StringField()
    curator_url = StringField()

VocabularyField ¶

Bases: StringField

A free string from a loose vocabulary.

Lowercased, with runs of spaces and underscores made single hyphens, then known synonyms mapped to one spelling. Unknown values pass through: Metron, mokkari and json-cbl disagree on these vocabularies, so none of them can be a closed enum.

Source code in comicbox/readinglists/schema.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
class VocabularyField(StringField):
    """
    A free string from a loose vocabulary.

    Lowercased, with runs of spaces and underscores made single hyphens,
    then known synonyms mapped to one spelling. Unknown values pass through:
    Metron, mokkari and json-cbl disagree on these vocabularies, so none of
    them can be a closed enum.
    """

    SYNONYMS: MappingProxyType[str, str] = MappingProxyType({})

    @override
    def _deserialize(self, value: Any, *args: Any, **kwargs: Any) -> str:
        value = super()._deserialize(value, *args, **kwargs)
        value = "-".join(value.lower().replace("_", " ").split())
        return self.SYNONYMS.get(value, value)