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    _path = 'calendar'
14    _name = 'calendar'
15
16
17class Calendar(Entity):
18    """
19    Implementation of the [Calendar](https://projectal.com/docs/latest/#tag/Calendar) API.
20
21    The Calendar object acts as a "container" of calendar items based on type. Types of
22    calendars are distinguished by name ("base_calendar", "location", "staff") and
23    may contain a set of calendar items either for itself ("location", "staff") or
24    for its holder ("base_calendar").
25    """
26    _path = 'calendar'
27    _name = 'calendar'
28
29    def __init__(self, data):
30        super(Calendar, self).__init__(data)
31
32        # Override the inner "calendarList" with the expected type (they are CalendarItems
33        # within the Calendar). We have to do this because the built-in conversion assumes
34        # they are Calendars because of the name of the list.
35        if self.get('calendarList'):
36            cals_as_obj = []
37            for cal in self.get('calendarList', []):
38                cals_as_obj.append(CalendarItem(cal))
39            self['calendarList'] = cals_as_obj
40
41
42    @classmethod
43    def create(cls, holder, entity):
44        """Create a Calendar
45
46        `holder`: `uuId` of the owner
47
48        `entity`: The fields of the entity to be created
49        """
50        holder_id = holder['uuId'] if isinstance(holder, dict) else holder
51        params = "?holder=" + holder_id
52        out = super().create(entity, params)
53        # Calendars use "empty linkers" during creation which don't go through our
54        # usual linker pipeline where the internal list is updated. Do it here
55        # manually.
56        if isinstance(holder, Entity):
57            cl = holder.get('calendarList', [])
58            cl.append(out)
59            holder.set_readonly('calendarList', copy.deepcopy(cl))
60        return out
61
62    @classmethod
63    def list(cls, expand=False, links=None):
64        raise UnsupportedException("Calendar list is not supported by the API.")
class CalendarItem(projectal.entity.Entity):
 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    _path = 'calendar'
15    _name = 'calendar'

This object represents entries within a calendar, like holidays or leaves. They are referred to as "Calendar Exceptions" in the web client.

class Calendar(projectal.entity.Entity):
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    _path = 'calendar'
28    _name = 'calendar'
29
30    def __init__(self, data):
31        super(Calendar, self).__init__(data)
32
33        # Override the inner "calendarList" with the expected type (they are CalendarItems
34        # within the Calendar). We have to do this because the built-in conversion assumes
35        # they are Calendars because of the name of the list.
36        if self.get('calendarList'):
37            cals_as_obj = []
38            for cal in self.get('calendarList', []):
39                cals_as_obj.append(CalendarItem(cal))
40            self['calendarList'] = cals_as_obj
41
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.")

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").

@classmethod
def create(cls, holder, entity):
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

Create a Calendar

holder: uuId of the owner

entity: The fields of the entity to be created

@classmethod
def list(cls, expand=False, links=None):
63    @classmethod
64    def list(cls, expand=False, links=None):
65        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.