@@ -343,55 +343,37 @@ def user_update():
343
343
except :
344
344
pass
345
345
346
- print (update_dict )
346
+ if not update_dict :
347
+ return jsonify ("No changed items specified" )
347
348
348
- # If updating password, need to hash first
349
+ # TODO: If updating password, need to hash first
349
350
350
351
351
352
# We have a variable number of columns to update.
352
353
# We could generate a text query on the fly, but this seems the perfect place to use the ORM
353
354
# and let it handle the update for us.
354
355
355
-
356
- # with engine.connect() as connection:
357
-
358
- # for k,v in update_dict.items(): #TODO: Make less awful
359
- # s = text( """UPDATE pdp_users SET :key=:val where username=:u """ )
360
- # s = s.bindparams(u=username, key=k, val=v)
361
- # result = connection.execute(s)
362
-
363
356
from sqlalchemy import update
364
- from sqlalchemy .orm import Session
357
+ from sqlalchemy .orm import Session , sessionmaker
365
358
366
- with Session (engine ) as session :
359
+ Session = sessionmaker (engine )
367
360
368
- PU = Table ( "pdp_users" , metadata , autoload = True , autoload_with = engine )
369
- # pr = Table("pdp_user_roles", metadata, autoload=True, autoload_with=engine)
361
+ session = Session ()
362
+ # #TODO: Figure out context manager doesn't work or do try/finally
370
363
364
+ PU = Table ("pdp_users" , metadata , autoload = True , autoload_with = engine )
365
+ # pr = Table("pdp_user_roles", metadata, autoload=True, autoload_with=engine)
371
366
372
- stmt = update (PU ).where (PU .username == username ).values (update_dict ).\
373
- execution_options (synchronize_session = "fetch" )
374
367
375
- result = session .execute (stmt )
368
+ stmt = update (PU ).where (PU .columns .username == username ).values (update_dict ).\
369
+ execution_options (synchronize_session = "fetch" )
376
370
371
+ result = session .execute (stmt )
377
372
378
- return jsonify ("Work in process" )
373
+ session .commit ()
374
+ session .close ()
379
375
380
- # TODO: A single do-all update_user()
381
- @user_api .route ("/api/admin/user/deactivate" , methods = ["POST" ])
382
- @jwt_ops .admin_required
383
- def user_deactivate ():
384
- """Mark user as inactive in DB"""
385
- # TODO
386
- return "" , 200
387
-
388
-
389
- @user_api .route ("/api/admin/user/activate" , methods = ["POST" ])
390
- @jwt_ops .admin_required
391
- def user_activate ():
392
- """Mark user as active in DB"""
393
- # TODO
394
- return "" , 200
376
+ return jsonify ("Updated" )
395
377
396
378
397
379
@user_api .route ("/api/admin/user/get_users" , methods = ["GET" ])
0 commit comments