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

Single taxonomy view [FC-0030] #78

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

ChrisChV
Copy link
Contributor

@ChrisChV ChrisChV commented Sep 8, 2023

Description

Adds a new view to return tags for a given taxonomy. With this view, you can:

  • Return paginated root tags.
  • Return paginated children of given tag.
  • Search tags in all taxonomy.
  • Search tags on a children list.

Also updates the ADR 0014 with some logics on search.

Supporting Information

Testing Instructions

  • Ensure that the tests cover the expected behavior of the view as described in the related issue.
  • Run this command to create a small taxonomy:
python manage.py loaddata tests/openedx_tagging/core/fixtures/tagging.yaml
  • Run this commands to create a large taxonomy:
python manage.py shell
> from tests.openedx_tagging.core.tagging.test_views import TestTaxonomyTagsView
> case = TestTaxonomyTagsView()
> case.setUp()
> case.build_large_taxonomy()
> from openedx_tagging.core.tagging.models import Taxonomy, Tag
> Taxonomy.objects.filter(name="Large Taxonomy")

@openedx-webhooks
Copy link

openedx-webhooks commented Sep 8, 2023

Thanks for the pull request, @ChrisChV! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 8, 2023
@ChrisChV ChrisChV marked this pull request as draft September 8, 2023 23:05
@ChrisChV ChrisChV changed the title Single taxonomy view Single taxonomy view [FC-0030] Sep 8, 2023
@ChrisChV ChrisChV marked this pull request as ready for review September 13, 2023 20:26
@ChrisChV
Copy link
Contributor Author

@bradenmacdonald Do you have any idea why quality errors occur? We have the same syntax here and here

@bradenmacdonald
Copy link
Contributor

@ChrisChV Yes, it's very simple - you need to put from __future__ import annotations at the top of the file :)
It's because Open edX is still using python 3.8.

tag_set = self.tag_set.all()

if self.allow_free_text:
return tag_set.none()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really a big fan of the idea that we have to call different APIs to get the tags based on the type of taxonomy. It would be nice if the API could handle that implementation detail internally. We can think about this for later though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean having two functions? get_tags and get_filtered_tags?

Copy link
Contributor

Choose a reason for hiding this comment

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

No I mean for example that it would be nice if search_tags worked for any taxonomy, but right now it only works for taxonomies that aren't free text. We can change that in the future though; no change for now. After all we have excluded free text from the MVP anyways.

openedx_tagging/core/tagging/models/base.py Show resolved Hide resolved
openedx_tagging/core/tagging/rest_api/paginators.py Outdated Show resolved Hide resolved
openedx_tagging/core/tagging/rest_api/v1/permissions.py Outdated Show resolved Hide resolved

class TagsPagination(DefaultPagination):
"""
Custom paginator that returns the range index of the current page
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this useful/necessary? As far as I can see, we're not using it (yet).

It's always a good idea to put the "why" into the docstring so that in the future people know why it's here and can remove the code if it's not needed. If we don't say why and it never gets used, the code may sit around forever anyways, if nobody knows whether it's important or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's for openedx/modular-learning#111 , I'm actually going to suggest that we exclude that from the MVP or at least do it later as part of Step 4, not implement it now in Step 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's always a good idea to put the "why" into the docstring so that in the future people know why it's here and can remove the code if it's not needed.

It is because of this discussion. The range index of the current page is shown in the UI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it's for openedx/modular-learning#111 , I'm actually going to suggest that we exclude that from the MVP or at least do it later as part of Step 4, not implement it now in Step 2.

Ok, I see. In that case, should I remove everything related to range index?

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 updated this here: 6dded73

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's more of a UI thing. Especially when we're tight for budget, let's exclude it for now and we can consider adding it later when we implement that story. Also I think it makes more sense to implement it generally for the whole platform, not just for the tagging use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I think it makes more sense to implement it generally for the whole platform, not just for the tagging use case.

I have implemented it that way because of how special this tag view is. We have to change the paginator to disable pagination in that view.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok. Well if you want to keep what you have it's fine with me. I just don't want to spend any more time on it now.

openedx_tagging/core/tagging/rest_api/v1/views.py Outdated Show resolved Hide resolved
openedx_tagging/core/tagging/rest_api/v1/views.py Outdated Show resolved Hide resolved
tests/openedx_tagging/core/tagging/test_models.py Outdated Show resolved Hide resolved
@bradenmacdonald
Copy link
Contributor

I'm not sure why the CLA check isn't working. Please rebase/squash this tomorrow and ping me to merge ; hopefully the check is fixed by then.

docs: ADR for pagination and repr of single taxonomy api

feat: Initial view and pagination config

feat: get_range_index added to paginator

feat: View for get tags

- Get paginated root tags
- Get paginated children tags
- Get all tags for small taxonomies
- Tags structure for response

chore: Adding permissions and docstrings

style: quality

feat: Search added to get tags view

feat: searching tags

docs: Adding comments on the view

docs: Update ADR with search logic

chore: fix quality checks

chore: fix tests

style: Nits on type hints and docstrings and comments

fix: Delete all about range index in paginators
@ChrisChV ChrisChV force-pushed the chris/single-taxonomy-view branch from 6dded73 to d7e5872 Compare September 20, 2023 20:16
@ChrisChV
Copy link
Contributor Author

I'm not sure why the CLA check isn't working. Please rebase/squash this tomorrow and ping me to merge ; hopefully the check is fixed by then.

@bradenmacdonald Done

@bradenmacdonald bradenmacdonald merged commit 69519f4 into openedx:main Sep 20, 2023
6 checks passed
@openedx-webhooks
Copy link

@ChrisChV 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@bradenmacdonald bradenmacdonald deleted the chris/single-taxonomy-view branch September 20, 2023 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Tagging] Single taxonomy view API
3 participants