projectal.entities.file API documentation

# projectal.entities.file

View Source

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

      7class File(
      8    Entity,
      9    CompanyLinker,
     10    CustomerLinker,
     11    FolderLinker,
     12    ProjectLinker,
     13    StaffLinker,
     14    TaskLinker,
     15    TaskTemplateLinker,
     16    NoteLinker,
     17    TagLinker,
     18):
     19    """
     20    Implementation of the [File](https://projectal.com/docs/latest/#tag/File) API.
     21    """
     22
     23    _path = "file"
     24    _name = "file"
     25    _links = [NoteLinker, TagLinker]
     26    _links_reverse = [
     27        CompanyLinker,
     28        CustomerLinker,
     29        FolderLinker,
     30        ProjectLinker,
     31        StaffLinker,
     32        TaskLinker,
     33        TaskTemplateLinker,
     34    ]
     35
     36    @classmethod
     37    def create(cls, file_data, entity):
     38        """
     39        Create a File entity with file data.
     40
     41        `file_data` is the raw file data in bytes
     42
     43        `entity` is the File entity and its fields.
     44        """
     45        payload = entity
     46        url = "/api/file/upload"
     47        file = {"file": file_data}
     48        response = api.post(url, payload, file=file)
     49        entity["uuId"] = response["jobClue"]["uuId"]
     50        return cls(entity)
     51
     52    @classmethod
     53    def get(cls, uuId, links=None):
     54        """Get the File entity. No file data is included."""
     55        link_set = cls._get_linkset(links)
     56        url = "/api/file/get?uuId={}".format(uuId)
     57        if link_set:
     58            url += "&links=" + ",".join(link_set)
     59        return cls(api.get(url))
     60
     61    @classmethod
     62    def update(cls, entity, file_data=None):
     63        """
     64        Update the File entity. Optionally, also update the
     65        file data that this File holds.
     66        """
     67        payload = entity
     68        url = "/api/file/update"
     69        if file_data:
     70            file = {"file": file_data}
     71            api.put(url, payload, file=file)
     72        else:
     73            api.put(url, payload, form=True)
     74
     75    @classmethod
     76    def get_file_data(cls, uuId):
     77        """
     78        Get the file data that is held by the file with `uuId`.
     79        Returns the raw content of the response.
     80        """
     81        url = "/api/file/{}".format(uuId)
     82        response = api.get(url, is_json=False)
     83        return response.content
     84
     85    @classmethod
     86    def download_to_browser(cls, uuId):
     87        """
     88        Get the file data that is held by the file with `uuId`.
     89        Returns the response object which will have headers suitable
     90        to initiate a download by the user agent.
     91        """
     92        url = "/api/file/download"
     93        payload = {"uuId": uuId}
     94        response = api.post(url, payload, is_json=False)
     95        return response
     96
     97    @classmethod
     98    def delete(cls, uuId):
     99        """
    100        Delete the File entity and its file data.
    101        """
    102        url = "/api/file/delete/{}".format(uuId)
    103        api.delete(url)
    104        return True
    105
    106    @classmethod
    107    def download_multiple(cls, list):
    108        """
    109        Given a list of File entities, return the file data held by
    110        each as a `.zip` file.
    111        """
    112        url = "/api/file/multidownload"
    113        response = api.post(url, list, is_json=False)
    114        return response.content
    115
    116    @classmethod
    117    def list(cls, expand=True):
    118        """Return all files as a list"""
    119        files = api.get("/api/file/list")
    120        return [cls(f) for f in files]

Implementation of the File API.

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

    36    @classmethod
    37    def create(cls, file_data, entity):
    38        """
    39        Create a File entity with file data.
    40
    41        `file_data` is the raw file data in bytes
    42
    43        `entity` is the File entity and its fields.
    44        """
    45        payload = entity
    46        url = "/api/file/upload"
    47        file = {"file": file_data}
    48        response = api.post(url, payload, file=file)
    49        entity["uuId"] = response["jobClue"]["uuId"]
    50        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

    52    @classmethod
    53    def get(cls, uuId, links=None):
    54        """Get the File entity. No file data is included."""
    55        link_set = cls._get_linkset(links)
    56        url = "/api/file/get?uuId={}".format(uuId)
    57        if link_set:
    58            url += "&links=" + ",".join(link_set)
    59        return cls(api.get(url))

Get the File entity. No file data is included.

@classmethod
def update(cls, entity, file_data=None): View Source

    61    @classmethod
    62    def update(cls, entity, file_data=None):
    63        """
    64        Update the File entity. Optionally, also update the
    65        file data that this File holds.
    66        """
    67        payload = entity
    68        url = "/api/file/update"
    69        if file_data:
    70            file = {"file": file_data}
    71            api.put(url, payload, file=file)
    72        else:
    73            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

    75    @classmethod
    76    def get_file_data(cls, uuId):
    77        """
    78        Get the file data that is held by the file with `uuId`.
    79        Returns the raw content of the response.
    80        """
    81        url = "/api/file/{}".format(uuId)
    82        response = api.get(url, is_json=False)
    83        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

    85    @classmethod
    86    def download_to_browser(cls, uuId):
    87        """
    88        Get the file data that is held by the file with `uuId`.
    89        Returns the response object which will have headers suitable
    90        to initiate a download by the user agent.
    91        """
    92        url = "/api/file/download"
    93        payload = {"uuId": uuId}
    94        response = api.post(url, payload, is_json=False)
    95        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

     97    @classmethod
     98    def delete(cls, uuId):
     99        """
    100        Delete the File entity and its file data.
    101        """
    102        url = "/api/file/delete/{}".format(uuId)
    103        api.delete(url)
    104        return True

Delete the File entity and its file data.

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

    106    @classmethod
    107    def download_multiple(cls, list):
    108        """
    109        Given a list of File entities, return the file data held by
    110        each as a `.zip` file.
    111        """
    112        url = "/api/file/multidownload"
    113        response = api.post(url, list, is_json=False)
    114        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

    116    @classmethod
    117    def list(cls, expand=True):
    118        """Return all files as a list"""
    119        files = api.get("/api/file/list")
    120        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
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
projectal.linkers.TagLinker
  link_tag
  unlink_tag