projectal.entities.file API documentation

# projectal.entities.file

View Source

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

    class File(Entity, CompanyLinker, CustomerLinker, FolderLinker, ProjectLinker,
               StaffLinker, TaskLinker, TaskTemplateLinker, NoteLinker):
        """
        Implementation of the [File](https://projectal.com/docs/latest/#tag/File) API.
        """
        _path = 'file'
        _name = 'file'
        _links = [NoteLinker]
        _links_reverse = [CompanyLinker, CustomerLinker, FolderLinker, ProjectLinker,
                          StaffLinker, TaskLinker, TaskTemplateLinker]

        @classmethod
        def create(cls, file_data, 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.
            """
            payload = entity
            url = '/api/file/upload'
            file = {'file': file_data}
            response = api.post(url, payload, file=file)
            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/file/get?uuId={}'.format(uuId)
            if link_set:
                url += '&links=' + ','.join(link_set)
            return cls(api.get(url))

        @classmethod
        def update(cls, entity, file_data=None):
            """
            Update the File entity. Optionally, also update the
            file data that this File holds.
            """
            payload = entity
            url = '/api/file/update'
            if file_data:
                file = {'file': file_data}
                api.put(url, payload, file=file)
            else:
                api.put(url, payload, form=True)

        @classmethod
        def get_file_data(cls, uuId):
            """
            Get the file data that is held by the file with `uuId`.
            Returns the raw content of the response.
            """
            url = '/api/file/{}'.format(uuId)
            response = api.get(url, is_json=False)
            return response.content

        @classmethod
        def download_to_browser(cls, uuId):
            """
            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.
            """
            url = '/api/file/download'
            payload = {'uuId': uuId}
            response = api.post(url, payload, is_json=False)
            return response

        @classmethod
        def delete(cls, uuId):
            """
            Delete the File entity and its file data.
            """
            url = '/api/file/delete/{}'.format(uuId)
            api.delete(url)
            return True

        @classmethod
        def download_multiple(cls, list):
            """
            Given a list of File entities, return the file data held by
            each as a `.zip` file.
            """
            url = '/api/file/multidownload'
            response = api.post(url, list, is_json=False)
            return response.content

        @classmethod
        def list(cls, expand=True):
            """Return all files as a list"""
            files = api.get('/api/file/list')
            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):
View Source

    class File(Entity, CompanyLinker, CustomerLinker, FolderLinker, ProjectLinker,
               StaffLinker, TaskLinker, TaskTemplateLinker, NoteLinker):
        """
        Implementation of the [File](https://projectal.com/docs/latest/#tag/File) API.
        """
        _path = 'file'
        _name = 'file'
        _links = [NoteLinker]
        _links_reverse = [CompanyLinker, CustomerLinker, FolderLinker, ProjectLinker,
                          StaffLinker, TaskLinker, TaskTemplateLinker]

        @classmethod
        def create(cls, file_data, 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.
            """
            payload = entity
            url = '/api/file/upload'
            file = {'file': file_data}
            response = api.post(url, payload, file=file)
            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/file/get?uuId={}'.format(uuId)
            if link_set:
                url += '&links=' + ','.join(link_set)
            return cls(api.get(url))

        @classmethod
        def update(cls, entity, file_data=None):
            """
            Update the File entity. Optionally, also update the
            file data that this File holds.
            """
            payload = entity
            url = '/api/file/update'
            if file_data:
                file = {'file': file_data}
                api.put(url, payload, file=file)
            else:
                api.put(url, payload, form=True)

        @classmethod
        def get_file_data(cls, uuId):
            """
            Get the file data that is held by the file with `uuId`.
            Returns the raw content of the response.
            """
            url = '/api/file/{}'.format(uuId)
            response = api.get(url, is_json=False)
            return response.content

        @classmethod
        def download_to_browser(cls, uuId):
            """
            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.
            """
            url = '/api/file/download'
            payload = {'uuId': uuId}
            response = api.post(url, payload, is_json=False)
            return response

        @classmethod
        def delete(cls, uuId):
            """
            Delete the File entity and its file data.
            """
            url = '/api/file/delete/{}'.format(uuId)
            api.delete(url)
            return True

        @classmethod
        def download_multiple(cls, list):
            """
            Given a list of File entities, return the file data held by
            each as a `.zip` file.
            """
            url = '/api/file/multidownload'
            response = api.post(url, list, is_json=False)
            return response.content

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

Implementation of the File API.

@classmethod
def create(cls, file_data, entity):
View Source

        @classmethod
        def create(cls, file_data, 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.
            """
            payload = entity
            url = '/api/file/upload'
            file = {'file': file_data}
            response = api.post(url, payload, file=file)
            entity['uuId'] = response['jobClue']['uuId']
            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):
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/file/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, file_data=None):
View Source

        @classmethod
        def update(cls, entity, file_data=None):
            """
            Update the File entity. Optionally, also update the
            file data that this File holds.
            """
            payload = entity
            url = '/api/file/update'
            if file_data:
                file = {'file': file_data}
                api.put(url, payload, file=file)
            else:
                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):
View Source

        @classmethod
        def get_file_data(cls, uuId):
            """
            Get the file data that is held by the file with `uuId`.
            Returns the raw content of the response.
            """
            url = '/api/file/{}'.format(uuId)
            response = api.get(url, is_json=False)
            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):
View Source

        @classmethod
        def download_to_browser(cls, uuId):
            """
            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.
            """
            url = '/api/file/download'
            payload = {'uuId': uuId}
            response = api.post(url, payload, is_json=False)
            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):
View Source

        @classmethod
        def delete(cls, uuId):
            """
            Delete the File entity and its file data.
            """
            url = '/api/file/delete/{}'.format(uuId)
            api.delete(url)
            return True

Delete the File entity and its file data.

@classmethod
def download_multiple(cls, list):
View Source

        @classmethod
        def download_multiple(cls, list):
            """
            Given a list of File entities, return the file data held by
            each as a `.zip` file.
            """
            url = '/api/file/multidownload'
            response = api.post(url, list, is_json=False)
            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):
View Source

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

Return all files as a list

##### Inherited Members

projectal.entity.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
  entity_name
projectal.linkers.CompanyLinker
  link_company
  unlink_company
projectal.linkers.CustomerLinker
  link_customer
  unlink_customer
projectal.linkers.FolderLinker
  link_folder
  unlink_folder
projectal.linkers.ProjectLinker
  link_project
  unlink_project
projectal.linkers.StaffLinker
  link_staff
  relink_staff
  unlink_staff
projectal.linkers.TaskLinker
  link_task
  unlink_task
projectal.linkers.TaskTemplateLinker
  link_task_template
  unlink_task_template
builtins.dict
  setdefault
  pop
  popitem
  keys
  items
  values
  fromkeys
  clear
  copy