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

Load a folder of views #24

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Load a folder of views #24

wants to merge 5 commits into from

Conversation

Mte90
Copy link

@Mte90 Mte90 commented Jan 24, 2024

This fix #13

In urls.py it is required that code:

import os
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
urlpatterns = [
path("", include_view_urls(extra_modules=[root + "/portal/views"])),
]

In this way loads from a folder the various views automatically.
I will update the readme tomorrow (also some parameters like login_required are not documented, I will do that).

@Mte90
Copy link
Author

Mte90 commented Jan 25, 2024

Now the readme is updated but require a review from @valberg

@valberg
Copy link
Owner

valberg commented Jan 29, 2024

Hi @Mte90

Thanks for the pull request.

I'm not sure that this is the right approach. I would much rather that we traverse the contents of a python module than directly interacting with the filesystem. I think that could be accomplished by using pkg_util from the standard library.

Also I think we should be explicit about how the functionality is used. One should be explicit about wanting to scan all modules in a package, so we should introduce a new keyword argument "extra_packages" to solve this case.

Basically I want the API to be:

include_view_urls(
    extra_modules=["dotted.path.to.module"],
    extra_packages=["dotted.path.to.package"],
)


* `paths`: is in a plural form because support also a list of paths
* `name` the classic route name
* `namespace`: {I don't know what to write here}
Copy link
Author

Choose a reason for hiding this comment

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

it is required a review here

@Mte90
Copy link
Author

Mte90 commented Jan 29, 2024

So I added the new parameter and updated the readme but about pkg_util I don't know how to proceed.

To me is better if we don't know need to to define a variable with the root folder so it should be more fast butI don't know how to achieve it, I am not so much experience in this python knowledge.

@Mte90
Copy link
Author

Mte90 commented Jul 4, 2024

ping @valberg

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.

View not detected
2 participants