Skip to content

Commit e0d7c0e

Browse files
committed
Changed entry custom_view response to be HttpReponse
1 parent 409a232 commit e0d7c0e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

entry/tests/test_view.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3448,7 +3448,7 @@ def test_revert_attrv_with_custom_view_by_latest_value(self):
34483448
self.assertEqual(attr.get_latest_value(), attrv)
34493449

34503450
@patch('custom_view.is_custom', Mock(return_value=True))
3451-
@patch('custom_view.call_custom', Mock(return_value=(False, 400, 'test')))
3451+
@patch('custom_view.call_custom', Mock(return_value=HttpResponse('test', status=400)))
34523452
def test_call_custom_do_create_entry_return_int(self):
34533453
self.admin_login()
34543454

@@ -3468,7 +3468,7 @@ def test_call_custom_do_create_entry_return_int(self):
34683468

34693469
@patch('custom_view.is_custom', Mock(return_value=True))
34703470
@patch('custom_view.call_custom',
3471-
Mock(return_value=(False, JsonResponse({'entry_id': 1, 'entry_name': 'fuga', }), '')))
3471+
Mock(return_value=JsonResponse({'entry_id': 1, 'entry_name': 'fuga', })))
34723472
def test_call_custom_do_create_entry_return_json(self):
34733473
self.admin_login()
34743474

entry/views.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,11 @@ def do_create(request, entity_id, recv_data):
178178
return err
179179

180180
if custom_view.is_custom("do_create_entry", entity.name):
181-
(is_continue, resp, msg) = custom_view.call_custom(
181+
# resp is HttpReponse instance or its subclass (e.g. JsonResponse)
182+
resp = custom_view.call_custom(
182183
"do_create_entry", entity.name, request, recv_data, user, entity)
183-
if not is_continue:
184-
if isinstance(resp, int):
185-
return HttpResponse(msg, status=resp)
186-
elif isinstance(resp, JsonResponse):
187-
return resp
184+
if resp:
185+
return resp
188186

189187
# Create a new Entry object
190188
entry = Entry.objects.create(name=recv_data['entry_name'],
@@ -268,14 +266,12 @@ def do_edit(request, entry_id, recv_data):
268266
return HttpResponse('Target entry is now under processing', status=400)
269267

270268
if custom_view.is_custom("do_edit_entry", entry.schema.name):
271-
(is_continue, resp, msg) = custom_view.call_custom(*[
269+
# resp is HttpReponse instance or its subclass (e.g. JsonResponse)
270+
resp = custom_view.call_custom(
272271
"do_edit_entry", entry.schema.name, request, recv_data, user, entry
273-
])
274-
if not is_continue:
275-
if isinstance(resp, int):
276-
return HttpResponse(msg, status=resp)
277-
elif isinstance(resp, JsonResponse):
278-
return resp
272+
)
273+
if resp:
274+
return resp
279275

280276
# update name of Entry object. If name would be updated, the elasticsearch data of entries that
281277
# refers this entry also be updated by creating REGISTERED_REFERRALS task.

0 commit comments

Comments
 (0)