Skip to content

Default to default actions of view if .as_view(actions=None) #3742

@niklasfemerstrand

Description

@niklasfemerstrand

In the latest Django stable one can't use patterns() anymore:

RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.

This was quite nice as one didn't have to pass default actions to views with default actions. When doing the following today:

urlpatterns = [
    url(r"things", views.ThingView.as_view()),
]

We get a warning from the .as_view() override due to the way that #2171 was solved with #2175:

TypeError: The actions argument must be provided when calling .as_view() on a ViewSet. For example .as_view({'get': 'list'})

The problematic part is when ThingView uses e.g. ModelViewSet or another viewset with default actions defined. It would be nice if the patch for #2171 would take the type of view in consideration and if actions is None default to the actions that exist in the viewset by default. It currently appears that we need to solve the problem this way, passing actions dictionaries for a viewset with default actions set because actions is not permitted to be None and does not default to the default values of the view:

urlpatterns = [
    url(r"things/$", views.ThingView.as_view({"get": "list"}), name="ticket-list"),
    url(r"things/(?P<pk>[0-9]+)/$", views.ThingView.as_view({"get": "retrieve", "post": "create", "put": "update", "patch": "partial_update", "delete": "destroy"}), name="ticket-detail"),
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy