How to use the paperwork-backend.paperwork_backend.common.doc.BasicDoc function in paperwork-backend

To help you get started, we’ve selected a few paperwork-backend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
return self.__pages[idx]

    def __len__(self):
        return self.doc.nb_pages

    def __contains__(self, page):
        return (page.doc == self.doc and page.page_nb <= self.doc.nb_pages)

    def __eq__(self, other):
        return (self.doc == other.doc)

    def __iter__(self):
        return _ImgPagesIterator(self)


class ImgDoc(BasicDoc):

    """
    Represents a document (aka a set of pages + labels).
    """
    IMPORT_IMG_EXTENSIONS = [
        ".jpg",
        ".jpeg",
        ".png"
    ]
    can_edit = True
    doctype = u"Img"

    def __init__(self, fs, docpath, docid=None):
        """
        Arguments:
            docpath --- For an existing document, the path to its folder. For
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / pdf / doc.py View on Github external
self.on_disk_cache = on_disk_cache

    def __getitem__(self, idx):
        if idx < 0:
            idx = self.pdf.get_n_pages() + idx
        return PdfPage(self.pdfdoc, idx,
                       self.on_disk_cache)

    def __len__(self):
        return self.pdf.get_n_pages()

    def __iter__(self):
        return PdfPagesIterator(self.pdfdoc)


class _CommonPdfDoc(BasicDoc):
    can_edit = False
    doctype = u"PDF"

    def __init__(self, fs, pdfpath, docpath, docid=None, on_disk_cache=False):
        super().__init__(fs, docpath, docid)
        self.pdfpath = fs.safe(pdfpath)
        self._on_disk_cache = on_disk_cache
        # number of pages never change --> we can keep it in memory safely
        self._nb_pages = -1
        # page sizes never change --> we can keep them in memory safely
        self._page_sizes = None

    def clone(self):
        assert()

    def _get_last_mod(self):
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
def __get_last_mod(self):
        last_mod = 0.0
        for page in self.pages:
            if last_mod < page.last_mod:
                last_mod = page.last_mod
        labels_path = self.fs.join(self.path, BasicDoc.LABEL_FILE)
        try:
            file_last_mod = self.fs.getmtime(labels_path)
            if file_last_mod > last_mod:
                last_mod = file_last_mod
        except OSError:
            pass
        extra_txt_path = self.fs.join(self.path, BasicDoc.EXTRA_TEXT_FILE)
        try:
            file_last_mod = self.fs.getmtime(extra_txt_path)
            if file_last_mod > last_mod:
                last_mod = file_last_mod
        except OSError:
            pass
        return last_mod