|
|
@ -189,6 +189,9 @@ def list_theaters(group=None): |
|
|
|
@app.route('/theater/<string:theater_id>/', methods=['GET', 'POST']) |
|
|
|
@app.route('/theater/<string:theater_id>/', methods=['GET', 'POST']) |
|
|
|
@crossdomain(origin='*') |
|
|
|
@crossdomain(origin='*') |
|
|
|
def get_theater(theater_id): |
|
|
|
def get_theater(theater_id): |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
TODO: cannot add theater yet |
|
|
|
|
|
|
|
''' |
|
|
|
if request.method == 'GET': |
|
|
|
if request.method == 'GET': |
|
|
|
result = db.theater.find_one({'_id': bson.objectid.ObjectId(theater_id)}) |
|
|
|
result = db.theater.find_one({'_id': bson.objectid.ObjectId(theater_id)}) |
|
|
|
r = make_response(dumps(result, default=miscObjHandler)) |
|
|
|
r = make_response(dumps(result, default=miscObjHandler)) |
|
|
@ -202,9 +205,20 @@ def get_theater(theater_id): |
|
|
|
abort(400) |
|
|
|
abort(400) |
|
|
|
try: |
|
|
|
try: |
|
|
|
key = {'_id': bson.objectid.ObjectId(theater_id)} |
|
|
|
key = {'_id': bson.objectid.ObjectId(theater_id)} |
|
|
|
## TODO: better verify if group/code is still the same |
|
|
|
prev = db.theater.find_one(key) |
|
|
|
# otherwise things could get worse w/o any proof before updating |
|
|
|
if not prev: |
|
|
|
|
|
|
|
abort(500) |
|
|
|
|
|
|
|
is_allowed = True |
|
|
|
|
|
|
|
for k in ['code', 'group', 'name']: |
|
|
|
|
|
|
|
if request.json[k] != prev[k]: |
|
|
|
|
|
|
|
is_allowed = False |
|
|
|
|
|
|
|
if is_allowed: |
|
|
|
result = db.theater.update(key, {'$set': request.json}, False) |
|
|
|
result = db.theater.update(key, {'$set': request.json}, False) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
result = { # mimicking mongo update result for consistency |
|
|
|
|
|
|
|
'updatedExisting': False, 'ok': 0, 'nModified': 0, |
|
|
|
|
|
|
|
'error': "cannot alter mandatory fields", |
|
|
|
|
|
|
|
} |
|
|
|
r = make_response(dumps(result, default=miscObjHandler)) |
|
|
|
r = make_response(dumps(result, default=miscObjHandler)) |
|
|
|
r.mimetype = 'application/json' |
|
|
|
r.mimetype = 'application/json' |
|
|
|
return r |
|
|
|
return r |
|
|
|