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

Added support for DictField / ListField #59

Merged
merged 5 commits into from
Jan 22, 2020
Merged

Conversation

peterfarrell
Copy link
Contributor

@peterfarrell peterfarrell commented Jan 13, 2020

There is no way using Django Forms to pass around arbitrary dictionaries. The only other way was to override __init__ and pass the dictionary "input" as a kwarg which is a hack. This is a shim to support passing dictionaries to services:

class PDFGenerate(Service):
    context = DictField()

    process(self):
        context = self.cleaned_data['context']

PDFGenerate.execute({
    'context': {'a': 1, 'b': 2}
})

PR includes tests.

@jackton1
Copy link
Contributor

@peterfarrell Might also take a look at Postgres JSONField form field.

service_objects/fields.py Outdated Show resolved Hide resolved
@peterfarrell
Copy link
Contributor Author

@peterfarrell Might also take a look at Postgres JSONField form field.

Thanks @jackton1 for the suggestion. I thought about it, but given the data I have -- this seems like a better choice. Also, Django Rest Framework has a DictField and a ListField:

https://www.django-rest-framework.org/api-guide/fields/#dictfield

@peterfarrell peterfarrell changed the title Added support for DictField Added support for DictField / ListField Jan 22, 2020
@peterfarrell
Copy link
Contributor Author

I added support for ListField to have parity.

@peterfarrell
Copy link
Contributor Author

I am tempted to add additional features akin the ListField and DictField in the Django Rest Framework:

https://www.django-rest-framework.org/api-guide/fields/#listfield

@jackton1 @c17r Let me know your thoughts. I know they are issues related to using DRF serializers in addition to form fields. I think you ever went that direction -- we'd need these fields in the PR to keep parity.

@c17r c17r merged commit 10168a3 into mixxorz:master Jan 22, 2020
@c17r
Copy link
Collaborator

c17r commented Jan 22, 2020

@peterfarrell thanks for the contribution!

@peterfarrell
Copy link
Contributor Author

@c17r Thanks, let me know when we can get a build on PyPi.

@jackton1
Copy link
Contributor

jackton1 commented Jan 22, 2020

I am tempted to add additional features akin the ListField and DictField in the Django Rest Framework:

https://www.django-rest-framework.org/api-guide/fields/#listfield

@jackton1 @c17r Let me know your thoughts. I know they are issues related to using DRF serializers in addition to form fields. I think you ever went that direction -- we'd need these fields in the PR to keep parity.

@peterfarrell
Definitely like the idea you could take a look json-models for things like dict/json validation or using child pattern for values validation personally I use SimpleArrayField which enforces the expected child types ATM.

@peterfarrell
Copy link
Contributor Author

@jackton1 Thanks. I'll put some thought into it. I was leaning towards the DRF parameters just for simplicity assuming that if you're using Django -- you are likely using DRF for REST API / etc.

@seanlinehan
Copy link

Hey @c17r, this solves some problems we're running into as well. Any plan to push a new release to PyPi soon?

@c17r
Copy link
Collaborator

c17r commented Apr 22, 2020

We need @mixxorz for that I don't have PyPi access for this project.

@seanlinehan
Copy link

Ah got it! Good to know for the future. :-)

@mixxorz
Copy link
Owner

mixxorz commented Apr 23, 2020

I've just published a new release. 0.7.0

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

Successfully merging this pull request may close these issues.

5 participants