Skip to content

Commit 9067c02

Browse files
Improvements for calendar & sharepoint namespaces (types, methods)
1 parent 211b384 commit 9067c02

30 files changed

+363
-159
lines changed

office365/base_item.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
from office365.directory.identitySet import IdentitySet
22
from office365.entity import Entity
33
from office365.onedrive.itemReference import ItemReference
4-
from office365.runtime.queries.delete_entity_query import DeleteEntityQuery
54

65

76
class BaseItem(Entity):
87
"""The baseItem resource is an abstract resource that contains a common set of properties shared among several
98
other resources types """
109

11-
def delete_object(self):
12-
"""Deletes the item."""
13-
qry = DeleteEntityQuery(self)
14-
self.context.add_query(qry)
15-
self.remove_from_parent_collection()
16-
return self
17-
1810
@property
1911
def etag(self):
2012
"""ETag for the item."""
21-
if self.is_property_available("eTag"):
22-
return self.properties['eTag']
23-
return None
13+
return self.properties.get('eTag', None)
2414

2515
@property
2616
def createdBy(self):
@@ -30,23 +20,17 @@ def createdBy(self):
3020
@property
3121
def lastModifiedBy(self):
3222
"""Identity of the user, device, and application which last modified the item."""
33-
if self.is_property_available("lastModifiedBy"):
34-
return self.properties['lastModifiedBy']
35-
return IdentitySet()
23+
return self.properties.get('lastModifiedBy', IdentitySet())
3624

3725
@property
3826
def createdDateTime(self):
3927
"""Date and time of item creation."""
40-
if self.is_property_available("createdDateTime"):
41-
return self.properties['createdDateTime']
42-
return None
28+
return self.properties.get('createdDateTime', None)
4329

4430
@property
4531
def lastModifiedDateTime(self):
4632
"""Date and time the item was last modified."""
47-
if self.is_property_available("lastModifiedDateTime"):
48-
return self.properties['lastModifiedDateTime']
49-
return None
33+
return self.properties.get('lastModifiedDateTime', None)
5034

5135
@property
5236
def name(self):
@@ -60,9 +44,7 @@ def name(self, value):
6044
@property
6145
def description(self):
6246
"""Provides a user-visible description of the item."""
63-
if self.is_property_available("description"):
64-
return self.properties['description']
65-
return None
47+
return self.properties.get('description',None)
6648

6749
@description.setter
6850
def description(self, value):
@@ -71,9 +53,7 @@ def description(self, value):
7153
@property
7254
def web_url(self):
7355
"""URL that displays the resource in the browser."""
74-
if self.is_property_available("webUrl"):
75-
return self.properties['webUrl']
76-
return None
56+
return self.properties.get('webUrl', None)
7757

7858
@property
7959
def parentReference(self):

office365/calendar/attendee.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from office365.calendar.attendeeBase import AttendeeBase
2+
from office365.calendar.emailAddress import EmailAddress
3+
4+
5+
class Attendee(AttendeeBase):
6+
"""An event attendee. This can be a person or resource such as a meeting room or equipment,
7+
that has been set up as a resource on the Exchange server for the tenant."""
8+
9+
def __init__(self, emailAddress=EmailAddress(), attendee_type=None, proposedNewTime=None, status=None):
10+
"""
11+
12+
:param office365.mail.emailAddress.EmailAddress emailAddress emailAddress:
13+
:param office365.calendar.timeSlot.TimeSlot proposedNewTime:
14+
:param str status: The attendee's response (none, accepted, declined, etc.) for the event and date-time
15+
that the response was sent.
16+
"""
17+
super().__init__(emailAddress, attendee_type)
18+
self.proposedNewTime = proposedNewTime
19+
self.status = status

office365/calendar/attendeeBase.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from office365.mail.recipient import Recipient
2+
3+
4+
class AttendeeBase(Recipient):
5+
"""The type of attendee."""
6+
7+
def __init__(self, emailAddress, attendee_type=None):
8+
"""
9+
10+
:param office365.mail.emailAddress.EmailAddress emailAddress: Includes the name and SMTP address of the attendee
11+
:param str attendee_type: The type of attendee. The possible values are: required, optional, resource.
12+
Currently if the attendee is a person, findMeetingTimes always considers the person is of the Required type.
13+
"""
14+
super().__init__(emailAddress)
15+
self.type = attendee_type

office365/calendar/calendar_permission.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22

33

44
class CalendarPermission(Entity):
5+
"""
6+
The permissions of a user with whom the calendar has been shared or delegated in an Outlook client.
7+
8+
Get, update, and delete of calendar permissions is supported on behalf of only the calendar owner.
9+
10+
Getting the calendar permissions of a calendar on behalf of a sharee or delegate returns
11+
an empty calendar permissions collection.
12+
13+
Once a sharee or delegate has been set up for a calendar, you can update only the role property to change
14+
the permissions of a sharee or delegate. You cannot update the allowedRoles, emailAddress, isInsideOrganization,
15+
or isRemovable property. To change these properties, you should delete the corresponding calendarPermission
16+
object and create another sharee or delegate in an Outlook client.
17+
18+
"""
519
pass

office365/calendar/event.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
from office365.calendar.attendee import Attendee
2+
from office365.mail.attachment_collection import AttachmentCollection
13
from office365.mail.item import Item
4+
from office365.mail.location import Location
5+
from office365.runtime.client_value_collection import ClientValueCollection
26
from office365.runtime.resource_path import ResourcePath
37

48

59
class Event(Item):
610
"""An event in a user calendar, or the default calendar of a Microsoft 365 group."""
711

8-
@property
9-
def id(self):
10-
return self.properties.get("id", None)
11-
1212
@property
1313
def body_preview(self):
1414
"""
@@ -25,6 +25,13 @@ def subject(self):
2525
"""
2626
return self.properties.get("subject", None)
2727

28+
@property
29+
def location(self):
30+
"""
31+
The location of the event.
32+
"""
33+
return self.properties.get("location", Location())
34+
2835
@property
2936
def web_link(self):
3037
"""
@@ -45,3 +52,15 @@ def calendar(self):
4552
from office365.calendar.calendar import Calendar
4653
return self.properties.get('calendar',
4754
Calendar(self.context, ResourcePath("calendar", self.resource_path)))
55+
56+
@property
57+
def attendees(self):
58+
"""The collection of attendees for the event."""
59+
return self.properties.get('attendees',
60+
ClientValueCollection(Attendee))
61+
62+
@property
63+
def attachments(self):
64+
"""The collection of fileAttachment and itemAttachment attachments for the event. """
65+
return self.properties.get('attachments',
66+
AttachmentCollection(self.context, ResourcePath("attachments", self.resource_path)))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1+
from office365.calendar.attendee import Attendee
2+
from office365.calendar.dateTimeTimeZone import DateTimeTimeZone
3+
from office365.calendar.emailAddress import EmailAddress
14
from office365.calendar.event import Event
25
from office365.entity_collection import EntityCollection
6+
from office365.mail.itemBody import ItemBody
7+
from office365.runtime.client_value_collection import ClientValueCollection
38

49

510
class EventCollection(EntityCollection):
611
"""Event's collection"""
712
def __init__(self, context, resource_path=None):
813
super(EventCollection, self).__init__(context, Event, resource_path)
14+
15+
def add(self, subject, body, start, end, attendees_emails):
16+
"""
17+
:param list[str] attendees_emails: The collection of attendees emails for the event.
18+
:param datetime.datetime end: The date, time, and time zone that the event ends.
19+
By default, the end time is in UTC.
20+
:param datetime.datetime start: The date, time, and time zone that the event starts.
21+
By default, the start time is in UTC.
22+
:param str body: The body of the message associated with the event. It can be in HTML format.
23+
:param str subject: The text of the event's subject line.
24+
:rtype: Event
25+
"""
26+
attendees_list = [Attendee(EmailAddress(email), attendee_type="required") for email in attendees_emails]
27+
payload = {
28+
"subject": subject,
29+
"body": ItemBody(body, "HTML"),
30+
"start": DateTimeTimeZone.parse(start),
31+
"end": DateTimeTimeZone.parse(end),
32+
"attendees": ClientValueCollection(Attendee, attendees_list)
33+
}
34+
return self.add_from_json(payload)

office365/calendar/timeSlot.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class TimeSlot(ClientValue):
5+
"""Represents a time slot for a meeting."""
6+
7+
def __init__(self, start, end):
8+
"""
9+
10+
:param datetime.datetime start: The date, time, and time zone that a period begins.
11+
:param datetime.datetime end: The date, time, and time zone that a period ends.
12+
"""
13+
super().__init__()
14+
self.start = start
15+
self.end = end

office365/directory/group.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,14 @@ def members(self):
7373
@property
7474
def owners(self):
7575
"""The owners of the group."""
76-
if self.is_property_available('owners'):
77-
return self.properties['owners']
78-
else:
79-
return DirectoryObjectCollection(self.context,
80-
ResourcePath("owners", self.resource_path))
76+
return self.properties.get('owners',
77+
DirectoryObjectCollection(self.context, ResourcePath("owners", self.resource_path)))
8178

8279
@property
8380
def drives(self):
8481
"""The group's drives. Read-only."""
85-
if self.is_property_available('drives'):
86-
return self.properties['drives']
87-
else:
88-
return DriveCollection(self.context, ResourcePath("drives", self.resource_path))
82+
return self.properties.get('drives',
83+
DriveCollection(self.context, ResourcePath("drives", self.resource_path)))
8984

9085
@property
9186
def sites(self):

office365/directory/objectIdentity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ObjectIdentity(ClientValue):
66
Represents an identity used to sign in to a user account.
77
"""
88

9-
def __init__(self, signInType, issuer, issuerAssignedId):
9+
def __init__(self, signInType=None, issuer=None, issuerAssignedId=None):
1010
"""
1111
1212
:param str signInType: Specifies the user sign-in types in your directory, such as emailAddress, userName

office365/mail/emailAddress.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)