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

Look at schematics #30

Open
mjtamlyn opened this issue Nov 24, 2016 · 3 comments
Open

Look at schematics #30

mjtamlyn opened this issue Nov 24, 2016 · 3 comments

Comments

@mjtamlyn
Copy link
Owner

https://github.com/schematics/schematics

http://schematics.readthedocs.io/en/latest/index.html

Looks like this gets a lot of things right that we're looking at. The API is nice, the to_primitive is a pretty good naming convention, and the validation/coercion/conversion logic seems clean. It lacks introspectability and good complex validation support as far as I can see, but it's pretty good!

@LilyFoote
Copy link
Collaborator

LilyFoote commented Nov 24, 2016

The roles seem pretty shiny - I don't think I've seen that sort of idea with such a clean api before.

@jpic
Copy link
Contributor

jpic commented Mar 6, 2018

Awesome, I think it would be great to reuse it in this lib, if it fits our needs: reinventing it would seem like a waste of human resources

@jpic
Copy link
Contributor

jpic commented Mar 9, 2018

Based on their getting started, SchematicsAdapters could be usable like:

import datetime
from schematics.models import Model
from schematics.types import StringType, DecimalType, DateTimeType

class WeatherReport(Model):
    city = StringType()
    temperature = DecimalType()
    taken_at = DateTimeType(default=datetime.datetime.now)

a = SchematicsAdapter(model=WeatherReport)
a = a.steps.clean(data={'city': 'NYC', 'temperature': 80})
assert a.instance.temperature == Decimal('80.0')

But that we could also do:

a = DjangoSchematicsAdapter(
   pk=3, # DjangoModel.instanciate step will use this to set self.instance
   adapters=[WeatherDjangoModelAdapter, SchematicsAdapter(WeatherModel)],
).steps.clean(data={'city': 'NYC', 'temperature': 80})
if not a.errors:
    a = a.steps.process()

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

3 participants