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

Feature 307 integrate drf browsable api #317

Merged
merged 2 commits into from
Jun 21, 2022

Conversation

mina-atef-00
Copy link
Collaborator

Fixes #307

Type of change:

  • New feature (change which adds functionality).

What's Changed:

  • Added drf browsable api switch in env.template
  • Added get_drf_template_mode() to return which drf template mode to use in DEFAULT_RENDERER_CLASSES reading the env

Screenshots:

  1. DRF_BROWSABLE_API_MODE=yes
    image

  2. DRF_BROWSABLE_API_MODE=no
    image


Affected URLs:

e.g. 127.0.0.1:8000/*


Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings.

@mina-atef-00
Copy link
Collaborator Author

mina-atef-00 commented Jun 19, 2022

@2ynn there are some forms like in HarvestViewset.list() (and the rest of the list functions) that aren't serializeable. (returned by get_filter_context() in api.py.

For example I get this error when requesting HTML format when the browsable api is on:
image
I think the list function needs refactoring for the context in general.

@mina-atef-00
Copy link
Collaborator Author

Also what do you think if we use a harvest list serializer that returns less data than the original serializer? using the big database made the whole site pretty unusable for me. Maybe this combined with pagination would make a lot of pages a lot faster.

@2ynn
Copy link
Collaborator

2ynn commented Jun 19, 2022

@mina-andajos for filtering we should use built-in rest filtering (to be tested in Browsable API)
https://www.django-rest-framework.org/api-guide/filtering/#filtering

Filter forms should already be generated for you without needing to pass them to context manually. See see venv/lib/python3.9/site-packages/rest_framework/templates/rest_framework/filters/*.html for example.

Crispy forms might be what you are looking for: https://django-filter.readthedocs.io/en/main/guide/rest_framework.html#crispy-forms

@mina-atef-00
Copy link
Collaborator Author

@mina-andajos for filtering we should use built-in rest filtering (to be tested in Browsable API)
https://www.django-rest-framework.org/api-guide/filtering/#filtering

Filter forms should already be generated for you without needing to pass them to context manually. See see venv/lib/python3.9/site-packages/rest_framework/templates/rest_framework/filters/*.html for example.

Crispy forms might be what you are looking for: https://django-filter.readthedocs.io/en/main/guide/rest_framework.html#crispy-forms

thanks, i looked into the rest filtering doc but was still confused on how to implement that.

Copy link
Collaborator

@2ynn 2ynn left a comment

Choose a reason for hiding this comment

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

Nice! I'll approve now so you can move on but if you don't mind please move the function closer to where it's being used. Thanks!

saskatoon/saskatoon/settings.py Outdated Show resolved Hide resolved
@mina-atef-00 mina-atef-00 force-pushed the Feature-307-integrate_drf_browsable_api branch from cea6fc8 to 4b1553c Compare June 21, 2022 11:56
@mina-atef-00 mina-atef-00 force-pushed the Feature-307-integrate_drf_browsable_api branch from 4b1553c to 767a475 Compare June 21, 2022 11:59
@mina-atef-00 mina-atef-00 merged commit 1fc4ed4 into develop Jun 21, 2022
@2ynn 2ynn deleted the Feature-307-integrate_drf_browsable_api branch March 30, 2024 00:55
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.

Integrate Django REST Browsable API
2 participants