-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
…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): |
There was a problem hiding this comment.
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 %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work, @DavidOberholzer
@DavidOberholzer As discussed, please remove the files under 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 |
There was a problem hiding this comment.
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 %}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
generated/views.py
Outdated
import generated.schemas as schemas | ||
import generated.utils as utils | ||
|
||
import demo.schemas as schemas |
There was a problem hiding this comment.
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'), |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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...
An overwhelming 👍 |
…ode to templates views/urls. Changed commented line for jinja2 loader to work locally when commented out