diff --git a/duty_board/alchemy/update_duty_calendars.py b/duty_board/alchemy/update_duty_calendars.py index 7e09212..ab420e2 100644 --- a/duty_board/alchemy/update_duty_calendars.py +++ b/duty_board/alchemy/update_duty_calendars.py @@ -1,5 +1,6 @@ import datetime -from typing import List +import json +from typing import List, Union from pendulum.tz.timezone import UTC from sqlalchemy import delete, select @@ -11,6 +12,7 @@ def _create_or_update_calendar(session: SASession, calendar: DutyCalendarConfig) -> None: calendar_db_instance = session.scalars(select(Calendar).where(Calendar.uid == calendar.uid)).one_or_none() + extra_info_serialized: Union[None, str] = json.dumps(calendar.extra_info) if calendar.extra_info else None if calendar_db_instance is not None: calendar_db_instance.name = calendar.name calendar_db_instance.description = calendar.description @@ -18,6 +20,7 @@ def _create_or_update_calendar(session: SASession, calendar: DutyCalendarConfig) calendar_db_instance.order = calendar.order calendar_db_instance.icalendar_url = calendar.icalendar_url calendar_db_instance.event_prefix = calendar.event_prefix + calendar_db_instance.extra_info = extra_info_serialized session.merge(calendar_db_instance) else: calendar_db_instance = Calendar( @@ -28,6 +31,7 @@ def _create_or_update_calendar(session: SASession, calendar: DutyCalendarConfig) order=calendar.order, icalendar_url=calendar.icalendar_url, event_prefix=calendar.event_prefix, + extra_info=extra_info_serialized, error_msg=None, last_update_utc=datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=UTC), sync=True, diff --git a/duty_board/models/calendar.py b/duty_board/models/calendar.py index 5a2aead..729ccb2 100644 --- a/duty_board/models/calendar.py +++ b/duty_board/models/calendar.py @@ -20,7 +20,6 @@ class Calendar(Base): order: Mapped[int] icalendar_url: Mapped[str] = mapped_column(String(500), nullable=False) event_prefix: Mapped[Optional[str]] = mapped_column(String(50), nullable=True) - # The `extra_info` can be used to store information that we can use in the plugin. extra_info: Mapped[Optional[str]] = mapped_column(Text, nullable=True) error_msg: Mapped[Optional[str]] = mapped_column( String(9999), diff --git a/duty_board/plugin/helpers/duty_calendar_config.py b/duty_board/plugin/helpers/duty_calendar_config.py index 1d25c59..5fc62f5 100644 --- a/duty_board/plugin/helpers/duty_calendar_config.py +++ b/duty_board/plugin/helpers/duty_calendar_config.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Dict, Optional, Union from pydantic import BaseModel, Field from typing_extensions import Annotated @@ -20,3 +20,5 @@ class DutyCalendarConfig(BaseModel): order: Annotated[int, Field(default=99999, ge=0, le=9999999)] # Prefix before user LDAP or user email is mentioned. Example prefix; 'duty:' when calendar event; 'duty: thomas' event_prefix: Annotated[Optional[str], Field(max_length=50, default=None)] + # The extra_info can be used to store information that we can use in the plugin. + extra_info: Optional[Dict[str, Union[int, float, str]]]