projectal.entities.file
1from projectal.entity import Entity 2from projectal.linkers import * 3from projectal import api 4 5 6class File(Entity, CompanyLinker, CustomerLinker, FolderLinker, ProjectLinker, 7 StaffLinker, TaskLinker, TaskTemplateLinker, NoteLinker, TagLinker): 8 """ 9 Implementation of the [File](https://projectal.com/docs/latest/#tag/File) API. 10 """ 11 _path = 'file' 12 _name = 'file' 13 _links = [NoteLinker, TagLinker] 14 _links_reverse = [CompanyLinker, CustomerLinker, FolderLinker, ProjectLinker, 15 StaffLinker, TaskLinker, TaskTemplateLinker] 16 17 @classmethod 18 def create(cls, file_data, entity): 19 """ 20 Create a File entity with file data. 21 22 `file_data` is the raw file data in bytes 23 24 `entity` is the File entity and its fields. 25 """ 26 payload = entity 27 url = '/api/file/upload' 28 file = {'file': file_data} 29 response = api.post(url, payload, file=file) 30 entity['uuId'] = response['jobClue']['uuId'] 31 return cls(entity) 32 33 @classmethod 34 def get(cls, uuId, links=None): 35 """Get the File entity. No file data is included.""" 36 link_set = cls._get_linkset(links) 37 url = '/api/file/get?uuId={}'.format(uuId) 38 if link_set: 39 url += '&links=' + ','.join(link_set) 40 return cls(api.get(url)) 41 42 @classmethod 43 def update(cls, entity, file_data=None): 44 """ 45 Update the File entity. Optionally, also update the 46 file data that this File holds. 47 """ 48 payload = entity 49 url = '/api/file/update' 50 if file_data: 51 file = {'file': file_data} 52 api.put(url, payload, file=file) 53 else: 54 api.put(url, payload, form=True) 55 56 @classmethod 57 def get_file_data(cls, uuId): 58 """ 59 Get the file data that is held by the file with `uuId`. 60 Returns the raw content of the response. 61 """ 62 url = '/api/file/{}'.format(uuId) 63 response = api.get(url, is_json=False) 64 return response.content 65 66 @classmethod 67 def download_to_browser(cls, uuId): 68 """ 69 Get the file data that is held by the file with `uuId`. 70 Returns the response object which will have headers suitable 71 to initiate a download by the user agent. 72 """ 73 url = '/api/file/download' 74 payload = {'uuId': uuId} 75 response = api.post(url, payload, is_json=False) 76 return response 77 78 @classmethod 79 def delete(cls, uuId): 80 """ 81 Delete the File entity and its file data. 82 """ 83 url = '/api/file/delete/{}'.format(uuId) 84 api.delete(url) 85 return True 86 87 @classmethod 88 def download_multiple(cls, list): 89 """ 90 Given a list of File entities, return the file data held by 91 each as a `.zip` file. 92 """ 93 url = '/api/file/multidownload' 94 response = api.post(url, list, is_json=False) 95 return response.content 96 97 @classmethod 98 def list(cls, expand=True): 99 """Return all files as a list""" 100 files = api.get('/api/file/list') 101 return [cls(f) for f in files]
class
File(projectal.entity.Entity, projectal.linkers.CompanyLinker, projectal.linkers.CustomerLinker, projectal.linkers.FolderLinker, projectal.linkers.ProjectLinker, projectal.linkers.StaffLinker, projectal.linkers.TaskLinker, projectal.linkers.TaskTemplateLinker, projectal.linkers.NoteLinker, projectal.linkers.TagLinker):
7class File(Entity, CompanyLinker, CustomerLinker, FolderLinker, ProjectLinker, 8 StaffLinker, TaskLinker, TaskTemplateLinker, NoteLinker, TagLinker): 9 """ 10 Implementation of the [File](https://projectal.com/docs/latest/#tag/File) API. 11 """ 12 _path = 'file' 13 _name = 'file' 14 _links = [NoteLinker, TagLinker] 15 _links_reverse = [CompanyLinker, CustomerLinker, FolderLinker, ProjectLinker, 16 StaffLinker, TaskLinker, TaskTemplateLinker] 17 18 @classmethod 19 def create(cls, file_data, entity): 20 """ 21 Create a File entity with file data. 22 23 `file_data` is the raw file data in bytes 24 25 `entity` is the File entity and its fields. 26 """ 27 payload = entity 28 url = '/api/file/upload' 29 file = {'file': file_data} 30 response = api.post(url, payload, file=file) 31 entity['uuId'] = response['jobClue']['uuId'] 32 return cls(entity) 33 34 @classmethod 35 def get(cls, uuId, links=None): 36 """Get the File entity. No file data is included.""" 37 link_set = cls._get_linkset(links) 38 url = '/api/file/get?uuId={}'.format(uuId) 39 if link_set: 40 url += '&links=' + ','.join(link_set) 41 return cls(api.get(url)) 42 43 @classmethod 44 def update(cls, entity, file_data=None): 45 """ 46 Update the File entity. Optionally, also update the 47 file data that this File holds. 48 """ 49 payload = entity 50 url = '/api/file/update' 51 if file_data: 52 file = {'file': file_data} 53 api.put(url, payload, file=file) 54 else: 55 api.put(url, payload, form=True) 56 57 @classmethod 58 def get_file_data(cls, uuId): 59 """ 60 Get the file data that is held by the file with `uuId`. 61 Returns the raw content of the response. 62 """ 63 url = '/api/file/{}'.format(uuId) 64 response = api.get(url, is_json=False) 65 return response.content 66 67 @classmethod 68 def download_to_browser(cls, uuId): 69 """ 70 Get the file data that is held by the file with `uuId`. 71 Returns the response object which will have headers suitable 72 to initiate a download by the user agent. 73 """ 74 url = '/api/file/download' 75 payload = {'uuId': uuId} 76 response = api.post(url, payload, is_json=False) 77 return response 78 79 @classmethod 80 def delete(cls, uuId): 81 """ 82 Delete the File entity and its file data. 83 """ 84 url = '/api/file/delete/{}'.format(uuId) 85 api.delete(url) 86 return True 87 88 @classmethod 89 def download_multiple(cls, list): 90 """ 91 Given a list of File entities, return the file data held by 92 each as a `.zip` file. 93 """ 94 url = '/api/file/multidownload' 95 response = api.post(url, list, is_json=False) 96 return response.content 97 98 @classmethod 99 def list(cls, expand=True): 100 """Return all files as a list""" 101 files = api.get('/api/file/list') 102 return [cls(f) for f in files]
Implementation of the File API.
@classmethod
def
create(cls, file_data, entity):
18 @classmethod 19 def create(cls, file_data, entity): 20 """ 21 Create a File entity with file data. 22 23 `file_data` is the raw file data in bytes 24 25 `entity` is the File entity and its fields. 26 """ 27 payload = entity 28 url = '/api/file/upload' 29 file = {'file': file_data} 30 response = api.post(url, payload, file=file) 31 entity['uuId'] = response['jobClue']['uuId'] 32 return cls(entity)
Create a File entity with file data.
file_data
is the raw file data in bytes
entity
is the File entity and its fields.
@classmethod
def
get(cls, uuId, links=None):
34 @classmethod 35 def get(cls, uuId, links=None): 36 """Get the File entity. No file data is included.""" 37 link_set = cls._get_linkset(links) 38 url = '/api/file/get?uuId={}'.format(uuId) 39 if link_set: 40 url += '&links=' + ','.join(link_set) 41 return cls(api.get(url))
Get the File entity. No file data is included.
@classmethod
def
update(cls, entity, file_data=None):
43 @classmethod 44 def update(cls, entity, file_data=None): 45 """ 46 Update the File entity. Optionally, also update the 47 file data that this File holds. 48 """ 49 payload = entity 50 url = '/api/file/update' 51 if file_data: 52 file = {'file': file_data} 53 api.put(url, payload, file=file) 54 else: 55 api.put(url, payload, form=True)
Update the File entity. Optionally, also update the file data that this File holds.
@classmethod
def
get_file_data(cls, uuId):
57 @classmethod 58 def get_file_data(cls, uuId): 59 """ 60 Get the file data that is held by the file with `uuId`. 61 Returns the raw content of the response. 62 """ 63 url = '/api/file/{}'.format(uuId) 64 response = api.get(url, is_json=False) 65 return response.content
Get the file data that is held by the file with uuId
.
Returns the raw content of the response.
@classmethod
def
download_to_browser(cls, uuId):
67 @classmethod 68 def download_to_browser(cls, uuId): 69 """ 70 Get the file data that is held by the file with `uuId`. 71 Returns the response object which will have headers suitable 72 to initiate a download by the user agent. 73 """ 74 url = '/api/file/download' 75 payload = {'uuId': uuId} 76 response = api.post(url, payload, is_json=False) 77 return response
Get the file data that is held by the file with uuId
.
Returns the response object which will have headers suitable
to initiate a download by the user agent.
@classmethod
def
delete(cls, uuId):
79 @classmethod 80 def delete(cls, uuId): 81 """ 82 Delete the File entity and its file data. 83 """ 84 url = '/api/file/delete/{}'.format(uuId) 85 api.delete(url) 86 return True
Delete the File entity and its file data.
@classmethod
def
download_multiple(cls, list):
88 @classmethod 89 def download_multiple(cls, list): 90 """ 91 Given a list of File entities, return the file data held by 92 each as a `.zip` file. 93 """ 94 url = '/api/file/multidownload' 95 response = api.post(url, list, is_json=False) 96 return response.content
Given a list of File entities, return the file data held by
each as a .zip
file.
@classmethod
def
list(cls, expand=True):
98 @classmethod 99 def list(cls, expand=True): 100 """Return all files as a list""" 101 files = api.get('/api/file/list') 102 return [cls(f) for f in files]
Return all files as a list
Inherited Members
- projectal.entity.Entity
- history
- save
- clone
- match
- match_startswith
- match_endswith
- match_one
- match_startswith_one
- match_endswith_one
- search
- query
- profile_get
- profile_set
- changes
- set_readonly
- get_link_definitions
- entity_name
- builtins.dict
- setdefault
- pop
- popitem
- keys
- items
- values
- fromkeys
- clear
- copy