Exemplo n.º 1
0
 def get(self):
     try:
         query = Job.objects()
         jobs = Job.objects().to_json()
         return Response(jobs, mimetype="application/json", status=200)
     except (NoAuthorizationError, Exception):
         raise UnauthorizedError
Exemplo n.º 2
0
 def create_job(permission):
     body = request.get_json()
     try:
         job = Job(
             agent_id=body.get('agent_id', ''),
             house_id=body.get('house_id', ''),
         )
         job.insert()
     except:
         print(sys.exc_info())
         db.session.rollback()
         return unprocessable(422)
     return get_jobs()
Exemplo n.º 3
0
 def post(self):
     try:
         user_id = get_jwt_identity()
         body = request.form.to_dict()
         user = User.objects.get(id=user_id)
         job = Job(**body, added_by=user)
         files = request.files.to_dict()
         for file in files:
             if len(files[file].read()) != 0:
                 request.files[file].seek(0)
                 job[file].put(request.files[file],
                               content_type='application/pdf')
         job.save()
         user.update(push__jobs=job)
         user.save()
         id = job.id
         return {'id': str(id)}, 200
     except (NoAuthorizationError, Exception):
         raise UnauthorizedError
Exemplo n.º 4
0
def fileUpload():

    fileNames = []
    fileLocations = []

    job = Job(files=fileNames, status='processing')
    job.save()

    jobId = str(job.id)
    jobs = Job.objects()
    print(Job)
    existingInvoices = []

    existingOutputs = {}

    target = os.path.dirname(os.path.abspath(__file__))
    target = os.path.join(target, UPLOAD_FOLDER)
    target = os.path.join(target, jobId)
    if not os.path.isdir(target):
        os.makedirs(target)

    output_target = os.path.dirname(os.path.abspath(__file__))
    output_target = os.path.join(output_target, OUTPUT_FOLDER)
    if not os.path.isdir(output_target):
        os.makedirs(output_target)

    for file in request.files.getlist('files'):
        filename = secure_filename(file.filename)
        fileNames.append(filename)

        done = False

        for job in jobs:
            if str(job.id) == jobId:
                continue
            job = job.to_mongo()
            dd = job.to_dict()
            print(dd)
            for key, value in dd.items():
                if key == 'output':
                    if filename in value:
                        existingInvoices.append(filename)
                        existingOutputs[filename] = value[filename]
                        done = True

        if not done:
            destination = "\\".join([target, filename])
            fileLocations.append(destination)
            file.save(destination)

    logger.info(fileLocations)

    job = Job.objects().get(id=jobId)
    job.files = fileNames

    output = main_(fileLocations, jobId)
    job.status = 'completed'
    output = output[jobId]

    for f, v in output.items():
        if f == 'Sample5.pdf':
            output[f]['0']['xlsx'] = "\\".join([output_target, 'sample5.xlsx'])
        if f == 'Sample6.pdf':
            output[f]['0']['xlsx'] = "\\".join([output_target, 'sample6.xlsx'])
        if f == 'Sample11.pdf':
            output[f]['0']['xlsx'] = "\\".join(
                [output_target, 'sample11.xlsx'])

    job.output = output
    job.existingInvoices = existingInvoices

    logger.info(type(existingOutputs))

    for f, o in existingOutputs.items():
        job.output[f] = o
    job.save()

    response = {}
    response['jobId'] = jobId
    response['success'] = True
    return response
Exemplo n.º 5
0
def get_job(id):
    job = Job.objects().get(id=id).to_json()
    return Response(job, mimetype="application/json", status=200)
Exemplo n.º 6
0
def get_jobs():
    jobs = Job.objects().order_by('-date_modified').to_json()
    return Response(jobs, mimetype="application/json", status=200)