projectal.entities.folder

View Source
from projectal.entity import Entity
from projectal.linkers import *
from projectal import api


class Folder(Entity, FolderLinker, FileLinker):
    """
    Implementation of the [Folder](https://projectal.com/docs/latest/#tag/Folder) API.
    """
    _path = 'folder'
    _name = 'STORAGE_FOLDER'

    @classmethod
    def create(cls, entity):
        payload = entity
        endpoint = '/api/folder/add'
        response = api.post(endpoint, payload)
        entity['uuId'] = response['jobClue']['uuId'];
        return cls(entity)

    @classmethod
    def get(cls, uuId):
        return cls(api.get('/api/folder/get?uuId={}'.format(uuId)))

    @classmethod
    def update(cls, entity):
        payload = entity
        api.put('/api/folder/update', payload)
        return True

    @classmethod
    def delete(cls, uuId):
        api.delete('/api/folder/delete/{}'.format(uuId))
        return True

    # TODO: reimplemented here due to differences in list name vs other file linkers.
    # Remove in future if/when api is fixed
    def link_file(self, file):
        self._add_link(self['uuId'], 'file', [file], list_name='files')

    def unlink_file(self,  file):
        self._delete_link(self['uuId'], 'file', [file], list_name='files')

    @classmethod
    def list(cls):
        """Return all folders as a list"""
        folders = api.get('/api/folder/list')
        return [cls(f) for f in folders]
View Source
class Folder(Entity, FolderLinker, FileLinker):
    """
    Implementation of the [Folder](https://projectal.com/docs/latest/#tag/Folder) API.
    """
    _path = 'folder'
    _name = 'STORAGE_FOLDER'

    @classmethod
    def create(cls, entity):
        payload = entity
        endpoint = '/api/folder/add'
        response = api.post(endpoint, payload)
        entity['uuId'] = response['jobClue']['uuId'];
        return cls(entity)

    @classmethod
    def get(cls, uuId):
        return cls(api.get('/api/folder/get?uuId={}'.format(uuId)))

    @classmethod
    def update(cls, entity):
        payload = entity
        api.put('/api/folder/update', payload)
        return True

    @classmethod
    def delete(cls, uuId):
        api.delete('/api/folder/delete/{}'.format(uuId))
        return True

    # TODO: reimplemented here due to differences in list name vs other file linkers.
    # Remove in future if/when api is fixed
    def link_file(self, file):
        self._add_link(self['uuId'], 'file', [file], list_name='files')

    def unlink_file(self,  file):
        self._delete_link(self['uuId'], 'file', [file], list_name='files')

    @classmethod
    def list(cls):
        """Return all folders as a list"""
        folders = api.get('/api/folder/list')
        return [cls(f) for f in folders]

Implementation of the Folder API.

#  
@classmethod
def create(cls, entity):
View Source
    @classmethod
    def create(cls, entity):
        payload = entity
        endpoint = '/api/folder/add'
        response = api.post(endpoint, payload)
        entity['uuId'] = response['jobClue']['uuId'];
        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 dicts 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 dicts, returns a list of entity subclasses.

# Example usage:
projectal.Customer.create({'name': 'NewCustomer'})
# returns Customer object
#  
@classmethod
def get(cls, uuId):
View Source
    @classmethod
    def get(cls, uuId):
        return cls(api.get('/api/folder/get?uuId={}'.format(uuId)))

Get one or more entities of the same type. The entity type is determined by the subclass calling this method.

entities: One of several formats containing the uuIds of the entities you want to get (see bottom for examples):

  • str or list of str
  • dict or list of dict (with uuId key)

links: Optional URL parameter to request entity links as part of the response (e.g: ?links=COMPANY,LOCATION,). For performance reasons, links are only returned on demand.

Links follow a common naming convention in the output with a _List suffix. E.g.: ?links=COMPANY,LOCATION will appear as companyList and locationList in the response.

# Example usage:
# str
projectal.Project.get('1b21e445-f29a-4a9f-95ff-fe253a3e1b11')

# list of str
ids = ['1b21e445-f29a...', '1b21e445-f29a...', '1b21e445-f29a...']
projectal.Project.get(ids)

# dict
project = project.Project.create({'name': 'MyProject'})
# project = {'uuId': '1b21e445-f29a...', 'name': 'MyProject', ...}
projectal.Project.get(project)

# list of dicts (e.g. from a query)
# projects = [{'uuId': '1b21e445-f29a...'}, {'uuId': '1b21e445-f29a...'}, ...]
project.Project.get(projects)

# str with links
projectal.Project.get('1b21e445-f29a...', 'links=COMPANY,LOCATION')
#  
@classmethod
def update(cls, entity):
View Source
    @classmethod
    def update(cls, entity):
        payload = entity
        api.put('/api/folder/update', payload)
        return True

Save 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 update a single entity, or a list of dicts 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.
#  
@classmethod
def delete(cls, uuId):
View Source
    @classmethod
    def delete(cls, uuId):
        api.delete('/api/folder/delete/{}'.format(uuId))
        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)
#  
@classmethod
def list(cls):
View Source
    @classmethod
    def list(cls):
        """Return all folders as a list"""
        folders = api.get('/api/folder/list')
        return [cls(f) for f in folders]

Return all folders as a list

Inherited Members
projectal.entity.Entity
Entity
save
clone
history
match
match_startswith
match_endswith
search
query
projectal.linkers.FolderLinker
builtins.dict
setdefault
pop
popitem
keys
items
values
fromkeys
clear
copy