def _get_multi(): # get_multi max_ = int(request.args.get("max", '20')) offset = int(request.args.get('offset', '0')) q = request.args.get('q', '') or None exact = str2bool(request.args.get('exact', None)) or False fields = dict([(f, q) for f in parse_fields(request.args.get('fields', 'code'))]) tags = request.args.get('tags', '') or None if tags: tags = parse_fields(tags) valid_tags = filter(lambda x: x in transfusion_tags, tags) else: valid_tags = None if offset < 0: offset = 0 if max_ > 50: max_ = 50 if max_ < 0: max_ = 0 total = Transfusion.count() endpoint = "transfusion.get" patient_key_urlsafe = fields.get('patient.key', '') or None patient_key = None patient_key_non_exists = ndb.Key(Patient, "NonExists") if patient_key_urlsafe: try: patient_key = ndb.Key(urlsafe=patient_key_urlsafe) except (ProtocolBufferDecodeError, TypeError): logging.error("Cannot get patient from key %r" % (patient_key_urlsafe)) # return make_response(jsonify(code="Bad request"), 400, {}) patient_key = patient_key_non_exists if tags is not None and len(tags) == 1 and len(tags) != len(valid_tags): # one tag was passed and it is a invalid tag query = Transfusion.build_query(patient_key=patient_key_non_exists) else: query = Transfusion.build_query(exact=exact, patient_code=fields.get('patient.code'), patient_name=fields.get('patient.name'), patient_key=patient_key, tags=valid_tags, code=fields.get('code')) return make_response_list_paginator(max_=max_, offset=offset, q=q, fields=','.join(fields.keys()), exact=bool2int(exact), dbquery=query, tags=','.join(tags) if tags else '', total=total, endpoint=endpoint)
def _get_multi(): max_ = int(request.args.get("max", "20")) offset = int(request.args.get("offset", "0")) q = request.args.get("q", "") or None fields = dict([(f, q) for f in parse_fields(request.args.get("fields", ""))]) total = UserPrefs.build_query().count() admin = str2bool(fields.get("admin", None)) authorized = str2bool(fields.get("admin", None)) query = UserPrefs.build_query(admin=admin, authorized=authorized) endpoint = "user.get" return make_response_list_paginator( max_=max_, offset=offset, q=q, fields=",".join(fields.keys()), dbquery=query, total=total, endpoint=endpoint )