projectal.entities.calendar
1import copy 2 3from projectal.errors import UnsupportedException 4 5from projectal.entity import Entity 6 7 8class CalendarItem(Entity): 9 """ 10 This object represents entries within a calendar, like holidays or leaves. 11 They are referred to as "Calendar Exceptions" in the web client. 12 """ 13 14 _path = "calendar" 15 _name = "calendar" 16 17 18class Calendar(Entity): 19 """ 20 Implementation of the [Calendar](https://projectal.com/docs/latest/#tag/Calendar) API. 21 22 The Calendar object acts as a "container" of calendar items based on type. Types of 23 calendars are distinguished by name ("base_calendar", "location", "staff") and 24 may contain a set of calendar items either for itself ("location", "staff") or 25 for its holder ("base_calendar"). 26 """ 27 28 _path = "calendar" 29 _name = "calendar" 30 31 def __init__(self, data): 32 super(Calendar, self).__init__(data) 33 34 # Override the inner "calendarList" with the expected type (they are CalendarItems 35 # within the Calendar). We have to do this because the built-in conversion assumes 36 # they are Calendars because of the name of the list. 37 if self.get("calendarList"): 38 cals_as_obj = [] 39 for cal in self.get("calendarList", []): 40 cals_as_obj.append(CalendarItem(cal)) 41 self["calendarList"] = cals_as_obj 42 43 @classmethod 44 def create( 45 cls, 46 holder, 47 entity, 48 batch_linking=True, 49 disable_system_features=True, 50 enable_system_features_on_exit=True, 51 ): 52 """Create a Calendar 53 54 `holder`: `uuId` of the owner 55 56 `entity`: The fields of the entity to be created 57 """ 58 holder_id = holder["uuId"] if isinstance(holder, dict) else holder 59 params = "?holder=" + holder_id 60 out = super().create( 61 entity, 62 params, 63 batch_linking, 64 disable_system_features, 65 enable_system_features_on_exit, 66 ) 67 # Calendars use "empty linkers" during creation which don't go through our 68 # usual linker pipeline where the internal list is updated. Do it here 69 # manually. 70 if isinstance(holder, Entity): 71 cl = holder.get("calendarList", []) 72 cl.append(out) 73 holder.set_readonly("calendarList", copy.deepcopy(cl)) 74 return out 75 76 @classmethod 77 def list(cls, expand=False, links=None): 78 raise UnsupportedException("Calendar list is not supported by the API.")
9class CalendarItem(Entity): 10 """ 11 This object represents entries within a calendar, like holidays or leaves. 12 They are referred to as "Calendar Exceptions" in the web client. 13 """ 14 15 _path = "calendar" 16 _name = "calendar"
This object represents entries within a calendar, like holidays or leaves. They are referred to as "Calendar Exceptions" in the web client.
19class Calendar(Entity): 20 """ 21 Implementation of the [Calendar](https://projectal.com/docs/latest/#tag/Calendar) API. 22 23 The Calendar object acts as a "container" of calendar items based on type. Types of 24 calendars are distinguished by name ("base_calendar", "location", "staff") and 25 may contain a set of calendar items either for itself ("location", "staff") or 26 for its holder ("base_calendar"). 27 """ 28 29 _path = "calendar" 30 _name = "calendar" 31 32 def __init__(self, data): 33 super(Calendar, self).__init__(data) 34 35 # Override the inner "calendarList" with the expected type (they are CalendarItems 36 # within the Calendar). We have to do this because the built-in conversion assumes 37 # they are Calendars because of the name of the list. 38 if self.get("calendarList"): 39 cals_as_obj = [] 40 for cal in self.get("calendarList", []): 41 cals_as_obj.append(CalendarItem(cal)) 42 self["calendarList"] = cals_as_obj 43 44 @classmethod 45 def create( 46 cls, 47 holder, 48 entity, 49 batch_linking=True, 50 disable_system_features=True, 51 enable_system_features_on_exit=True, 52 ): 53 """Create a Calendar 54 55 `holder`: `uuId` of the owner 56 57 `entity`: The fields of the entity to be created 58 """ 59 holder_id = holder["uuId"] if isinstance(holder, dict) else holder 60 params = "?holder=" + holder_id 61 out = super().create( 62 entity, 63 params, 64 batch_linking, 65 disable_system_features, 66 enable_system_features_on_exit, 67 ) 68 # Calendars use "empty linkers" during creation which don't go through our 69 # usual linker pipeline where the internal list is updated. Do it here 70 # manually. 71 if isinstance(holder, Entity): 72 cl = holder.get("calendarList", []) 73 cl.append(out) 74 holder.set_readonly("calendarList", copy.deepcopy(cl)) 75 return out 76 77 @classmethod 78 def list(cls, expand=False, links=None): 79 raise UnsupportedException("Calendar list is not supported by the API.")
Implementation of the Calendar API.
The Calendar object acts as a "container" of calendar items based on type. Types of calendars are distinguished by name ("base_calendar", "location", "staff") and may contain a set of calendar items either for itself ("location", "staff") or for its holder ("base_calendar").
44 @classmethod 45 def create( 46 cls, 47 holder, 48 entity, 49 batch_linking=True, 50 disable_system_features=True, 51 enable_system_features_on_exit=True, 52 ): 53 """Create a Calendar 54 55 `holder`: `uuId` of the owner 56 57 `entity`: The fields of the entity to be created 58 """ 59 holder_id = holder["uuId"] if isinstance(holder, dict) else holder 60 params = "?holder=" + holder_id 61 out = super().create( 62 entity, 63 params, 64 batch_linking, 65 disable_system_features, 66 enable_system_features_on_exit, 67 ) 68 # Calendars use "empty linkers" during creation which don't go through our 69 # usual linker pipeline where the internal list is updated. Do it here 70 # manually. 71 if isinstance(holder, Entity): 72 cl = holder.get("calendarList", []) 73 cl.append(out) 74 holder.set_readonly("calendarList", copy.deepcopy(cl)) 75 return out
Create a Calendar
holder
: uuId
of the owner
entity
: The fields of the entity to be created
77 @classmethod 78 def list(cls, expand=False, links=None): 79 raise UnsupportedException("Calendar list is not supported by the API.")
Return a list of all entity UUIDs of this type.
You may pass in expand=True
to get full Entity objects
instead, but be aware this may be very slow if you have
thousands of objects.
If you are expanding the objects, you may further expand
the results with links
.