Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdda827b

Browse files
committed
update some comment; fix "NameError: name 'model_name' is not defined"; add 2 test cases
1 parentc32aa1d commitdda827b

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

‎tests/test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,42 @@ def test_apijson_get():
707707
>>> print(d)
708708
{'code': 400, 'msg': "'!'(not) expression need 2 items, but get '['username$', '!', 'nickname$']'"}
709709
710+
>>> #query array with like
711+
>>> data ='''{
712+
... "[]":{
713+
... "@count":4,
714+
... "@page":0,
715+
... "user":{
716+
... "@column":"id,username,nickname,email",
717+
... "@order":"id-",
718+
... "@role":"ADMIN",
719+
... "username$":"%b%"
720+
... }
721+
... }
722+
... }'''
723+
>>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
724+
>>> d = json_loads(r.data)
725+
>>> print(d)
726+
{'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'userb', 'nickname': 'User B', 'email': 'userb@localhost', 'id': 3}}]}
727+
728+
>>> #query array with like, but gave a nonexist column
729+
>>> data ='''{
730+
... "[]":{
731+
... "@count":4,
732+
... "@page":0,
733+
... "user":{
734+
... "@column":"id,username,nickname,email",
735+
... "@order":"id-",
736+
... "@role":"ADMIN",
737+
... "nonexist$":"%b%"
738+
... }
739+
... }
740+
... }'''
741+
>>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
742+
>>> d = json_loads(r.data)
743+
>>> print(d)
744+
{'code': 400, 'msg': "model does not have this column: 'nonexist'"}
745+
710746
>>> #Association query: Two tables, one to one,ref path is absolute path
711747
>>> data ='''{
712748
... "moment":{},

‎uliweb_apijson/apijson/views.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,30 @@ def _expr(self,model,model_param,model_expr):
225225
raiseUliwebError("unknown operator: '%s'"%(op))
226226

227227
def_get_filter_condition(self,model,model_param,item,expr=False):
228+
#item can be param key, or expr which expected to be a list
228229
ifisinstance(item,list):
229230
ifexpr:
230231
returnself._expr(model,model_param,model_expr=item)
231232
else:
232-
raiseUliwebError("item can be array only in @expr: '%s'"%(item))
233+
#current implementation won't run here, but keep for safe
234+
raiseUliwebError("item can be list only in @expr: '%s'"%(item))
233235
ifnotisinstance(item,string_types):
236+
#current implementation won't run here, but keep for safe
234237
raiseUliwebError("item should be array or string: '%s'"%(item))
235238
n=item
236239
ifn[0]=="@":
240+
#current implementation won't run here, but keep for safe
237241
raiseUliwebError("param key should not begin with @: '%s'"%(n))
238242
ifn[-1]=="$":
239243
name=n[:-1]
240244
ifhasattr(model,name):
241245
returngetattr(model.c,name).like(model_param[n])
242246
else:
243-
raiseUliwebError("'%s' does not have '%s'"%(model_name,name))
247+
raiseUliwebError("model does not havethis column:'%s'"%(name))
244248
elifn[-1]=="}"andn[-2]=="{":
245249
name=n[:-2]
246250
ifhasattr(model,name):
247-
# TODO
251+
# TODO: https://github.com/APIJSON/APIJSON/blob/master/Document.md#32-%E5%8A%9F%E8%83%BD%E7%AC%A6
248252
pass
249253
raiseUliwebError("still not support '%s'"%(name))
250254
elifhasattr(model,n):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp