-
-
Notifications
You must be signed in to change notification settings - Fork 944
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
docs(user): add query strings tutorial #2239
docs(user): add query strings tutorial #2239
Conversation
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.
Thanks for the PR, great work!
I've left a few suggestions
docs/user/tutorial.rst
Outdated
images = self._image_store.list(max_size) | ||
doc = { | ||
'images': [ | ||
{'href': '/images/'+image} for image in images |
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.
{'href': '/images/'+image} for image in images | |
{'href': '/images/' + image} for image in images |
def __init__(self, image_store): | ||
self._image_store = image_store | ||
|
||
def on_get(self, req, resp): |
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.
This version should be a static one like the above that serializes to msgpack, since we refer to it as "static"
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.
My bad 🥲 . You're totally right.
docs/user/tutorial.rst
Outdated
images = self._image_store.list(max_size) | ||
doc = { | ||
'images': [ | ||
{'href': '/images/'+image} for image in images |
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.
{'href': '/images/'+image} for image in images | |
{'href': '/images/' + image} for image in images |
docs/user/tutorial.rst
Outdated
] | ||
return images | ||
|
||
As you can see the method ``list`` has been added to ``ImageStore`` in order to return list of available images smaller than ``max_size`` unless it is not zero, in which case it will behave like there was no predicament of image size. |
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.
maybe we could use -1 for the "defaut" here?
docs/user/tutorial.rst
Outdated
return images | ||
|
||
As you can see the method ``list`` has been added to ``ImageStore`` in order to return list of available images smaller than ``max_size`` unless it is not zero, in which case it will behave like there was no predicament of image size. | ||
Let's try to save some binary data as images in the service and then try to retrieve their list. Execute the following commands in order to make 3 files as images with different sizes. |
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.
since these are not really images, we could use "images"
here and maybe say something like
Execute the following commands in order to simulate the creation of 3 files as images with different sizes. While these are not valid PNG files, they will work for this tutorial.
docs/user/tutorial.rst
Outdated
self._image_store = image_store | ||
|
||
def on_get(self, req, resp): | ||
max_size = int(req.params.get("maxsize", 0)) |
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 it would be useful to showcase get_param_as_int
here, so we could do
max_size = int(req.params.get("maxsize", 0)) | |
max_size = int(req.get_param_as_int("maxsize", default=0, min_value=1)) |
(I've added a min value but we may omit it too)
I have a question regarding a part of the code.
which I used from previous parts of the docs.
However, I didn't try to fix it here and I thought that maybe I should first report it as an issue and then resolve it in another PR. Am I right or should I try the fix on this PR since it's a small change? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2239 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 7726 7726
Branches 1071 1071
=========================================
Hits 7726 7726 ☔ View full report in Codecov by Sentry. |
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.
Thanks for this contribution, looks good for the most of it.
We just need to clean up things a bit before merging (see my comments inline, as well as @CaselIT's remarks).
|
||
Let's go back to the ``on_get`` method and create a dynamic response. We can use query strings to set maximum image size and get the list of all images smaller than the specified value. We will use method ``get_param_as_int`` to set a default value of ``-1`` in case no ``maxsize`` query string was provided and also to enable a minimum value validation. | ||
|
||
.. code:: python |
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.
Don't we need to update any example files on disk? And write tests for them too?
(See also: #2247.)
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.
Sure, I'll look into this.
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.
@vytas7, I see that a sample usage of query params is being used in the example file for wsgi.
falcon/examples/things_advanced.py
Line 158 in 65aa7f6
limit = req.get_param_as_int('limit') or 50 |
Are we looking for a more descriptive example?
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.
Hi again, no, sorry I was not very clear!
No, it has nothing to do with things_advanced.py
; what I meant was that we are tracking tutorial files in the Git tree as well, we even have some rudimentary tests for them. In this case it looks like you might need to update images.py
with your additions, and potentially even revise how the file develops further in this tutorial.
@vytas7 Would you please also help me on this? |
|
||
Let's go back to the ``on_get`` method and create a dynamic response. We can use query strings to set maximum image size and get the list of all images smaller than the specified value. We will use method ``get_param_as_int`` to set a default value of ``-1`` in case no ``maxsize`` query string was provided and also to enable a minimum value validation. | ||
|
||
.. code:: python |
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.
Hi again, no, sorry I was not very clear!
No, it has nothing to do with things_advanced.py
; what I meant was that we are tracking tutorial files in the Git tree as well, we even have some rudimentary tests for them. In this case it looks like you might need to update images.py
with your additions, and potentially even revise how the file develops further in this tutorial.
@vytas7 I'm very sorry for the very long delay. I mistakenly thought that all the tests were passed and I didn't got time to get back to the project since I was a little bit busy. |
No worries, @bssyousefi 🙂 |
I guess it's ready. I've updated the tests for the example |
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.
Nice work, just a couple of minor suggestions
Hi, |
Hi @bssyousefi, and thanks for bringing this up. No, I don't think so, I just need to review this again. |
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.
Let's merge this as-is, thanks for this improvement @bssyousefi!
It seems that there are a couple of minor inconsistencies, but that could be left as an exercise for the reader. Ultimately, we should move to the approach suggested in #2247, otherwise it is hard to keep track of all the minutiae by hand.
Summary of Changes
Fill in the placeholder for
Query Strings
in the documentation. The placeholder only existed on WSGI tutorial, so the proposed change is just about that part of the documentation.Related Issues
Fixes #475.
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once; it will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
docs/
.docs/
.versionadded
,versionchanged
, ordeprecated
directives.docs/_newsfragments/
, with the file name format{issue_number}.{fragment_type}.rst
. (Runtowncrier --draft
to ensure it renders correctly.)If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!
PR template inspired by the attrs project.