def test_column_editable_list():
    (app, db, admin) = setup()
    (Model1, Model2) = create_models(db)
    view = CustomModelView(Model1, column_editable_list=['test1', 'datetime_field'])
    admin.add_view(view)
    fill_db(Model1, Model2)
    client = app.test_client()
    rv = client.get('/admin/model1/')
    data = rv.data.decode('utf-8')
    ok_(('data-role="x-editable"' in data))
    obj1 = Model1.objects.get(test1='test1_val_3')
    rv = client.post('/admin/model1/ajax/update/', data={('test1-' + str(obj1.id)): 'change-success-1'})
    data = rv.data.decode('utf-8')
    ok_(('Record was successfully saved.' == data))
    rv = client.get('/admin/model1/')
    data = rv.data.decode('utf-8')
    ok_(('change-success-1' in data))
    obj2 = Model1.objects.get(test1='datetime_obj1')
    rv = client.post('/admin/model1/ajax/update/', data={('datetime_field-' + str(obj2.id)): 'problematic-input'})
    eq_(rv.status_code, 500)
    rv = client.post('/admin/model1/ajax/update/', data={'test1-1000': 'problematic-input'})
    data = rv.data.decode('utf-8')
    eq_(rv.status_code, 500)
    rv = client.post('/admin/model1/ajax/update/', data={'test2-1': 'problematic-input'})
    data = rv.data.decode('utf-8')
    eq_(rv.status_code, 500)
    view = CustomModelView(Model2, column_editable_list=['model1'])
    admin.add_view(view)
    obj3 = Model2.objects.get(string_field='string_field_val_1')
    rv = client.post('/admin/model2/ajax/update/', data={('model1-' + str(obj3.id)): str(obj1.id)})
    data = rv.data.decode('utf-8')
    ok_(('Record was successfully saved.' == data))
    rv = client.get('/admin/model2/')
    data = rv.data.decode('utf-8')
    ok_(('test1_val_1' in data))
def test_column_editable_list():
    (app, db, admin) = setup()
    (Model1, Model2) = create_models(db)
    view = CustomModelView(Model1, column_editable_list=['test1', 'datetime_field'])
    admin.add_view(view)
    fill_db(Model1, Model2)
    client = app.test_client()
    rv = client.get('/admin/model1/')
    data = rv.data.decode('utf-8')
    ok_(('data-role="x-editable"' in data))
    obj1 = Model1.objects.get(test1='test1_val_3')
    rv = client.post('/admin/model1/ajax/update/', data={('test1-' + str(obj1.id)): 'change-success-1'})
    data = rv.data.decode('utf-8')
    ok_(('Record was successfully saved.' == data))
    rv = client.get('/admin/model1/')
    data = rv.data.decode('utf-8')
    ok_(('change-success-1' in data))
    obj2 = Model1.objects.get(test1='datetime_obj1')
    rv = client.post('/admin/model1/ajax/update/', data={('datetime_field-' + str(obj2.id)): 'problematic-input'})
    eq_(rv.status_code, 500)
    rv = client.post('/admin/model1/ajax/update/', data={'test1-1000': 'problematic-input'})
    data = rv.data.decode('utf-8')
    eq_(rv.status_code, 500)
    rv = client.post('/admin/model1/ajax/update/', data={'test2-1': 'problematic-input'})
    data = rv.data.decode('utf-8')
    eq_(rv.status_code, 500)
    view = CustomModelView(Model2, column_editable_list=['model1'])
    admin.add_view(view)
    obj3 = Model2.objects.get(string_field='string_field_val_1')
    rv = client.post('/admin/model2/ajax/update/', data={('model1-' + str(obj3.id)): str(obj1.id)})
    data = rv.data.decode('utf-8')
    ok_(('Record was successfully saved.' == data))
    rv = client.get('/admin/model2/')
    data = rv.data.decode('utf-8')
    ok_(('test1_val_1' in data))