-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: easy way to allow customizing classes #133
Comments
I like that one as it is simpler. We have a start already. Maybe that can be incorporated. How to do it is now known to me at the moment.
On a general note, I see that the amount of arguments being dragged through the code increases:
This might be a point where a Strategy Pattern is a nicer solution. I think, people are fine with the odd argument and are unlikely to patch everything. A Strategy pattern might also allow customization in the case of #132. |
I'm not sure what you mean by using the Strategy Pattern. Customization import recurring_ical_events
class CustomRepeatedEvent(recurring_ical_events.RepeatedEvent):
def _get_component_end(self):
# Customized method
return super()._get_component_end()
class CustomUnfoldableCalendar(recurring_ical_events.UnfoldableCalendar):
keep_recurrence_attributes = True
recurrence_calculators = {
**recurring_ical_events.UnfoldableCalendar.recurrence_calculators,
"VEVENT": CustomRepeatedEvent,
}
calendar_events = recurring_ical_events.of(calendar, unfoldable_calendar_cls=CustomUnfoldableCalendar).between(...) Possible implementation def of(
a_calendar,
keep_recurrence_attributes=False,
components=None,
unfoldable_calendar_cls = UnfoldableCalendar,
) -> UnfoldableCalendar,:
...
return unfoldable_calendar_cls(a_calendar, keep_recurrence_attributes, components) class UnfoldableCalendar:
recurrence_calculators = {
"VEVENT": RepeatedEvent,
"VTODO": RepeatedTodo,
"VJOURNAL": RepeatedJournal,
}
keep_recurrence_attributes = False # Add this
components = None # Add this
def __init__(
self,
calendar,
keep_recurrence_attributes=None,
components=None,
):
# Keep existing behavior
if keep_recurrence_attributes is not None:
self.keep_recurrence_attributes = keep_recurrence_attributes
self.components = components or ["VEVENT"]
... |
@fabien-michel, sorry for taking so long. I must have missed your comment. It looks good to me what you propose. If you like, you could create an example file that overrides all the classes so that people have it easier and consistent and I can make sure that it works in the future. |
In Version 3.0.0, I added a new way: the ComponentAdapter. You can pass the ComponentAdapter to the components=[...] argument and it will be used to collect icalendar Components, create a Series and calculate the Occurrences. Thus, you can change all the components and classes if you like. I would say that it is necessary to document the public interface a bit better for this: Which classes/methods/functions are public how to override the classes, more documentation in the methods. Does this answer your question? What would you like to see to customize? Would documentation help? Let me know what you think, please. |
Thanks for all the works on version 3 ! |
I should add an example that filters, and shows how to do it... |
Please check with v3.3.0 if this can be closed. |
Add a mechanism to allow overriding classes.
Permit it would allow users to implement custom behavior without having to monkey-patch the code.
Example:
I'm not sure what is the good to way to do this kind of library customization.
The text was updated successfully, but these errors were encountered: