How to use the quart.request.args.get function in Quart

To help you get started, we’ve selected a few Quart examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AceFire6 / ordered-arrowverse / ordering / filters.py View on Github external
def inject_newest_first():
    newest_first = request.args.get('newest_first', default=False, type=_get_bool)
    return {'newest_first': newest_first}
github etalab / csvapi / csvapi / tableview.py View on Github external
async def get(self, urlhash):
        db_info = get_db_info(urlhash)
        p = Path(db_info['db_path'])
        if not p.exists():
            raise APIError('Database has probably been removed.', status=404)

        start = time.time()
        try:
            data = await self.data(db_info)
        except (sqlite3.OperationalError, sqlite3.IntegrityError) as e:
            raise APIError('Error selecting data', status=400, payload=dict(details=str(e)))
        end = time.time()

        _shape = request.args.get('_shape', DEFAULT_SHAPE)
        if _shape == 'objects':
            # Format data as an array of objects for the client
            rows = []
            for row in data['rows']:
                rows.append(dict(zip(data['columns'], row)))
        elif _shape == 'lists':
            rows = data['rows']
        else:
            raise APIError(f"Unknown _shape: {_shape}", status=400)

        res = {
            'ok': True,
            'query_ms': (end - start) * 1000,
            'rows': rows,
            'columns': data['columns'],
        }
github etalab / csvapi / csvapi / tableview.py View on Github external
async def data(self, db_info, export=False):
        limit = request.args.get('_size', ROWS_LIMIT) if not export else -1
        rowid = not (request.args.get('_rowid') == 'hide') and not export
        total = not (request.args.get('_total') == 'hide') and not export
        sort = request.args.get('_sort')
        sort_desc = request.args.get('_sort_desc')
        offset = request.args.get('_offset') if not export else 0

        # get filter arguments, like column__exact=xxx
        filters = []
        for key, value in request.args.items():
            if not key.startswith('_') and '__' in key:
                filters.append((key, value))

        cols = 'rowid, *' if rowid else '*'
        sql = 'SELECT {} FROM [{}]'.format(cols, db_info['table_name'])
        sql, params = self.add_filters_to_sql(sql, filters)
        if sort:
            sql += f' ORDER BY [{sort}]'
        elif sort_desc:
            sql += f' ORDER BY [{sort_desc}] DESC'
        else:
github etalab / csvapi / csvapi / parseview.py View on Github external
async def get(self):
        app.logger.debug('* Starting ParseView.get')
        url = request.args.get('url')
        encoding = request.args.get('encoding')
        if not url:
            raise APIError('Missing url query string variable.', status=400)
        if not validators.url(url):
            raise APIError('Malformed url parameter.', status=400)
        urlhash = get_hash(url)

        if not already_exists(urlhash):
            try:
                storage = app.config['DB_ROOT_DIR']
                await self.do_parse(url=url,
                                    urlhash=urlhash,
                                    encoding=encoding,
                                    storage=storage,
                                    logger=app.logger,
                                    sniff_limit=app.config.get('CSV_SNIFF_LIMIT'),
                                    max_file_size=app.config.get('MAX_FILE_SIZE')
github osks / httpkom / httpkom / conferences.py View on Github external
"comment_to_list": [],
          },
          
          ...
        ]
      }
    
    .. rubric:: Example
    
    ::
    
      curl -v -X GET -H "Content-Type: application/json" \\
           "http://localhost:5001/lyskom/conferences/texts/?no-of-texts=3"
    
    """
    no_of_texts = int(request.args.get('no-of-texts', 10))
    texts = await g.ksession.get_last_texts(conf_no, no_of_texts)
    return jsonify(texts=await to_dict(texts, g.ksession))
github osks / httpkom / httpkom / memberships.py View on Github external
},
          
          ...
        ]
      }
    
    .. rubric:: Example
    
    ::
    
      curl -v -X GET "http://localhost:5001/lyskom/persons/14506/memberships/?unread=true"
    
    """
    unread = get_bool_arg_with_default(request.args, 'unread', False)
    passive = get_bool_arg_with_default(request.args, 'passive', False)
    first = int(request.args.get('first', 0))
    no_of_memberships = int(request.args.get('no-of-memberships', 100))
    memberships, has_more = await g.ksession.get_memberships(
        pers_no, first, no_of_memberships, unread, passive)
    return jsonify(has_more=has_more, memberships=await to_dict(memberships, g.ksession))
github etalab / csvapi / csvapi / tableview.py View on Github external
async def data(self, db_info, export=False):
        limit = request.args.get('_size', ROWS_LIMIT) if not export else -1
        rowid = not (request.args.get('_rowid') == 'hide') and not export
        total = not (request.args.get('_total') == 'hide') and not export
        sort = request.args.get('_sort')
        sort_desc = request.args.get('_sort_desc')
        offset = request.args.get('_offset') if not export else 0

        # get filter arguments, like column__exact=xxx
        filters = []
        for key, value in request.args.items():
            if not key.startswith('_') and '__' in key:
                filters.append((key, value))

        cols = 'rowid, *' if rowid else '*'
        sql = 'SELECT {} FROM [{}]'.format(cols, db_info['table_name'])
        sql, params = self.add_filters_to_sql(sql, filters)
        if sort:
            sql += f' ORDER BY [{sort}]'
        elif sort_desc:
            sql += f' ORDER BY [{sort_desc}] DESC'
        else:
            sql += ' ORDER BY rowid'