carltongibson / neapolitan

Quick CRUD views for Django
https://noumenal.es/neapolitan/
MIT License
485 stars 34 forks source link

NoReverseMatch when create view is not registered in urls.py #46

Closed nanuxbe closed 3 months ago

nanuxbe commented 3 months ago

Hello,

I'm finally trying out neapolitan :-)

So, my first use-case is to have a CRUD without the C (records are created by something else).

So assuming *ContactListView.get_urls(roles={Role.LIST}) in my urls.py, going to http://localhost:8000/contactlst/ produces a NoReverseMatch error.

This seems to be due to https://github.com/carltongibson/neapolitan/blob/main/src/neapolitan/views.py#L374

patching get_context_data to catch the exception leads to similar error during rendering from https://github.com/carltongibson/neapolitan/blob/main/src/neapolitan/templatetags/neapolitan.py#L9 so I'm not sure about where to go from here? Whether this is a feature or a bug.

Thank you for your time

nanuxbe commented 3 months ago

This seems to be related to https://github.com/carltongibson/neapolitan/pull/44

carltongibson commented 3 months ago

Hi @nanuxbe. Yes, good spot.

The list view template assumes you routed the create view. That's probably a bug rather than a feature: better would be to say if you routed the create view... (Same in get_context_data())

carltongibson commented 3 months ago

This seems to be related to https://github.com/carltongibson/neapolitan/pull/44

So yes: we only just added routing a subset of roles, so this is a hangover from that.

I think wrapping in try...except... and setting create_view_url to None in the context (and then using an {% if %} in the list template would be correct there.

For the actions helper, I guess that needs to be per-action, and then only rendering the links for the existing actions.

Would you fancy taking that on @nanuxbe? (If not, I will potter on it over the next period.)

Thanks for the report!

nanuxbe commented 3 months ago

Yes, I can take that on, this is basically already mostly what I've done to get it running locally, I'll clean this up and make a proper PR with it

carltongibson commented 3 months ago

Great thanks.

Essentially the templates (and helpers) need to handle the case where some view isn't routed.

Welcome aboard! ⛵️

carltongibson commented 3 months ago

Fixed in https://github.com/carltongibson/neapolitan/pull/47