Exemple #1
0
from pony.orm import sum as db_sum
from webargs import flaskparser
from werkzeug.exceptions import HTTPException
from werkzeug.http import HTTP_STATUS_CODES
from werkzeug.utils import secure_filename

from radio import app
from radio.common.schemas import RequestStatus
from radio.common.schemas import SongData
from radio.database import Queue
from radio.database import Song

register_blueprint_prefixed = partial(
    app.register_blueprint, url_prefix=app.config["SERVER_API_PREFIX"])

parser = flaskparser.FlaskParser()


# I did not want to put this here, but since it uses make_api_response
# there can be some tricky circular dependencies
@parser.error_handler
def webargs_error(error: ValidationError, req, schema, error_status_code,
                  error_headers):
    code = getattr(error, "status_code", 400)
    resp = make_api_response(code, error.messages)
    raise HTTPException(description=resp.get_data(as_text=True), response=resp)


def make_api_response(status_code: int,
                      description: any = None,
                      content: Dict = None) -> Response:
Exemple #2
0
 def __init__(self):
     self.parser = flaskparser.FlaskParser()
     self.parser.error_handler(self.handle_error)
     self.request = reqparse.RequestParser()
     super().__init__()