New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending the Event class #403
Comments
With the current alpha, you should simply be able to subclass @attr.s(eq=True, order=False) # order methods are provided by Event
class MyEvent(`Event`):
my_property: Optional[str] = attr.ib(default=None) Basically, all |
I managed to get the custom properties out of # Subclass the EventAttrs
@attr.s(eq=True, order=False)
class EventAttrs(ics.event.EventAttrs):
custom_prop: Optional[str] = attr.ib(default=None)
class Event(ics.Event, EventAttrs):
"""A calendar event.
"""
pass
@attr.s
class CalendarAttrs(ics.icalendar.CalendarAttrs):
events: List[Event] = attr.ib(
factory=list, converter=list, metadata={"ics_priority": -100},
)
class Calendar(ics.Calendar, CalendarAttrs):
pass
ics.initialize_converters()
ComponentMeta.BY_TYPE[Event] = ComponentMeta(Event)
ComponentMeta.BY_TYPE[Calendar] = ComponentMeta(Calendar) I am now trying to figuring out how to add my own complex types instead of relying on |
I guess you could even simplify this, as the @attr.s
class MyObj(ics.Component):
int_prop : int
str_prop : str
@attr.s(eq=True, order=False)
class Event(ics.Event):
custom_prop: Optional[MyObj] = attr.ib(default=None) # should also work as List[MyObj] for multiple
@attr.s
class Calendar(ics.Calendar):
events: List[Event] = attr.ib(
factory=list, converter=list, metadata={"ics_priority": -100},
)
ics.initialize_converters()
ComponentMeta.BY_TYPE[ics.Event] = ComponentMeta(Event)
ComponentMeta.BY_TYPE[ics.Calendar] = ComponentMeta(Calendar) |
If I wish to have my own properties on the calendar event class, how can I subclass
Event
and extend it with custom properties?The text was updated successfully, but these errors were encountered: