Skip to content

Commit

Permalink
✨ Add extra_info to calendar for plugins to use
Browse files Browse the repository at this point in the history
  • Loading branch information
jorrick committed Aug 31, 2024
1 parent 1b435ec commit 35c2dd6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion duty_board/alchemy/update_duty_calendars.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,13 +12,15 @@

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
calendar_db_instance.category = calendar.category # type: ignore[assignment]
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(
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion duty_board/models/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion duty_board/plugin/helpers/duty_calendar_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Dict, Optional, Union

from pydantic import BaseModel, Field
from typing_extensions import Annotated
Expand All @@ -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]]]

0 comments on commit 35c2dd6

Please sign in to comment.