Implement older_than and newer_than in gifted-subs-api

master
Nikola Forró 6 years ago
parent ebe925f7f5
commit 85046a0f75

@ -55,6 +55,8 @@ gifted_sub_parser.add_argument('time', type=flask_restful.inputs.datetime_from_i
filter_parser = flask_restful.reqparse.RequestParser()
filter_parser.add_argument('filter', type=str)
filter_parser.add_argument('older_than', type=flask_restful.inputs.datetime_from_iso8601)
filter_parser.add_argument('newer_than', type=flask_restful.inputs.datetime_from_iso8601)
filter_parser.add_argument('sort_by', type=str)
filter_parser.add_argument('sort_order', type=str)
filter_parser.add_argument('page_number', type=int)
@ -120,6 +122,10 @@ class GiftedSubsResource(flask_restful.Resource):
if args['filter']:
q = q.filter(GiftedSub.giver.ilike('%{}%'.format(args['filter'])) |\
GiftedSub.receiver.ilike('%{}%'.format(args['filter'])))
if args['older_than']:
q = q.filter(GiftedSub.time < args['older_than'])
if args['newer_than']:
q = q.filter(GiftedSub.time > args['newer_than'])
count = q.count()
if args['sort_order'] == 'random':
q = q.order_by(sqlalchemy.func.random())

Loading…
Cancel
Save