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 formdata to payloads for generating templates. Added formdata c… #4

Merged
merged 3 commits into from
Nov 8, 2017

Conversation

DavidOberholzer
Copy link
Contributor

…ode to templates views/urls. Changed commented line for jinja2 loader to work locally when commented out

…ode to templates views/urls. Changed commented line for jinja2 loader to work locally when commented out
@@ -15,7 +15,7 @@ class AbstractStubClass(object):
{% for verb, info in verbs|dictsort(true) %}

@staticmethod
def {{ info.operation }}(request, {% if info.body %}body, {% endif %}{% for ra in info.required_args %}{{ ra.name }}, {% endfor %}{% for oa in info.optional_args %}{{ oa.name }}=None, {% endfor %}*args, **kwargs):
def {{ info.operation }}(request, {% if info.body %}body, {% endif %}{% if info.formdata %}formdata, {% endif %}{% for ra in info.required_args %}{{ ra.name }}, {% endfor %}{% for oa in info.optional_args %}{{ oa.name }}=None, {% endfor %}*args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you use formdata here and formData elsewhere. It needs to be consistent. Can we maybe change it to form_data everywhere, please?

@@ -83,7 +83,23 @@ def {{ verb }}(self, request, {% for ra in info.required_args %}{{ ra.name }}, {
return HttpResponseBadRequest("Body required")

{% endif %}
result = Stubs.{{ info.operation }}(request, {% if info.body %}body, {% endif %}{% for ra in info.required_args %}{{ ra.name }}, {% endfor %}{% for oa in info.optional_args %}{{ oa.name }}=None, {% endfor %}*args, **kwargs)
{% if info.formdata %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work, @DavidOberholzer

@cobusc
Copy link
Contributor

cobusc commented Nov 7, 2017

@DavidOberholzer As discussed, please remove the files under demo/ that were added. You can explicitly list them in the .gitignore file to prevent this. (My bad)

You made my day with this PR. Thank you very much!

@@ -39,7 +39,7 @@ class MockedStubClass(AbstractStubClass):
{% for verb, info in verbs|dictsort(true) %}

@staticmethod
def {{ info.operation }}(request, {% if info.body %}body, {% endif %}{% for ra in info.required_args %}{{ ra.name }}, {% endfor %}{% for oa in info.optional_args %}{{ oa.name }}=None, {% endfor %}*args, **kwargs):
def {{ info.operation }}(request, {% if info.body %}body, {% endif %}{% if info.formdata %}formData, {% endif %}{% for ra in info.required_args %}{{ ra.name }}, {% endfor %}{% for oa in info.optional_args %}{{ oa.name }}=None, {% endfor %}*args, **kwargs):
"""
:param request: An HttpRequest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a parameter description line here for body and form_data if it is available. Something like

{% if info.body %}
:param body: dict A dictionary containing the parsed and validated body 
{% endif %}
{% if info.formdata %}
:param form_data: dict A dictionary containing form fields and their values. In the case where the form fields refer to uploaded files, the values will be instances of `django.core.files.uploadedfile.UploadedFile`
{% endif %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought of that, but formdata is in the request, so it won't ever be a parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait, thats in stubs.py i see sorry you are right. I was thinking of views.py

…ded to git ignore. Replaced generated files with new stubs and views. Added param description in docstrings for form_data in stubs.py
import generated.schemas as schemas
import generated.utils as utils

import demo.schemas as schemas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you generated this using demo instead of generated as module.

@@ -79,8 +79,8 @@ def render_to_string(filename, context, path=None):
:return: The rendered template as a string
"""
return jinja2.Environment(
# loader=jinja2.FileSystemLoader(path or './'),
loader=jinja2.PackageLoader("swagger_django_generator", "templates"),
loader=jinja2.FileSystemLoader(path or './swagger_django_generator/templates'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we keep this as a PackageLoader?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah darn forgot to comment this out again...

@cobusc
Copy link
Contributor

cobusc commented Nov 8, 2017

An overwhelming 👍

@DavidOberholzer DavidOberholzer merged commit 3e80046 into master Nov 8, 2017
@DavidOberholzer DavidOberholzer deleted the feature/FileUploads branch November 8, 2017 08:03
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.

2 participants