Replace `base_name` => `basename` for consisntency's sake
Changed on DRF 3.12.x and related to PR https://github.com/encode/django-rest-framework/pull/5990
This commit is contained in:
parent
c21a52a756
commit
50f916fa4d
|
@ -23,16 +23,16 @@ def link_wrap(view, view_names):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def insert_links(viewset, base_name):
|
def insert_links(viewset, basename):
|
||||||
collection_links = ['api-root', '%s-list' % base_name]
|
collection_links = ['api-root', '%s-list' % basename]
|
||||||
object_links = ['api-root', '%s-list' % base_name, '%s-detail' % base_name]
|
object_links = ['api-root', '%s-list' % basename, '%s-detail' % basename]
|
||||||
exception_links = ['api-root']
|
exception_links = ['api-root']
|
||||||
list_links = ['api-root']
|
list_links = ['api-root']
|
||||||
retrieve_links = ['api-root', '%s-list' % base_name]
|
retrieve_links = ['api-root', '%s-list' % basename]
|
||||||
# Determine any `@action` or `@link` decorated methods on the viewset
|
# Determine any `@action` or `@link` decorated methods on the viewset
|
||||||
for methodname in dir(viewset):
|
for methodname in dir(viewset):
|
||||||
method = getattr(viewset, methodname)
|
method = getattr(viewset, methodname)
|
||||||
view_name = '%s-%s' % (base_name, methodname.replace('_', '-'))
|
view_name = '%s-%s' % (basename, methodname.replace('_', '-'))
|
||||||
if hasattr(method, 'collection_bind_to_methods'):
|
if hasattr(method, 'collection_bind_to_methods'):
|
||||||
list_links.append(view_name)
|
list_links.append(view_name)
|
||||||
retrieve_links.append(view_name)
|
retrieve_links.append(view_name)
|
||||||
|
|
|
@ -18,33 +18,33 @@ class LogApiMixin(object):
|
||||||
message = _('Added.')
|
message = _('Added.')
|
||||||
self.log(request, message, ADDITION, instance=self.serializer.instance)
|
self.log(request, message, ADDITION, instance=self.serializer.instance)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
""" stores serializer for accessing instance on create() """
|
""" stores serializer for accessing instance on create() """
|
||||||
super(LogApiMixin, self).perform_create(serializer)
|
super(LogApiMixin, self).perform_create(serializer)
|
||||||
self.serializer = serializer
|
self.serializer = serializer
|
||||||
|
|
||||||
def update(self, request, *args, **kwargs):
|
def update(self, request, *args, **kwargs):
|
||||||
from django.contrib.admin.models import CHANGE
|
from django.contrib.admin.models import CHANGE
|
||||||
response = super(LogApiMixin, self).update(request, *args, **kwargs)
|
response = super(LogApiMixin, self).update(request, *args, **kwargs)
|
||||||
message = _('Changed data')
|
message = _('Changed data')
|
||||||
self.log(request, message, CHANGE)
|
self.log(request, message, CHANGE)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def partial_update(self, request, *args, **kwargs):
|
def partial_update(self, request, *args, **kwargs):
|
||||||
from django.contrib.admin.models import CHANGE
|
from django.contrib.admin.models import CHANGE
|
||||||
response = super(LogApiMixin, self).partial_update(request, *args, **kwargs)
|
response = super(LogApiMixin, self).partial_update(request, *args, **kwargs)
|
||||||
message = _('Changed %s') % response.data
|
message = _('Changed %s') % response.data
|
||||||
self.log(request, message, CHANGE)
|
self.log(request, message, CHANGE)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
from django.contrib.admin.models import DELETION
|
from django.contrib.admin.models import DELETION
|
||||||
message = _('Deleted')
|
message = _('Deleted')
|
||||||
self.log(request, message, DELETION)
|
self.log(request, message, DELETION)
|
||||||
response = super(LogApiMixin, self).destroy(request, *args, **kwargs)
|
response = super(LogApiMixin, self).destroy(request, *args, **kwargs)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def log(self, request, message, action, instance=None):
|
def log(self, request, message, action, instance=None):
|
||||||
from django.contrib.admin.models import LogEntry
|
from django.contrib.admin.models import LogEntry
|
||||||
instance = instance or self.get_object()
|
instance = instance or self.get_object()
|
||||||
|
@ -64,21 +64,21 @@ class LinkHeaderRouter(DefaultRouter):
|
||||||
APIRoot = import_class(settings.ORCHESTRA_API_ROOT_VIEW)
|
APIRoot = import_class(settings.ORCHESTRA_API_ROOT_VIEW)
|
||||||
APIRoot.router = self
|
APIRoot.router = self
|
||||||
return APIRoot.as_view()
|
return APIRoot.as_view()
|
||||||
|
|
||||||
def register(self, prefix, viewset, base_name=None):
|
def register(self, prefix, viewset, basename=None):
|
||||||
""" inserts link headers on every viewset """
|
""" inserts link headers on every viewset """
|
||||||
if base_name is None:
|
if basename is None:
|
||||||
base_name = self.get_default_base_name(viewset)
|
basename = self.get_default_basename(viewset)
|
||||||
insert_links(viewset, base_name)
|
insert_links(viewset, basename)
|
||||||
self.registry.append((prefix, viewset, base_name))
|
self.registry.append((prefix, viewset, basename))
|
||||||
|
|
||||||
def get_viewset(self, prefix_or_model):
|
def get_viewset(self, prefix_or_model):
|
||||||
for _prefix, viewset, __ in self.registry:
|
for _prefix, viewset, __ in self.registry:
|
||||||
if _prefix == prefix_or_model or viewset.queryset.model == prefix_or_model:
|
if _prefix == prefix_or_model or viewset.queryset.model == prefix_or_model:
|
||||||
return viewset
|
return viewset
|
||||||
msg = "%s does not have a regiestered viewset" % prefix_or_model
|
msg = "%s does not have a regiestered viewset" % prefix_or_model
|
||||||
raise KeyError(msg)
|
raise KeyError(msg)
|
||||||
|
|
||||||
def insert(self, prefix_or_model, name, field, **kwargs):
|
def insert(self, prefix_or_model, name, field, **kwargs):
|
||||||
""" Dynamically add new fields to an existing serializer """
|
""" Dynamically add new fields to an existing serializer """
|
||||||
viewset = self.get_viewset(prefix_or_model)
|
viewset = self.get_viewset(prefix_or_model)
|
||||||
|
|
Loading…
Reference in New Issue