Exemplo n.º 1
0
def upload_file(proofId, fileSource, fileType):
    proof = get_by_id(proofId=proofId)

    if proof is None:
        raise NotFoundException(
            message="Proof not found associated with the given proofId (proofId=%d)" % proofId,
            code=MESSAGE_CODE_PROOF_NOT_FOUND
        )
    elif proof.finished is True:
        raise ForbiddenException(
            message="No more evidence is accepted for this proof (proofId=%d)" % proofId,
            code=MESSAGE_CODE_PROOF_NOT_MORE_EVIDENCE_ACCEPTED
        )
    else:
        file = File.createFromFileSource(
            fileSource=fileSource,
            fileType=fileType
        )

        FolderFile.create(
            folderId=proof.scannedFilesFolderId,
            fileId=file.fileId
        )

        return proof
Exemplo n.º 2
0
def response_file(fileId, as_attachment):
    file = Model.get_by_id(fileId=fileId)

    fileName = "%d-%s" % (file.fileId, file.fileName)

    return send_file(BytesIO(file.fileContent),
                     mimetype=file.fileMimeType,
                     attachment_filename=fileName,
                     as_attachment=as_attachment)
Exemplo n.º 3
0
def response_file(fileId, as_attachment):
    file = Model.get_by_id(fileId=fileId)

    fileName = "%d-%s" % (file.fileId, file.fileName)

    return send_from_directory(directory=FILE_DIRECTORY,
                               filename=str(file.fileId),
                               mimetype=file.fileMimeType,
                               attachment_filename=fileName,
                               as_attachment=as_attachment)
def upload_file(proofId, fileSource, fileType):
    proof = get_by_id(proofId=proofId)

    if proof is None:
        raise NotFoundException(
            "Proof not found associated with the given proofId (proofId=%d)" %
            proofId)
    elif proof.finished is True:
        raise ForbiddenException(
            "No more evidence is accepted for this proof (proofId=%d)" %
            proofId)
    else:
        file = File.createFromFileSource(fileSource=fileSource,
                                         fileType=fileType)

        FolderFile.create(folderId=proof.scannedFilesFolderId,
                          fileId=file.fileId)

        return proof
Exemplo n.º 5
0
    def get_exported_pdf_file_id(cls, tallySheetId, tallySheetVersionId):
        tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId)
        tallySheetVersion = cls.get_by_id(tallySheetId, tallySheetVersionId)

        if tallySheetVersion.exportedPdfFileId is None:
            tally_sheet_version_pdf_content = html_to_pdf(html=str(
                tallySheet.html(tallySheetVersionId=tallySheetVersionId)))
            tally_sheet_version_pdf_file = File.create(
                fileMimeType="application/pdf",
                fileContentLength=len(tally_sheet_version_pdf_content),
                fileContentType="application/pdf",
                fileContent=tally_sheet_version_pdf_content,
                fileName="%d-%d" % (tallySheetId, tallySheetVersionId))

            tallySheetVersion.exportedPdfFileId = tally_sheet_version_pdf_file.fileId

            db.session.add(tallySheetVersion)
            db.session.flush()

        return tallySheetVersion.exportedPdfFileId
Exemplo n.º 6
0
    def get_exported_letter_pdf_file_id(cls, tallySheetId, tallySheetVersionId,
                                        signatures):
        tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId)
        tallySheetVersion = cls.get_by_id(tallySheetId, tallySheetVersionId)

        # Disable persistence check since the addition of signatures creates different letters.
        # if tallySheetVersion.exportedLetterPdfFileId is None:
        tally_sheet_version_letter_pdf_content = html_to_pdf(html=str(
            tallySheet.html_letter(tallySheetVersionId=tallySheetVersionId,
                                   signatures=signatures)))
        tally_sheet_version_letter_pdf_file = File.create(
            fileMimeType="application/pdf",
            fileContentLength=len(tally_sheet_version_letter_pdf_content),
            fileContentType="application/pdf",
            fileContent=tally_sheet_version_letter_pdf_content,
            fileName="%d-%d" % (tallySheetId, tallySheetVersionId))

        tallySheetVersion.exportedLetterPdfFileId = tally_sheet_version_letter_pdf_file.fileId

        db.session.add(tallySheetVersion)
        db.session.flush()

        return tallySheetVersion.exportedLetterPdfFileId
Exemplo n.º 7
0
def get_by_id(fileId):
    result = Model.get_by_id(fileId=fileId)

    return Schema().dump(result).data
Exemplo n.º 8
0
 def set_number_of_seats_dataset(self, fileSource):
     dataset = File.createFromFileSource(fileSource=fileSource)
     self.numberOfSeatsDatasetId = dataset.fileId
Exemplo n.º 9
0
 def set_invalid_vote_categories_dataset(self, fileSource):
     dataset = File.createFromFileSource(fileSource=fileSource)
     self.invalidVoteCategoriesDatasetId = dataset.fileId
Exemplo n.º 10
0
 def set_party_candidates_dataset(self, fileSource):
     dataset = File.createFromFileSource(fileSource=fileSource)
     self.partyCandidateDatasetId = dataset.fileId
Exemplo n.º 11
0
 def set_postal_counting_centres_dataset(self, fileSource):
     dataset = File.createFromFileSource(fileSource=fileSource)
     self.postalCountingCentresDatasetId = dataset.fileId
Exemplo n.º 12
0
 def set_polling_stations_dataset(self, fileSource):
     dataset = File.createFromFileSource(fileSource=fileSource)
     self.pollingStationsDatasetId = dataset.fileId
Exemplo n.º 13
0
def create(fileSource):
    return File.create(fileSource=fileSource, fileType=FileTypeEnum.Image)