Skip to content

Commit

Permalink
feat: 院校接口支持条件过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
kian-zh committed Oct 20, 2023
1 parent c7c7cda commit 80ce1cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 0 additions & 4 deletions apps/post/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,9 @@ def manage_post(request, post_id):
elif request.method == 'POST':
body = json.loads(request.body)
record_serializer = GISourceSerializer(record, data=body)
logger.error('1')
if record_serializer.is_valid():
logger.error('2')
record_serializer.save()
logger.error('3')
return JsonResponse({"code": 0, "msg": "success"})
logger.error('4')
logger.error(record_serializer.errors)
return JsonResponse({"code": 500, "msg": 'record_serializer not pass'})
elif request.method == 'DELETE':
Expand Down
16 changes: 15 additions & 1 deletion apps/school/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
@permission_classes((AllowAny,))
@authentication_classes((TokenAuthentication,))
def get_school_list(request):
"""
e.g.
http://127.0.0.1:8000/api/schools
http://127.0.0.1:8000/api/schools?tag=Urban_Planning
http://127.0.0.1:8000/api/schools?tag=Urban_Planning,Transportation
"""
whereSql = ''
# 如果请求中带了 tag 参数,则用 tag 参数去构造 WHERE 条件
if 'tag' in request.GET:
tags = request.GET['tag'].split(',')
whereArr = []
for tag in tags:
whereArr.append('(u.' + tag + '=1 AND p.' + tag + '=1)')
whereSql = 'WHERE' + ' OR '.join(whereArr)
with connection.cursor() as cursor:
cursor.execute("""
SELECT u.University_Name_CN, u.University_Name_EN, u.University_Name_Local,
Expand All @@ -29,7 +43,7 @@ def get_school_list(request):
LEFT JOIN new_city c ON u.City = c.City_Name_EN
LEFT JOIN new_country co ON c.Country = co.Country_Name_CN
LEFT JOIN new_people p ON u.University_Name_EN = p.University
""")
""" + whereSql)
rows = cursor.fetchall()

data = []
Expand Down

0 comments on commit 80ce1cc

Please sign in to comment.