How to use the webargs.fields.Int function in webargs

To help you get started, we’ve selected a few webargs 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 marshmallow-code / webargs / tests / test_tornadoparser.py View on Github external
def test_it_should_parse_multiple_arg_required(self):
        args = {"foo": fields.List(fields.Int(), required=True)}
        request = make_json_request({})
        msg = "Missing data for required field."
        with pytest.raises(tornado.web.HTTPError, match=msg):
            parser.parse(args, request)
github holoviz / datashader / examples / dashboard / dashboard.py View on Github external
from datashader.colors import Hot, viridis

from datashader.bokeh_ext import HoverLayer, create_categorical_legend, create_ramp_legend
from datashader.utils import hold

from tornado.ioloop import IOLoop
from tornado.web import RequestHandler

from webargs import fields
from webargs.tornadoparser import use_args

# http request arguments for datashing HTTP request
ds_args = {
    'width': fields.Int(missing=800),
    'height': fields.Int(missing=600),
    'select': fields.Str(missing=""),
}


class GetDataset(RequestHandler):
    """Handles http requests for datashading."""

    @use_args(ds_args)
    def get(self, args):

        # parse args
        selection = args['select'].strip(',').split(',')
        xmin, ymin, xmax, ymax = map(float, selection)
        self.model.map_extent = [xmin, ymin, xmax, ymax]

        glyph = self.model.glyph.get(str(self.model.field), 'points')
github indico / indico / indico / modules / rb / controllers / backend / admin.py View on Github external
        'area_ids': fields.List(fields.Int(), required=True)
    })
    def _process_DELETE(self, area_ids):
        delete_areas(area_ids)
        return '', 204
github fedspendingtransparency / data-act-broker-backend / dataactbroker / fileRoutes.py View on Github external
        'limit': webargs_fields.Int(missing=5),
        'certified': webargs_fields.String(
            required=True,
            validate=webargs_validate.OneOf(('mixed', 'true', 'false'))),
        'sort': webargs_fields.String(missing='modified'),
        'order': webargs_fields.String(missing='desc')
    })
    def list_submissions(page, limit, certified, sort, order):
        """ List submission IDs associated with the current user """
        return list_submissions_handler(page, limit, certified, sort, order)
github davidmcclure / open-syllabus-project / osp / www / app.py View on Github external
@use_args(dict(institution_id = List(Int(), missing=None)))
def home(args):

    """
    Home page + ranking interface.
    """

    facets = utils.bootstrap_facets()

    # Bootstrap URL institution(s).
    facets['institution'] = utils.institution_facets(
        include=args['institution_id']
    )

    return render_template('home.html', facets=facets)
github marshmallow-code / webargs / examples / tornado_example.py View on Github external
class AdderHandler(BaseRequestHandler):
    """An addition endpoint."""

    add_args = {"x": fields.Float(required=True), "y": fields.Float(required=True)}

    @use_kwargs(add_args)
    def post(self, x, y):
        self.write({"result": x + y})


class DateAddHandler(BaseRequestHandler):
    """A date adder endpoint."""

    dateadd_args = {
        "value": fields.Date(required=False),
        "addend": fields.Int(required=True, validate=validate.Range(min=1)),
        "unit": fields.Str(
            missing="days", validate=validate.OneOf(["minutes", "days"])
        ),
    }

    @use_kwargs(dateadd_args)
    def post(self, value, addend, unit):
        """A date adder endpoint."""
        value = value or dt.datetime.utcnow()
        if unit == "minutes":
            delta = dt.timedelta(minutes=addend)
        else:
            delta = dt.timedelta(days=addend)
        result = value + delta
        self.write({"result": result.isoformat()})
github FreeDiscovery / FreeDiscovery / freediscovery / server / resources.py View on Github external
            'n_clusters': wfields.Int(missing=-1),
            'branching_factor': wfields.Int(missing=20),
            'max_tree_depth': wfields.Int(),
            # this corresponds approximately to threashold = 0.5
            'min_similarity': wfields.Number(missing=0.5),
            'metric': wfields.Str(missing='cosine')
            }
            )
    @marshal_with(IDSchema())
    def post(self, **args):
        from math import sqrt

        metric = args.pop('metric')
        S_cos = _scale_cosine_similarity(args.pop('min_similarity'),
                                         metric=metric,
                                         inverse=True)
        # cosine sim to euclidean distance
github suryasr007 / random-password-generator / api.py View on Github external
pwg = PasswordGenerator()

password_generator_args = {
    'minlen': fields.Int(missing=6, validate=lambda val: val > 0),
    'maxlen': fields.Int(missing=16, validate=lambda val: val > 0),
    'minuchars': fields.Int(missing=1, validate=lambda val: val > 0),
    'minuchars': fields.Int(missing=1, validate=lambda val: val > 0),
    'minlchars': fields.Int(missing=1, validate=lambda val: val > 0),
    'excludeuchars': fields.Str(missing=''),
    'excludelchars': fields.Str(missing=''),
    'excludenumbers': fields.Str(missing=''),
    'excludeschars': fields.Str(missing='')
}

shuffle_password_args = {
    'maxlen': fields.Int(required={'message': 'maximum length required', 'code': 400}),
    'password': fields.Str(required={'message': 'Password required', 'code': 400})
}

non_duplicate_args = {
    'maxlen': fields.Int(required={'message': 'maximum length required', 'code': 400})
}

class PasswordGenerator(Resource):

    @use_args(password_generator_args)
    def get(self, args):
        try:
            pwg.__dict__.update(args)
            res = pwg.generate()
        except Exception as e:
            abort(404, str(e))
github indico / indico / indico / modules / rb_new / controllers / backend.py View on Github external
        'room_ids': fields.List(fields.Int(), missing=[]),
        'start_date': fields.Date(),
        'end_date': fields.Date(),
        'reason': fields.Str(),
        'allowed_principals': fields.List(fields.Dict())
    })
    def _process(self, args):
        blocking = create_blocking(created_by=session.user, **args)
        approve_or_request_blocking(blocking)
        return jsonify_data(flash=False)

webargs

Declarative parsing and validation of HTTP request objects, with built-in support for popular web frameworks, including Flask, Django, Bottle, Tornado, Pyramid, Falcon, and aiohttp.

MIT
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis

Similar packages