noirbizarre / django.js

Javascript tools for Django
http://djangojs.readthedocs.org/en/latest/
GNU Lesser General Public License v3.0
181 stars 81 forks source link

Adding none-named views to resolve #15

Closed aschemschat closed 11 years ago

aschemschat commented 11 years ago

Just a quick question (Maybe suggestion?):

sometimes i dont have supplied names for my views, maybe like this:

url(r'^new_obj$', 'project.main.views.new_object'),
url(r'^load_obj$', 'project.main.views.load_object', name="load"),

which results in only beeing able to do the following, because new_object is not found

Django.url("load")

If, in the utils.py, the function _get_urls(...) is modified as follows, there would be a default for the name:

if issubclass(pattern.__class__, RegexURLPattern):            
    func_name =  u"{0}.{1}".format(pattern.callback.__module__,pattern.callback.__name__)
    pattern_name = pattern.name or func_name
    if pattern_name:
        ...

which would be resolved in JS as:

Django.url("project.main.views.new_object")

Maybee class-based views may mess that up, but a type-check of function would prevent that and also maybe include a Setting to prevent this. Would this be an idea worth implementing?

Greetings and thanks for the great util-package :)

noirbizarre commented 11 years ago

Interesting! I totally forgot this use case (I never call reverse() for unnamed url).

I will look at it but I will provide an optionnal setting because it an generate a lot of noise if enabled by default!

aschemschat commented 11 years ago

Thanks for the fix :)