Ejemplo n.º 1
0
def update(invoiceId, stationaryItemId, received=False, receivedFrom=None, receivedOfficeId=None, scannedImages=None):
    instance = get_by_id(invoiceId, stationaryItemId)

    # if scannedImages is not None:
    #     file = Image.create(fileSource=scannedImages)
    #     FolderFile.create(folderId=instance.receivedScannedFilesFolderId, fileId=file.fileId)

    # TODO support muliple images
    # https://github.com/zalando/connexion/issues/510

    if instance is None:
        raise NotFoundException("Invoice Stationary Item not found associated with the given invoiceId (%d, %d)"
                                % (invoiceId, stationaryItemId))
    else:
        if received is not None:
            instance.received = received
        if receivedFrom is not None:
            instance.receivedFrom = receivedFrom
        if receivedOfficeId is not None:
            instance.receivedOfficeId = receivedOfficeId

        if instance.received is True:
            Proof.update(
                proofId=instance.receivedProofId,
                finished=True
            )

        instance.receivedBy = Auth().get_user_id()
        instance.receivedAt = datetime.now()

        db.session.flush()

        return instance
Ejemplo n.º 2
0
    def __init__(self, historyId):
        super(HistoryVersionModel, self).__init__(
            historyId=historyId,
            createdBy=Auth().get_user_id(),
        )

        db.session.add(self)
        db.session.flush()
Ejemplo n.º 3
0
 def __init__(self, electionId, issuingOfficeId, receivingOfficeId,
              issuedTo):
     super(InvoiceModel, self).__init__(electionId=electionId,
                                        issuingOfficeId=issuingOfficeId,
                                        receivingOfficeId=receivingOfficeId,
                                        issuedTo=issuedTo,
                                        issuedBy=Auth().get_user_id(),
                                        issuedAt=datetime.now())
Ejemplo n.º 4
0
def registHandler():
    userName = request.form['userName']
    password = request.form['password']
    if len(userName) > 0 and len(password) > 0:
        auth = Auth.Autentication()
        token = auth.addUser(userName, password)
        return {"token": token}
    else:
        raise MdmException(4002, '用户名或密码不能为空')
def create(historyId):
    result = Model(
        historyId=historyId,
        createdBy=Auth().get_user_id(),
    )
    db.session.add(result)
    db.session.commit()

    return result
Ejemplo n.º 6
0
def create(electionId, issuingOfficeId, receivingOfficeId, issuedTo):
    result = Model(electionId=electionId,
                   issuingOfficeId=issuingOfficeId,
                   receivingOfficeId=receivingOfficeId,
                   issuedTo=issuedTo,
                   issuedBy=Auth().get_user_id(),
                   issuedAt=datetime.utcnow())

    db.session.add(result)
    db.session.commit()

    return result
Ejemplo n.º 7
0
def create_tallysheet_version(body, tallysheet):
    new_tallysheet_version = TallySheetVersionModel(
        tallySheetId=tallysheet.tallySheetId, createdBy=Auth().get_user_id())

    db.session.add(new_tallysheet_version)
    db.session.commit()

    tallysheet.latestVersion = new_tallysheet_version
    db.session.commit()

    if tallysheet.code == "PRE-41":
        return tallySheetPRE41Api.create(body, new_tallysheet_version)
    else:
        return new_tallysheet_version
Ejemplo n.º 8
0
def createReport(fileName, html):
    file = Model(fileType=FileTypeEnum.Pdf,
                 fileMimeType="application/pdf",
                 fileContentLength=len(html),
                 fileContentType="application/pdf ",
                 fileName=fileName,
                 fileCreatedBy=Auth().get_user_id())

    db.session.add(file)
    db.session.commit()

    options = {}
    file_path = os.path.join(FILE_DIRECTORY, str(file.fileId))
    pdfkit.from_string(html, file_path, options=options)

    return file
Ejemplo n.º 9
0
def authenticate():
    if request.method == 'POST':
        opr = request.form['opr']

        # print(str(opr)+"\t"+str(userName)+"\t"+str(password))
        auth = Auth.Autentication()
        if opr == "login":
            userName = request.form['userName']
            password = request.form['password']
            token = auth.verifyUser(userName, password)
            if token:
                return [{"token": token}, 4001, "login success"]
            else:
                raise MdmException(4002, "login failed")
        else:
            auth.deleteToken(request.form['password'])
            return [{"token": "None"}, 4003, "token change"]
Ejemplo n.º 10
0
def createFromFileSource(fileSource, fileType=FileTypeEnum.Any):
    # TODO validate the
    #   - file type
    #   - file size
    #         etc.

    if fileType is None:
        fileType = FileTypeEnum.Any

    result = Model(fileType=fileType,
                   fileMimeType=fileSource.mimetype,
                   fileContentLength=fileSource.content_length,
                   fileContentType=fileSource.content_type,
                   fileName=fileSource.filename,
                   fileCreatedBy=Auth().get_user_id())

    db.session.add(result)
    db.session.commit()

    save_uploaded_file_source(result, fileSource)

    return result