Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
fix(pydantic): change deprecated class-based configs to dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
zyv committed Dec 1, 2023
1 parent 0e553da commit d1f87d0
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions sepacetamol/views/datev.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.shortcuts import render
from django.utils.encoding import smart_str
from openpyxl.reader.excel import load_workbook
from pydantic import BaseModel, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field, field_validator


def float_to_german(value: float) -> str:
Expand All @@ -29,18 +29,22 @@ def date_to_datev(d: date) -> str:
return d.strftime("%Y%m%d")


DEFAULT_CONFIG = ConfigDict(
populate_by_name=True,
validate_default=True,
validate_assignment=True,
frozen=True,
)


PositiveInt = Annotated[int, Field(gt=0)]


class DatevSettings(BaseModel):
consultant_number: PositiveInt
client_numer: PositiveInt

class Config:
populate_by_name = True
validate_default = True
validate_assignment = True
frozen = True
model_config = DEFAULT_CONFIG


class DatevModel(BaseModel):
Expand All @@ -50,11 +54,12 @@ def model_dump_csv(self) -> str:
datev_writer.writerow(self.model_dump().values())
return "\n".join(unquote_empty_csv_strings(line) for line in output.getvalue().splitlines())

class Config:
populate_by_name = True
validate_default = True
validate_assignment = True
frozen = True
model_config = ConfigDict(
populate_by_name=True,
validate_default=True,
validate_assignment=True,
frozen=True,
)


class DatevHeader(DatevModel):
Expand Down

0 comments on commit d1f87d0

Please sign in to comment.