projectal.entities.folder

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


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

    def __init__(self, data):
        super().__init__(data)

        # TODO: override linker definition here due to differences in list name vs other file linkers.
        # Remove if/when API is changed to address this.
        class CustomFile(BaseLinker):
            _link_name = 'file'
            _link_key = 'files'
        self._add_link_def(CustomFile)

    @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, links=None):
        """Get the File entity. No file data is included."""
        link_set = cls._get_linkset(links)
        url = '/api/folder/get?uuId={}'.format(uuId)
        if link_set:
            url += '&links=' + ','.join(link_set)
        return cls(api.get(url))

    @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


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

    def __init__(self, data):
        super().__init__(data)

        # TODO: override linker definition here due to differences in list name vs other file linkers.
        # Remove if/when API is changed to address this.
        class CustomFile(BaseLinker):
            _link_name = 'file'
            _link_key = 'files'
        self._add_link_def(CustomFile)

    @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, links=None):
        """Get the File entity. No file data is included."""
        link_set = cls._get_linkset(links)
        url = '/api/folder/get?uuId={}'.format(uuId)
        if link_set:
            url += '&links=' + ','.join(link_set)
        return cls(api.get(url))

    @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


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

Implementation of the Folder API.

#   Folder(data)
View Source
    def __init__(self, data):
        super().__init__(data)

        # TODO: override linker definition here due to differences in list name vs other file linkers.
        # Remove if/when API is changed to address this.
        class CustomFile(BaseLinker):
            _link_name = 'file'
            _link_key = 'files'
        self._add_link_def(CustomFile)
#  
@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, links=None):
View Source
    @classmethod
    def get(cls, uuId, links=None):
        """Get the File entity. No file data is included."""
        link_set = cls._get_linkset(links)
        url = '/api/folder/get?uuId={}'.format(uuId)
        if link_set:
            url += '&links=' + ','.join(link_set)
        return cls(api.get(url))

Get the File entity. No file data is included.

#  
@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. 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 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, expand=True):
View Source
    @classmethod
    def list(cls, expand=True):
        """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