Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to Marshmallow instead of Reqparser? #5

Open
aliceafterall opened this issue Nov 4, 2017 · 0 comments
Open

Change to Marshmallow instead of Reqparser? #5

aliceafterall opened this issue Nov 4, 2017 · 0 comments

Comments

@aliceafterall
Copy link
Contributor

In light of Flask's Reqparser not only behaving oddly and being less-than-well-documented, would there be interest in using Marshmallow instead of Reqparser? The change would be relatively simple - in checkin.py we'd have a schema for the GameListing model, and simply run schema.load(request.get_json()) to get back a valid model. For an example, here's a schema for the GameListing model:

from marshmallow import Schema, fields

class GameListingSchema(Schema):
    game_name = fields.Str(required=True)
    game_status = fields.Str(required=True)
    game_website = fields.Str()
    listing_contact = fields.Str(required=True)
    short_description = fields.Str(validator=lambda v: return len(v) < 255)
    long_description = fields.Str()

    telnet_hostname = fields.Str()
    telnet_port = fields.Integer()
    web_client_url = fields.Str()

    connected_account_count = fields.Integer()
    total_account_count = fields.Integer()

    evennia_version = fields.Str(required=True)
    python_version = fields.Str()
    django_version = fields.Str()
    server_platform = fields.Str()

game_listing_schema = GameListingSchema()
...
# in GameListingCheckin(Resource)
    result = game_listing_schema.load(request.get_json())
    # process result as we did args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant