~homeworkprod/orgatalk-lanpartydb-tools

585d35b38ae78fa45b33837348584e7ce6bd7c9e — Jochen Kupperschmidt 24 days ago 6dc9947 main
Update lanpartydb to v0.6.0 (from v0.5.0)

`serialize_party()` is now provided by the library.
M converter/pyproject.toml => converter/pyproject.toml +1 -2
@@ 6,10 6,9 @@ authors = [
    { name = "Jochen Kupperschmidt", email = "homework@nwsnet.de" }
]
dependencies = [
    "lanpartydb>=0.5.0",
    "lanpartydb>=0.6.0",
    "pydantic>=2.7.4",
    "pydantic-xml>=2.11.0",
    "tomlkit>=0.12.3",
]
readme = "README.md"
requires-python = ">= 3.11"

M converter/requirements-dev.lock => converter/requirements-dev.lock +3 -3
@@ 11,7 11,7 @@
-e file:.
annotated-types==0.6.0
    # via pydantic
lanpartydb==0.5.0
lanpartydb==0.6.0
    # via lanpartydb-converter
pydantic==2.7.4
    # via lanpartydb-converter


@@ 21,8 21,8 @@ pydantic-core==2.18.4
    # via pydantic-xml
pydantic-xml==2.11.0
    # via lanpartydb-converter
tomlkit==0.12.3
    # via lanpartydb-converter
tomlkit==0.12.5
    # via lanpartydb
typing-extensions==4.9.0
    # via pydantic
    # via pydantic-core

M converter/requirements.lock => converter/requirements.lock +3 -3
@@ 11,7 11,7 @@
-e file:.
annotated-types==0.6.0
    # via pydantic
lanpartydb==0.5.0
lanpartydb==0.6.0
    # via lanpartydb-converter
pydantic==2.7.4
    # via lanpartydb-converter


@@ 21,8 21,8 @@ pydantic-core==2.18.4
    # via pydantic-xml
pydantic-xml==2.11.0
    # via lanpartydb-converter
tomlkit==0.12.3
    # via lanpartydb-converter
tomlkit==0.12.5
    # via lanpartydb
typing-extensions==4.9.0
    # via pydantic
    # via pydantic-core

M converter/src/lanpartydb_converter/exporter.py => converter/src/lanpartydb_converter/exporter.py +1 -26
@@ 8,13 8,11 @@ Data exporter
:License: MIT
"""

import dataclasses
from datetime import date
from pathlib import Path
from typing import Any

from lanpartydb.models import Party
import tomlkit
from lanpartydb.writing import serialize_party


def export_parties(parties: list[Party], output_path: Path) -> Path:


@@ 39,26 37,3 @@ def export_party(party: Party, output_path: Path) -> Path:
    filename = output_path / f'{party.slug}.toml'
    content = serialize_party(party)
    filename.write_text(content)


def serialize_party(party: Party) -> str:
    """Serialize party to TOML document."""
    party_dict = _party_to_sparse_dict(party)
    return tomlkit.dumps(party_dict)


def _party_to_sparse_dict(party: Party) -> dict[str, Any]:
    data = dataclasses.asdict(party)
    _remove_default_values(data)
    return data


def _remove_default_values(d: dict[str, Any]) -> dict[str, Any]:
    """Remove `None` values from first level of dictionary."""
    for k, v in list(d.items()):
        if (v is None) or (v is False):
            del d[k]
        elif isinstance(v, dict):
            _remove_default_values(v)

    return d