@@ -10,6 +10,9 @@ class Field(BaseEntity):
10
10
11
11
def __init__ (self , context , resource_path = None ):
12
12
super ().__init__ (context , resource_path )
13
+
14
+ @staticmethod
15
+ def get_field_type (type_id ):
13
16
from office365 .sharepoint .fields .fieldText import FieldText
14
17
from office365 .sharepoint .fields .fieldCalculated import FieldCalculated
15
18
from office365 .sharepoint .fields .fieldChoice import FieldChoice
@@ -21,7 +24,7 @@ def __init__(self, context, resource_path=None):
21
24
from office365 .sharepoint .fields .fieldGuid import FieldGuid
22
25
from office365 .sharepoint .fields .fieldCurrency import FieldCurrency
23
26
from office365 .sharepoint .fields .fieldMultiLineText import FieldMultiLineText
24
- self . _field_types = {
27
+ field_types = {
25
28
FieldType .Text : FieldText ,
26
29
FieldType .Calculated : FieldCalculated ,
27
30
FieldType .Choice : FieldChoice ,
@@ -34,14 +37,25 @@ def __init__(self, context, resource_path=None):
34
37
FieldType .Currency : FieldCurrency ,
35
38
FieldType .Note : FieldMultiLineText
36
39
}
40
+ return field_types .get (type_id , Field )
41
+
42
+ @staticmethod
43
+ def create_field_from_type (context , field_type ):
44
+ field_type = Field .get_field_type (field_type )
45
+ return field_type (context )
37
46
38
47
def set_show_in_display_form (self , flag ):
39
- """Sets the value of the ShowInDisplayForm property for this fields."""
48
+ """Sets the value of the ShowInDisplayForm property for this fields.
49
+
50
+ :type flag: bool
51
+ """
40
52
qry = ServiceOperationQuery (self , "setShowInDisplayForm" , [flag ])
41
53
self .context .add_query (qry )
42
54
43
55
def set_show_in_edit_form (self , flag ):
44
- """Sets the value of the ShowInEditForm property for this fields."""
56
+ """Sets the value of the ShowInEditForm property for this fields.
57
+ :type flag: bool
58
+ """
45
59
qry = ServiceOperationQuery (self , "setShowInEditForm" , [flag ])
46
60
self .context .add_query (qry )
47
61
@@ -59,7 +73,7 @@ def delete_object(self):
59
73
@property
60
74
def internal_name (self ):
61
75
"""Gets a value that specifies the field internal name."""
62
- return self .properties [ 'InternalName' ]
76
+ return self .properties . get ( 'InternalName' , None )
63
77
64
78
def set_property (self , name , value , persist_changes = True ):
65
79
super (Field , self ).set_property (name , value , persist_changes )
@@ -68,4 +82,4 @@ def set_property(self, name, value, persist_changes=True):
68
82
self ._resource_path = ResourcePathServiceOperation (
69
83
"getById" , [value ], self ._parent_collection .resource_path )
70
84
if name == "FieldTypeKind" :
71
- self .__class__ = self ._field_types . get (value , Field )
85
+ self .__class__ = self .get_field_type (value )
0 commit comments