Skip to content
Merged

Sync #42

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
apison_post: modify to be same with original apijson, just return "id…
…" and "count", not other fields
  • Loading branch information
zhangchunlin committed Oct 22, 2019
commit 6f8cadeb87ae02c2911327eae7e63fd611fd497d
3 changes: 1 addition & 2 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,8 @@ def test_apijson_post():
... }'''
>>> r = handler.post('/apijson/post', data=data, pre_call=pre_call_as("admin"), middlewares=[])
>>> d = json_loads(r.data)
>>> del d['moment']['date']
>>> print(d)
{'code': 200, 'msg': 'success', 'moment': {'user_id': 1, 'content': 'new moment for test', 'picture_list': ['http://static.oschina.net/uploads/user/48/96331_50.jpg'], 'id': 4, 'code': 200, 'message': 'success'}}
{'code': 200, 'msg': 'success', 'moment': {'id': 4, 'count': 1, 'code': 200, 'message': 'success'}}

>>> #apijson post to a non exist model
>>> data ='''{
Expand Down
9 changes: 4 additions & 5 deletions uliweb_apijson/apijson/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,12 @@ def _post_one(self,key,tag):

obj = model(**params)
ret = obj.save()
obj_dict = obj.to_dict(convert=False)
secret_fields = model_setting.get("secret_fields")
if secret_fields:
for k in secret_fields:
del obj_dict[k]
d = obj.to_dict(convert=False)

obj_dict = {}
if ret:
obj_dict["id"] = d.get("id")
obj_dict["count"] = 1
obj_dict["code"] = 200
obj_dict["message"] = "success"
else:
Expand Down