Skip to content

Commit 2f486ed

Browse files
vvgrem@gmail.comvvgrem@gmail.com
authored andcommitted
SharePoint API: ViewFieldCollection methods & properties, refactorings for json mapper
1 parent b9f3775 commit 2f486ed

File tree

15 files changed

+195
-50
lines changed

15 files changed

+195
-50
lines changed

generator/metadata/SharePoint.xml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

office365/runtime/client_object.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def expand(self, names):
5959
return self
6060

6161
def select(self, names):
62+
"""
63+
64+
:param list[str] names:
65+
:return:
66+
"""
6267
self.query_options.select = names
6368
return self
6469

@@ -68,13 +73,16 @@ def remove_from_parent_collection(self):
6873
self._parent_collection.remove_child(self)
6974

7075
def get_property(self, name):
71-
getter_name = name[0].lower() + name[1:]
72-
if hasattr(self, getter_name):
73-
return getattr(self, getter_name)
74-
return self._properties.get(name, None)
76+
"""
77+
Gets property value
78+
79+
:param str name: property name
80+
"""
81+
normalized_name = name[0].lower() + name[1:]
82+
return getattr(self, normalized_name, self._properties.get(normalized_name, None))
7583

7684
def set_property(self, name, value, persist_changes=True):
77-
"""Sets Property value
85+
"""Sets property value
7886
7987
:param str name: Property name
8088
:param any value: Property value
@@ -83,17 +91,13 @@ def set_property(self, name, value, persist_changes=True):
8391
if persist_changes:
8492
self._changed_properties.append(name)
8593

86-
safe_name = name[0].lower() + name[1:]
87-
if hasattr(self, safe_name) and value is not None:
88-
prop_type = getattr(self, safe_name)
89-
if isinstance(prop_type, ClientObject) or isinstance(prop_type, ClientValue):
90-
if isinstance(value, list):
91-
[prop_type.set_property(i, v, persist_changes) for i, v in enumerate(value)]
92-
else:
93-
[prop_type.set_property(k, v, persist_changes) for k, v in value.items()]
94-
self._properties[name] = prop_type
94+
prop_type = self.get_property(name)
95+
if isinstance(prop_type, ClientObject) or isinstance(prop_type, ClientValue) and value is not None:
96+
if isinstance(value, list):
97+
[prop_type.set_property(i, v, persist_changes) for i, v in enumerate(value)]
9598
else:
96-
self._properties[name] = value
99+
[prop_type.set_property(k, v, persist_changes) for k, v in value.items()]
100+
self._properties[name] = prop_type
97101
else:
98102
self._properties[name] = value
99103
return self
@@ -124,6 +128,7 @@ def ensure_properties(self, names, action):
124128
def _process_query(current_query):
125129
if current_query.id == qry.id:
126130
action()
131+
127132
self.context.after_execute_query(_process_query)
128133
else:
129134
action()

office365/runtime/queries/batch_query.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ def add(self, query):
4141
def get(self, index):
4242
result = [qry for qry in self.change_sets if qry.return_type is not None] + \
4343
[qry for qry in self._queries if isinstance(qry, ReadEntityQuery)]
44-
45-
# result = [qry for qry in self._queries
46-
# if isinstance(qry, ReadEntityQuery)
47-
# or isinstance(qry, CreateEntityQuery)
48-
# or isinstance(qry, ServiceOperationQuery)]
4944
return result[index]
5045

5146
@property

office365/sharepoint/files/file.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,23 +342,23 @@ def name(self):
342342
return self.properties.get("Name", None)
343343

344344
@property
345-
def siteId(self):
345+
def site_id(self):
346346
"""Gets the GUID that identifies the site collection containing the file.
347347
348348
:rtype: str or None
349349
"""
350350
return self.properties.get("SiteId", None)
351351

352352
@property
353-
def webId(self):
353+
def web_id(self):
354354
"""Gets the GUID for the site containing the file.
355355
356356
:rtype: str or None
357357
"""
358358
return self.properties.get("WebId", None)
359359

360360
@property
361-
def timeLastModified(self):
361+
def time_last_modified(self):
362362
"""Specifies when the file was last modified.
363363
364364
:rtype: str or None
@@ -379,3 +379,4 @@ def set_property(self, name, value, persist_changes=True):
379379
"GetFileById",
380380
[value],
381381
ResourcePath("Web"))
382+
return self

office365/sharepoint/folders/folder.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def upload_file(self, name, content):
7979
target_file = self.files.add(info)
8080
return target_file
8181

82-
def copyto(self, new_relative_url, overwrite):
82+
def copy_to(self, new_relative_url, overwrite):
8383
"""Copies the folder with files to the destination URL.
8484
8585
:type new_relative_url: str
@@ -94,7 +94,7 @@ def _copy_files():
9494
self.ensure_property("Files", _copy_files)
9595
return self
9696

97-
def moveto(self, new_relative_url, flags):
97+
def move_to(self, new_relative_url, flags):
9898
"""Moves the folder with files to the destination URL.
9999
100100
:type new_relative_url: str
@@ -128,6 +128,43 @@ def files(self):
128128
from office365.sharepoint.files.file_collection import FileCollection
129129
return FileCollection(self.context, ResourcePath("Files", self.resource_path))
130130

131+
@property
132+
def unique_id(self):
133+
"""Gets the unique ID of the folder.
134+
:rtype: str or None
135+
"""
136+
return self.properties.get("UniqueId", None)
137+
138+
@property
139+
def exists(self):
140+
"""Gets a Boolean value that indicates whether the folder exists.
141+
:rtype: bool or None
142+
"""
143+
return self.properties.get("Exists", None)
144+
145+
@property
146+
def welcome_page(self):
147+
"""Specifies the server-relative URL for the list folder Welcome page.
148+
:rtype: str or None
149+
"""
150+
return self.properties.get("WelcomePage", None)
151+
152+
@property
153+
def unique_content_type_order(self):
154+
"""Specifies the content type order for the list folder.
155+
156+
:rtype: office365.sharepoint.contenttypes.content_type_id.ContentTypeId or None
157+
"""
158+
return self.properties.get("UniqueContentTypeOrder", None)
159+
160+
@property
161+
def time_last_modified(self):
162+
"""Gets the last time this folder or a direct child was modified in UTC.
163+
164+
:rtype: str or None
165+
"""
166+
return self.properties.get("TimeLastModified", None)
167+
131168
@property
132169
def serverRelativeUrl(self):
133170
"""Gets the server-relative URL of the list folder.

office365/sharepoint/folders/folder_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def ensure_folder_path(self, path):
2525
"""
2626

2727
url_component = os.path.normpath(path).split(os.path.sep)
28-
url_component = [part for part in url_component if part] # ensure no empty elements
28+
url_component = [part for part in url_component if part]
2929
if not url_component:
3030
raise NotADirectoryError("Wrong relative URL provided")
3131
child_folder = self

office365/sharepoint/listitems/caml/caml_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from office365.runtime.client_value import ClientValue
2-
from office365.sharepoint.views.viewScope import ViewScope
2+
from office365.sharepoint.views.view_scope import ViewScope
33

44

55
class CamlQuery(ClientValue):

office365/sharepoint/usercustomactions/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class UserCustomAction(BaseEntity):
5+
pass

office365/sharepoint/views/view.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ def __init__(self, context, resource_path=None, parent_list=None):
1515
super(View, self).__init__(context, resource_path)
1616
self._parent_list = parent_list
1717

18+
def get_property(self, name):
19+
if name == "ViewFields":
20+
return self.view_fields
21+
elif name == "DefaultView":
22+
return self.default_view
23+
else:
24+
return super(View, self).get_property(name)
25+
1826
def get_items(self):
1927
"""Get list items per a view
2028
2129
:rtype: office365.sharepoint.listitems.listItem_collection.ListItemCollection
2230
"""
2331

2432
def _get_items_inner():
25-
caml_query = CamlQuery.parse(self.viewQuery)
33+
caml_query = CamlQuery.parse(self.view_query)
2634
qry = ServiceOperationQuery(self._parent_list, "GetItems", None, caml_query, "query",
2735
self._parent_list.items)
2836
self.context.add_query(qry)
@@ -38,14 +46,14 @@ def delete_object(self):
3846
return self
3947

4048
@property
41-
def contentTypeId(self):
49+
def content_type_id(self):
4250
"""Gets the identifier of the content type with which the view is associated.
4351
:rtype: ContentTypeId
4452
"""
4553
return self.properties.get("ContentTypeId", ContentTypeId())
4654

47-
@contentTypeId.setter
48-
def contentTypeId(self, value):
55+
@content_type_id.setter
56+
def content_type_id(self, value):
4957
"""Sets the identifier of the content type with which the view is associated."""
5058
self.set_property("ContentTypeId", value)
5159

@@ -63,33 +71,30 @@ def hidden(self, value):
6371
self.set_property("Hidden", value)
6472

6573
@property
66-
def defaultView(self):
74+
def default_view(self):
6775
"""Gets whether the list view is the default list view.
6876
:rtype: bool or None
6977
"""
7078
return self.properties.get("DefaultView", None)
7179

72-
@defaultView.setter
73-
def defaultView(self, value):
80+
@default_view.setter
81+
def default_view(self, value):
7482
"""Sets whether the list view is the default list view.
7583
"""
7684
self.set_property("DefaultView", value)
7785

7886
@property
79-
def viewFields(self):
87+
def view_fields(self):
8088
"""Gets a value that specifies the collection of fields in the list view."""
8189
if self.is_property_available('ViewFields'):
8290
return self.properties['ViewFields']
8391
else:
8492
return ViewFieldCollection(self.context, ResourcePath("ViewFields", self.resource_path))
8593

8694
@property
87-
def viewQuery(self):
95+
def view_query(self):
8896
"""Gets or sets a value that specifies the query that is used by the list view."""
89-
if self.is_property_available('ViewQuery'):
90-
return self.properties['ViewQuery']
91-
else:
92-
return None
97+
return self.properties.get('ViewQuery', None)
9398

9499
def set_property(self, name, value, persist_changes=True):
95100
super(View, self).set_property(name, value, persist_changes)

0 commit comments

Comments
 (0)