Skip to content

Commit d85f717

Browse files
vvgrem@gmail.comvvgrem@gmail.com
authored andcommitted
SharePoint API: fields namespace improvements
1 parent af9d90d commit d85f717

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+301
-76
lines changed

examples/sharepoint/tenant/get_set_site_admin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
admins = tenant.get_site_secondary_administrators(site_id=target_site.id)
1818
admin_client.execute_query()
1919

20-
existing_admin_names = [admin.get_property('loginName') for admin in admins]
20+
existing_admin_names = [admin.loginName for admin in admins]
2121

22-
target_user = target_site.rootWeb.ensure_user(f"mdoe@{tenant_prefix}.onmicrosoft.com").execute_query()
22+
target_user = target_site.root_web.ensure_user(f"mdoe@{tenant_prefix}.onmicrosoft.com").execute_query()
2323
names = existing_admin_names + [target_user.login_name]
2424
tenant.set_site_secondary_administrators(site_id=target_site.id, names=names).execute_query()
2525

2626
for admin in admins: # type: SecondaryAdministratorsInfo
27-
print(admin.get_property('loginName'))
27+
print(admin.loginName)

generator/metadata/SharePoint.xml

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

office365/runtime/client_object.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def __init__(self, context, resource_path=None, properties=None, parent_collecti
2626
for k, v in properties.items():
2727
self.set_property(k, v, True)
2828

29+
def clear(self):
30+
self._changed_properties = []
31+
2932
def execute_query(self):
3033
self.context.execute_query()
3134
return self

office365/runtime/odata/odata_path_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def from_method(method_name, method_parameters=None):
2626
url += "("
2727
if isinstance(method_parameters, dict):
2828
url += ','.join(['%s=%s' % (key, ODataPathParser.encode_method_value(value)) for (key, value) in
29-
method_parameters.items()])
29+
method_parameters.items() if value is not None])
3030
else:
3131
url += ','.join(['%s' % (ODataPathParser.encode_method_value(value)) for (i, value) in
32-
enumerate(method_parameters)])
32+
enumerate(method_parameters) if value is not None])
3333
url += ")"
3434
return url
3535

office365/runtime/odata/odata_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def process_response(self, response):
6262
"""
6363
qry = self.current_query
6464
result_object = qry.return_type
65-
if isinstance(result_object, ClientObjectCollection):
65+
if isinstance(result_object, ClientObject):
6666
result_object.clear()
6767

6868
if response.headers.get('Content-Type', '').lower().split(';')[0] != 'application/json':

office365/sharepoint/fields/field.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ def resolve_field_type(type_id_or_name):
1919
from office365.sharepoint.fields.field_currency import FieldCurrency
2020
from office365.sharepoint.fields.field_guid import FieldGuid
2121
from office365.sharepoint.fields.field_lookup import FieldLookup
22-
from office365.sharepoint.fields.fieldMultiChoice import FieldMultiChoice
23-
from office365.sharepoint.fields.fieldMultiLineText import FieldMultiLineText
22+
from office365.sharepoint.fields.field_multi_choice import FieldMultiChoice
23+
from office365.sharepoint.fields.field_multi_line_text import FieldMultiLineText
2424
from office365.sharepoint.fields.field_text import FieldText
2525
from office365.sharepoint.fields.field_url import FieldUrl
2626
from office365.sharepoint.fields.field_user import FieldUser
2727
from office365.sharepoint.taxonomy.taxonomy_field import TaxonomyField
28+
from office365.sharepoint.fields.field_date_time import FieldDateTime
2829
field_known_types = {
2930
FieldType.Text: FieldText,
3031
FieldType.Calculated: FieldCalculated,
@@ -36,17 +37,27 @@ def resolve_field_type(type_id_or_name):
3637
FieldType.URL: FieldUrl,
3738
FieldType.Guid: FieldGuid,
3839
FieldType.Currency: FieldCurrency,
39-
FieldType.Note: FieldMultiLineText
40+
FieldType.Note: FieldMultiLineText,
41+
FieldType.DateTime: FieldDateTime
4042
}
4143
if isinstance(type_id_or_name, int):
4244
return field_known_types.get(type_id_or_name, Field)
4345
else:
4446
return TaxonomyField if type_id_or_name == "TaxonomyFieldType" else Field
4547

4648
@staticmethod
47-
def create_field_from_type(context, field_type):
48-
field_type = Field.resolve_field_type(field_type)
49-
return field_type(context)
49+
def create_field_from_type(context, field_parameters):
50+
"""
51+
52+
:type context: ClientContext
53+
:type field_parameters: office365.sharepoint.fields.field_creation_information.FieldCreationInformation
54+
:return: Field
55+
"""
56+
field_type = Field.resolve_field_type(field_parameters.FieldTypeKind)
57+
field = field_type(context)
58+
for n, v in field_parameters.to_json().items():
59+
field.set_property(n, v)
60+
return field
5061

5162
def set_show_in_display_form(self, flag):
5263
"""Sets the value of the ShowInDisplayForm property for this fields.
@@ -85,14 +96,46 @@ def id(self):
8596
"""
8697
return self.properties.get('Id', None)
8798

99+
@property
100+
def type_as_string(self):
101+
"""Gets a value that specifies the type of the field..
102+
103+
:rtype: str or None
104+
"""
105+
return self.properties.get('TypeAsString', None)
106+
88107
@property
89108
def title(self):
90-
"""Gets or sets a value that specifies the display name of the field.
109+
"""Gets a value that specifies the display name of the field.
91110
92111
:rtype: str or None
93112
"""
94113
return self.properties.get('Title', None)
95114

115+
@title.setter
116+
def title(self, val):
117+
"""Sets a value that specifies the display name of the field.
118+
119+
:rtype: str or None
120+
"""
121+
self.set_property("Title", val)
122+
123+
@property
124+
def group(self):
125+
"""Gets a value that specifies the field group.
126+
127+
:rtype: str or None
128+
"""
129+
return self.properties.get('Group', None)
130+
131+
@group.setter
132+
def group(self, val):
133+
"""Sets a value that specifies the field group.
134+
135+
:rtype: str or None
136+
"""
137+
self.set_property("Group", val)
138+
96139
@property
97140
def internal_name(self):
98141
"""Gets a value that specifies the field internal name.

office365/sharepoint/fields/fieldMultiLookupValue.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_collection import ClientValueCollection
2-
from office365.sharepoint.fields.fieldLookupValue import FieldLookupValue
2+
from office365.sharepoint.fields.field_lookup_value import FieldLookupValue
33

44

55
class FieldMultiLookupValue(ClientValueCollection):

office365/sharepoint/fields/field_collection.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,20 @@ def add(self, field_create_information):
2323
2424
:type field_create_information: office365.sharepoint.fields.field_creation_information.FieldCreationInformation
2525
"""
26-
field = Field.create_field_from_type(self.context, field_create_information.FieldTypeKind)
26+
field = Field.create_field_from_type(self.context, field_create_information)
2727
self.add_child(field)
28-
qry = CreateEntityQuery(self, field_create_information, field)
28+
qry = CreateEntityQuery(self, field, field)
29+
self.context.add_query(qry)
30+
return field
31+
32+
def add_field(self, parameters):
33+
"""Adds a fields to the fields collection.
34+
35+
:type parameters: office365.sharepoint.fields.field_creation_information.FieldCreationInformation
36+
"""
37+
field = Field(self.context)
38+
self.add_child(field)
39+
qry = ServiceOperationQuery(self, "AddField", None, parameters, "parameters", field)
2940
self.context.add_query(qry)
3041
return field
3142

office365/sharepoint/fields/field_computed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class FieldComputed(Field):
55

66
@property
7-
def enableLookup(self):
7+
def enable_lookup(self):
88
"""
99
Specifies whether a lookup field can reference the field (2).
1010

0 commit comments

Comments
 (0)