示例#1
0
def excel_update(entity_id):
    finvis.aaa.require(fail_redirect='/sorry_page')

    obj = Entity.objects(id=entity_id).only('id', 'version')[0]

    # you can only update your own private documents, unless you're admin
    # public docs are protected
    if (obj.username != finvis.aaa.current_user.username or
        obj.public is False) and \
            finvis.aaa.current_user.role != 'admin':
        return 'Error: you may not update that document.'

    excelfile = request.files.get('excelfile')

    if excelfile is None:
        response.status = 422
        return 'Error: No file sent. Please submit a file.'

    try:
        newobj = excel.import_excel(excelfile.file.read(),
                                    finvis.aaa.current_user.username)
    except excel.ExcelError as e:
        response.status = 422
        return 'Error: ' + e.message

    newobj.id = obj.id
    newobj.version = obj.version + 1
    newobj.save()

    redirect('/index.html/' + str(obj.id))
示例#2
0
def excel_update(entity_id):
    finvis.aaa.require(fail_redirect='/sorry_page')

    obj = Entity.objects(id=entity_id).only('id', 'version')[0]

    # you can only update your own private documents, unless you're admin
    # public docs are protected
    if (obj.username != finvis.aaa.current_user.username or
        obj.public is False) and \
            finvis.aaa.current_user.role != 'admin':
        return 'Error: you may not update that document.'

    excelfile = request.files.get('excelfile')

    if excelfile is None:
        response.status = 422
        return 'Error: No file sent. Please submit a file.'

    try:
        newobj = excel.import_excel(excelfile.file.read(),
                                    finvis.aaa.current_user.username)
    except excel.ExcelError as e:
        response.status = 422
        return 'Error: ' + e.message

    newobj.id = obj.id
    newobj.version = obj.version + 1
    newobj.save()

    redirect('/index.html/' + str(obj.id))
示例#3
0
 def test_Item(self):
     item = open(os.path.join(self.rootdir, 'transportandcoms.xls'),
                 'r').read()
     assert_equal(
         bson.json_util.dumps(excel.import_excel(item).to_mongo()),
         open(os.path.join(self.rootdir, 'transportandcoms.json'),
              'r').read())
示例#4
0
def excel_to_json():
    """Return the uploaded excel file as a JSON document."""
    response.content_type = 'text/json'

    excelfile = request.files.get('excelfile')

    if excelfile is None:
        response.status = 422
        return {'error': 'No file detected. Please chose a file to upload.'}

    try:
        obj = excel.import_excel(excelfile.file.read(), 'anonymous')
    except excel.ExcelError as e:
        response.status = 422
        return {'error': str(e)}

    result = bson.json_util.dumps(obj.to_mongo())
    return result
示例#5
0
def excel_to_json():
    """Return the uploaded excel file as a JSON document."""
    response.content_type = 'text/json'

    excelfile = request.files.get('excelfile')

    if excelfile is None:
        response.status = 422
        return {'error': 'No file detected. Please chose a file to upload.'}

    try:
        obj = excel.import_excel(excelfile.file.read(), 'anonymous')
    except excel.ExcelError as e:
        response.status = 422
        return {'error': str(e)}

    result = bson.json_util.dumps(obj.to_mongo())
    return result
示例#6
0
def excel_upload():
    """Upload the file to the DB."""

    finvis.aaa.require(fail_redirect="/login")

    excelfile = request.files.get('excelfile')

    if excelfile is None:
        response.status = 422
        return 'Error: No file sent. Please submit a file.'

    try:
        obj = excel.import_excel(excelfile.file.read(),
                                 finvis.aaa.current_user.username)
    except excel.ExcelError as e:
        response.status = 422
        return 'Error: ' + e.message

    obj.save()

    target = request.headers.get('Referer', '/').strip()
    redirect(target)
示例#7
0
def excel_upload():
    """Upload the file to the DB."""

    finvis.aaa.require(fail_redirect="/login")

    excelfile = request.files.get('excelfile')

    if excelfile is None:
        response.status = 422
        return 'Error: No file sent. Please submit a file.'

    try:
        obj = excel.import_excel(excelfile.file.read(),
                                 finvis.aaa.current_user.username)
    except excel.ExcelError as e:
        response.status = 422
        return 'Error: ' + e.message

    obj.save()

    target = request.headers.get('Referer', '/').strip()
    redirect(target)
示例#8
0
 def test_Aggregate(self):
     aggregate = open(os.path.join(self.rootdir, 'cth-fbo.xls'), 'r').read()
     assert_equal(
         bson.json_util.dumps(excel.import_excel(aggregate).to_mongo()),
         open(os.path.join(self.rootdir, 'cth-fbo.json'), 'r').read())
示例#9
0
 def test_Item(self):
     item = open(os.path.join(self.rootdir, "transportandcoms.xls"), "r").read()
     assert_equal(
         bson.json_util.dumps(excel.import_excel(item).to_mongo()),
         open(os.path.join(self.rootdir, "transportandcoms.json"), "r").read(),
     )
示例#10
0
 def test_Aggregate(self):
     aggregate = open(os.path.join(self.rootdir, "cth-fbo.xls"), "r").read()
     assert_equal(
         bson.json_util.dumps(excel.import_excel(aggregate).to_mongo()),
         open(os.path.join(self.rootdir, "cth-fbo.json"), "r").read(),
     )