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(cls, holder, entity): 45 """Create a Calendar 46 47 `holder`: `uuId` of the owner 48 49 `entity`: The fields of the entity to be created 50 """ 51 holder_id = holder["uuId"] if isinstance(holder, dict) else holder 52 params = "?holder=" + holder_id 53 out = super().create(entity, params) 54 # Calendars use "empty linkers" during creation which don't go through our 55 # usual linker pipeline where the internal list is updated. Do it here 56 # manually. 57 if isinstance(holder, Entity): 58 cl = holder.get("calendarList", []) 59 cl.append(out) 60 holder.set_readonly("calendarList", copy.deepcopy(cl)) 61 return out 62 63 @classmethod 64 def list(cls, expand=False, links=None): 65 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.
Inherited Members
- projectal.entity.Entity
- get
- update
- delete
- history
- create
- save
- clone
- list
- match
- match_startswith
- match_endswith
- match_one
- match_startswith_one
- match_endswith_one
- search
- query
- profile_get
- profile_set
- changes
- set_readonly
- get_link_definitions
- entity_name
- builtins.dict
- setdefault
- pop
- popitem
- keys
- items
- values
- fromkeys
- clear
- copy
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(cls, holder, entity): 46 """Create a Calendar 47 48 `holder`: `uuId` of the owner 49 50 `entity`: The fields of the entity to be created 51 """ 52 holder_id = holder["uuId"] if isinstance(holder, dict) else holder 53 params = "?holder=" + holder_id 54 out = super().create(entity, params) 55 # Calendars use "empty linkers" during creation which don't go through our 56 # usual linker pipeline where the internal list is updated. Do it here 57 # manually. 58 if isinstance(holder, Entity): 59 cl = holder.get("calendarList", []) 60 cl.append(out) 61 holder.set_readonly("calendarList", copy.deepcopy(cl)) 62 return out 63 64 @classmethod 65 def list(cls, expand=False, links=None): 66 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(cls, holder, entity): 46 """Create a Calendar 47 48 `holder`: `uuId` of the owner 49 50 `entity`: The fields of the entity to be created 51 """ 52 holder_id = holder["uuId"] if isinstance(holder, dict) else holder 53 params = "?holder=" + holder_id 54 out = super().create(entity, params) 55 # Calendars use "empty linkers" during creation which don't go through our 56 # usual linker pipeline where the internal list is updated. Do it here 57 # manually. 58 if isinstance(holder, Entity): 59 cl = holder.get("calendarList", []) 60 cl.append(out) 61 holder.set_readonly("calendarList", copy.deepcopy(cl)) 62 return out
Create a Calendar
holder
: uuId
of the owner
entity
: The fields of the entity to be created
64 @classmethod 65 def list(cls, expand=False, links=None): 66 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
.
Inherited Members
- projectal.entity.Entity
- get
- update
- delete
- history
- save
- clone
- match
- match_startswith
- match_endswith
- match_one
- match_startswith_one
- match_endswith_one
- search
- query
- profile_get
- profile_set
- changes
- set_readonly
- get_link_definitions
- entity_name
- builtins.dict
- setdefault
- pop
- popitem
- keys
- items
- values
- fromkeys
- clear
- copy