projectal.entities.folder
1from projectal.entity import Entity 2from projectal.linkers import * 3from projectal import api 4 5 6class Folder(Entity, FileLinker, FolderLinker, NoteLinker, TagLinker): 7 """ 8 Implementation of the [Folder](https://projectal.com/docs/latest/#tag/Folder) API. 9 """ 10 _path = 'folder' 11 _name = 'folder' 12 _links = [FileLinker, FolderLinker, NoteLinker, TagLinker] 13 14 def __init__(self, data): 15 super().__init__(data) 16 17 # TODO: override linker definition here due to differences in list name vs other file linkers. 18 # Remove if/when API is changed to address this. 19 class CustomFile(BaseLinker): 20 _link_name = 'file' 21 _link_key = 'files' 22 self._add_link_def(CustomFile) 23 24 @classmethod 25 def create(cls, entity): 26 payload = entity 27 endpoint = '/api/folder/add' 28 response = api.post(endpoint, payload) 29 entity['uuId'] = response['jobClue']['uuId'] 30 return cls(entity) 31 32 @classmethod 33 def get(cls, uuId, links=None): 34 """Get the File entity. No file data is included.""" 35 link_set = cls._get_linkset(links) 36 url = '/api/folder/get?uuId={}'.format(uuId) 37 if link_set: 38 url += '&links=' + ','.join(link_set) 39 return cls(api.get(url)) 40 41 @classmethod 42 def update(cls, entity): 43 payload = entity 44 api.put('/api/folder/update', payload) 45 return True 46 47 @classmethod 48 def delete(cls, uuId): 49 api.delete('/api/folder/delete/{}'.format(uuId)) 50 return True 51 52 53 @classmethod 54 def list(cls, expand=True): 55 """Return all folders as a list""" 56 folders = api.get('/api/folder/list') 57 return [cls(f) for f in folders]
7class Folder(Entity, FileLinker, FolderLinker, NoteLinker, TagLinker): 8 """ 9 Implementation of the [Folder](https://projectal.com/docs/latest/#tag/Folder) API. 10 """ 11 _path = 'folder' 12 _name = 'folder' 13 _links = [FileLinker, FolderLinker, NoteLinker, TagLinker] 14 15 def __init__(self, data): 16 super().__init__(data) 17 18 # TODO: override linker definition here due to differences in list name vs other file linkers. 19 # Remove if/when API is changed to address this. 20 class CustomFile(BaseLinker): 21 _link_name = 'file' 22 _link_key = 'files' 23 self._add_link_def(CustomFile) 24 25 @classmethod 26 def create(cls, entity): 27 payload = entity 28 endpoint = '/api/folder/add' 29 response = api.post(endpoint, payload) 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/folder/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): 44 payload = entity 45 api.put('/api/folder/update', payload) 46 return True 47 48 @classmethod 49 def delete(cls, uuId): 50 api.delete('/api/folder/delete/{}'.format(uuId)) 51 return True 52 53 54 @classmethod 55 def list(cls, expand=True): 56 """Return all folders as a list""" 57 folders = api.get('/api/folder/list') 58 return [cls(f) for f in folders]
Implementation of the Folder API.
25 @classmethod 26 def create(cls, entity): 27 payload = entity 28 endpoint = '/api/folder/add' 29 response = api.post(endpoint, payload) 30 entity['uuId'] = response['jobClue']['uuId'] 31 return cls(entity)
Create one or more entities of the same type. The entity type is determined by the subclass calling this method.
entities
: Can be a dict
to create a single entity,
or a list of dict
s to create many entities in bulk.
params
: Optional URL parameters that may apply to the
entity's API (e.g: ?holder=1234
).
If input was a dict
, returns an entity subclass. If input was
a list of dict
s, returns a list of entity subclasses.
# Example usage:
projectal.Customer.create({'name': 'NewCustomer'})
# returns Customer object
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/folder/get?uuId={}'.format(uuId) 38 if link_set: 39 url += '&links=' + ','.join(link_set) 40 return cls(api.get(url))
Get the File entity. No file data is included.
42 @classmethod 43 def update(cls, entity): 44 payload = entity 45 api.put('/api/folder/update', payload) 46 return True
Save one or more entities of the same type. The entity type is determined by the subclass calling this method. Only the fields that have been modifier will be sent to the server as part of the request.
entities
: Can be a dict
to update a single entity,
or a list of dict
s to update many entities in bulk.
Returns True
if all entities update successfully.
# Example usage:
rebate = projectal.Rebate.create({'name': 'Rebate2022', 'rebate': 0.2})
rebate['name'] = 'Rebate2024'
projectal.Rebate.update(rebate)
# Returns True. New rebate name has been saved.
48 @classmethod 49 def delete(cls, uuId): 50 api.delete('/api/folder/delete/{}'.format(uuId)) 51 return True
Delete one or more entities of the same type. The entity type is determined by the subclass calling this method.
entities
: See Entity.get()
for expected formats.
# Example usage:
ids = ['1b21e445-f29a...', '1b21e445-f29a...', '1b21e445-f29a...']
projectal.Customer.delete(ids)
54 @classmethod 55 def list(cls, expand=True): 56 """Return all folders as a list""" 57 folders = api.get('/api/folder/list') 58 return [cls(f) for f in folders]
Return all folders 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