1
1
from office365 .runtime .action_type import ActionType
2
2
from office365 .runtime .client_object import ClientObject
3
3
from office365 .runtime .client_query import ClientQuery
4
+ from office365 .runtime .client_result import ClientResult
4
5
from office365 .runtime .odata .odata_path_parser import ODataPathParser
5
6
from office365 .runtime .resource_path_entry import ResourcePathEntry
7
+ from office365 .runtime .resource_path_service_operation import ResourcePathServiceOperation
6
8
from office365 .runtime .utilities .http_method import HttpMethod
7
9
from office365 .runtime .utilities .request_options import RequestOptions
8
10
from office365 .sharepoint .listitem import ListItem
11
+ from office365 .sharepoint .webparts .limited_webpart_manager import LimitedWebPartManager
9
12
10
13
11
14
class AbstractFile (ClientObject ):
@@ -35,7 +38,28 @@ class File(AbstractFile):
35
38
"""Represents a file in a SharePoint Web site that can be a Web Part Page, an item in a document library,
36
39
or a file in a folder."""
37
40
41
+ def approve (self , comment ):
42
+ """Approves the file submitted for content approval with the specified comment."""
43
+ qry = ClientQuery .service_operation_query (self ,
44
+ ActionType .PostMethod ,
45
+ "approve" ,
46
+ {
47
+ "comment" : comment
48
+ })
49
+ self .context .add_query (qry )
50
+
51
+ def deny (self , comment ):
52
+ """Denies approval for a file that was submitted for content approval."""
53
+ qry = ClientQuery .service_operation_query (self ,
54
+ ActionType .PostMethod ,
55
+ "deny" ,
56
+ {
57
+ "comment" : comment
58
+ })
59
+ self .context .add_query (qry )
60
+
38
61
def copyto (self , new_relative_url , overwrite ):
62
+ """Copies the file to the destination URL."""
39
63
qry = ClientQuery .service_operation_query (self ,
40
64
ActionType .PostMethod ,
41
65
"moveto" ,
@@ -47,6 +71,7 @@ def copyto(self, new_relative_url, overwrite):
47
71
self .context .add_query (qry )
48
72
49
73
def moveto (self , new_relative_url , flag ):
74
+ """Moves the file to the specified destination URL."""
50
75
qry = ClientQuery .service_operation_query (self ,
51
76
ActionType .PostMethod ,
52
77
"moveto" ,
@@ -57,6 +82,119 @@ def moveto(self, new_relative_url, flag):
57
82
None )
58
83
self .context .add_query (qry )
59
84
85
+ def publish (self , comment ):
86
+ """Submits the file for content approval with the specified comment."""
87
+ qry = ClientQuery .service_operation_query (self ,
88
+ ActionType .PostMethod ,
89
+ "publish" ,
90
+ {
91
+ "comment" : comment ,
92
+ }
93
+ )
94
+ self .context .add_query (qry )
95
+
96
+ def unpublish (self , comment ):
97
+ """Removes the file from content approval or unpublish a major version."""
98
+ qry = ClientQuery .service_operation_query (self ,
99
+ ActionType .PostMethod ,
100
+ "unpublish" ,
101
+ {
102
+ "comment" : comment ,
103
+ }
104
+ )
105
+ self .context .add_query (qry )
106
+
107
+ def checkout (self ):
108
+ """Checks out the file from a document library based on the check-out type."""
109
+ qry = ClientQuery .service_operation_query (self ,
110
+ ActionType .PostMethod ,
111
+ "checkout" ,
112
+ )
113
+ self .context .add_query (qry )
114
+
115
+ def checkin (self , comment , checkin_type ):
116
+ """Checks the file in to a document library based on the check-in type."""
117
+ qry = ClientQuery .service_operation_query (self ,
118
+ ActionType .PostMethod ,
119
+ "checkin" ,
120
+ {
121
+ "comment" : comment ,
122
+ "checkInType" : checkin_type
123
+ }
124
+ )
125
+ self .context .add_query (qry )
126
+
127
+ def undocheckout (self ):
128
+ """Reverts an existing checkout for the file."""
129
+ qry = ClientQuery .service_operation_query (self ,
130
+ ActionType .PostMethod ,
131
+ "undocheckout" ,
132
+ )
133
+ self .context .add_query (qry )
134
+
135
+ def recycle (self ):
136
+ """Moves the file to the Recycle Bin and returns the identifier of the new Recycle Bin item."""
137
+ qry = ClientQuery .service_operation_query (self ,
138
+ ActionType .PostMethod ,
139
+ "recycle" ,
140
+ )
141
+ self .context .add_query (qry )
142
+
143
+ def get_limited_webpart_manager (self , scope ):
144
+ """Specifies the control set used to access, modify, or add Web Parts associated with this Web Part Page and
145
+ view. """
146
+ return LimitedWebPartManager (self .context ,
147
+ ResourcePathServiceOperation (self .context , self .resource_path ,
148
+ "getlimitedwebpartmanager" ,
149
+ [scope ]
150
+ ))
151
+
152
+ def start_upload (self , upload_id , content ):
153
+ """Starts a new chunk upload session and uploads the first fragment."""
154
+ qry = ClientQuery .service_operation_query (self ,
155
+ ActionType .PostMethod ,
156
+ "startupload" ,
157
+ {
158
+ "uploadID" : upload_id
159
+ },
160
+ content
161
+ )
162
+ result = ClientResult
163
+ self .context .add_query (qry , result )
164
+ return result
165
+
166
+ def continue_upload (self , upload_id , file_offset , content ):
167
+ """Continues the chunk upload session with an additional fragment. The current file content is not changed."""
168
+ qry = ClientQuery .service_operation_query (self ,
169
+ ActionType .PostMethod ,
170
+ "continueupload" ,
171
+ {
172
+ "uploadID" : upload_id ,
173
+ "fileOffset" : file_offset ,
174
+ },
175
+ content
176
+ )
177
+ result = ClientResult
178
+ self .context .add_query (qry , result )
179
+ return result
180
+
181
+ def finish_upload (self , upload_id , file_offset , content ):
182
+ """Uploads the last file fragment and commits the file. The current file content is changed when this method
183
+ completes. """
184
+ qry = ClientQuery .service_operation_query (self ,
185
+ ActionType .PostMethod ,
186
+ "finishupload" ,
187
+ {
188
+ "uploadID" : upload_id ,
189
+ "fileOffset" : file_offset ,
190
+ },
191
+ content
192
+ )
193
+ self .context .add_query (qry , self )
194
+ return self
195
+
196
+
197
+
60
198
@staticmethod
61
199
def save_binary (ctx , server_relative_url , content ):
62
200
try :
0 commit comments