Open spookylukey opened 3 years ago
@spookylukey Hi there! This seems to be a great idea, and I want to help out. How do you recommend proceeding?
@AliSayyah Thanks for your interest!
I'm assuming you already know some Python and Django - if not, this project might not be for you.
This is how I would go about it:
A quick look at your GitHub contributions makes me think you will not be lost with all of the above, but some of these steps could be hard if you've never done them before. I'm happy to try and help if you get stuck.
In addition: the following are not necessary, especially if you are overwhelmed by all this, but at some point I would highly recommend:
I wonder why not to generate them from function prototypes instead of checking?
@spookylukey Thank you for your explanations🙏 I`ll keep you updated about the process.
@KOLANICH Could you please explain more?
I wonder why not to generate them from function prototypes instead of checking?
That wouldn't solve the problem of them getting out of sync. In other frameworks, URLs and view functions are closer together, like in Flask, but in Django they are separated.
# urls.py
from django.urls import path
from . import views
urlpatterns = [
path('articles/2003/', views.special_case_2003),
path('articles/{}/', views.year_archive),
path('articles/{}/{}/', views.month_archive),
path('articles/{}/{}/{}/', views.article_detail),
# or
path('articles/{slash_delimited}', views.article_detail), #magic name
]
# views.py
def special_case(request):
pass
def year_archive(request, year: int):
pass
def month_archive(request, year: int, month: int):
pass
def article_detail(request, year: int, month: int, slug: slug):
pass
I created the repository and required workflows. I would appreciate any feedback. https://github.com/AliSayyah/django-urlconf-checks
@spookylukey hey! https://pypi.org/project/django-urlconfchecks/ the package is now functional. I'll start working on better tests and TODOs. Thank you for your assistance. https://github.com/AliSayyah/django-urlconfchecks/discussions/23 Can you please join me in this discussion?
Hey, this looks brilliant! 🎉️
I'll join that discussion.
Project description
Given some URLs configured like this (as per the Django docs):
And some views like this:
...we can check that the types of parameters match. So, for example, if we changed one of these but forget to change the other, we'd be immediately be notified, instead of waiting for runtime errors or test failures.
The good thing about this - I've already written a big chunk of the code! You can find it here: https://github.com/spookylukey/django-views-the-right-way/blob/master/code/the_right_way/url_checker.py . I've started using this code in some real projects, but it needs work, and I think it could be useful to a lot of people in the Django community.
What is missing is:
Relevant Technology
You need experience with Django and Python. Very advanced knowledge is not needed, but it will introduce you to introspection and type annotations if you don't have that knowledge already. The main skills used/developed will be to do with testing, documentation and package management.
Complexity and required time
Complexity
This is easily small enough to be managed by a single person, and will get your feet wet with running a small project.
Required time (ETA)
The bare minimum to get this project packaged could be done in a couple of days, but I think the project could benefit from tests, docs etc. which would take longer.
Categories
Help/guidance
I'm happy to give help/suggestions for anyone interested but needing some pointers with any aspects.