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

Extend register_model_view() to handle list views #18023

Closed
jeremystretch opened this issue Nov 15, 2024 · 1 comment
Closed

Extend register_model_view() to handle list views #18023

jeremystretch opened this issue Nov 15, 2024 · 1 comment
Assignees
Labels
netbox status: accepted This issue has been accepted for implementation topic: plugins Relates to the plugins framework type: feature Introduction of new functionality to the application
Milestone

Comments

@jeremystretch
Copy link
Member

Proposed Changes

We currently use register_model_view() to register detail views (edit, delete, etc.) for models, which obviates the need to declare explicit URL paths for each. This could be extended to support list views as well. For example, a common set of views might look like this:

# List view
@register_model_view(MyModel, list=True)
class FooListView(generic.ObjectListView):

# Detail view
@register_model_view(MyModel)
class MyModelView(generic.ObjectView):

# Add/edit views
@register_model_view(MyModel, 'edit')
@register_model_view(MyModel, 'add', list=True)
class MyModelEditView(generic.ObjectEditView):

# Delete view
@register_model_view(MyModel, 'delete')
class MyModelDeleteView(generic.ObjectDeleteView):

# Bulk import view
@register_model_view(MyModel, 'import', list=True)
class MyModelBulkImportView(generic.BulkImportView):

# Bulk delete view
@register_model_view(MyModel, 'delete', list=True)
class MyModelBulkDeleteView(generic.BulkDeleteView):

The corresponding set of URL paths could then be reduced to:

path('my-models/', include(get_model_urls('myapp', 'mymodel', list=True))),
path('my-models/<int:pk>/', include(get_model_urls('myapp', 'mymodel'))),

(This could potentially be reduced even further, but I'm also wary of over-optimizing.)

get_model_urls() will likewise need to be extended to differentiate between list and detail views.

Justification

This will allow us to reduce a substantial amount of boilerplate URL patterns without any breaking changes (AFAICT).

@jeremystretch jeremystretch added type: housekeeping Changes to the application which do not directly impact the end user status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Nov 15, 2024
@jeremystretch jeremystretch added the netbox label Nov 15, 2024 — with Linear
@jeremystretch jeremystretch self-assigned this Nov 15, 2024
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Nov 19, 2024
@jeremystretch jeremystretch added this to the v4.2 milestone Nov 19, 2024
@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application and removed type: housekeeping Changes to the application which do not directly impact the end user labels Nov 19, 2024
@jeremystretch
Copy link
Member Author

Reclassifying this as a light feature request, as we expose register_model_view() in the plugins API.

jeremystretch added a commit that referenced this issue Nov 20, 2024
* Extend register_model_view() to enable registering list views

* Register circuits list views with register_model_view()

* Register core list views with register_model_view()

* Fix bulk_edit & bulk_delete URL paths

* Register dcim list views with register_model_view() (WIP)

* Register dcim list views with register_model_view()

* Register extras list views with register_model_view()

* Register ipam list views with register_model_view()

* Register tenancy list views with register_model_view()

* Register users list views with register_model_view()

* Register virtualization list views with register_model_view()

* Register vpn list views with register_model_view()

* Register wireless list views with register_model_view()

* Add change note for register_model_view()
@jeremystretch jeremystretch added the topic: plugins Relates to the plugins framework label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
netbox status: accepted This issue has been accepted for implementation topic: plugins Relates to the plugins framework type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

1 participant