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:
Santiago L 2021-07-08 12:46:55 +02:00
parent c21a52a756
commit 50f916fa4d
2 changed files with 18 additions and 18 deletions

View File

@ -23,16 +23,16 @@ def link_wrap(view, view_names):
return wrapper
def insert_links(viewset, base_name):
collection_links = ['api-root', '%s-list' % base_name]
object_links = ['api-root', '%s-list' % base_name, '%s-detail' % base_name]
def insert_links(viewset, basename):
collection_links = ['api-root', '%s-list' % basename]
object_links = ['api-root', '%s-list' % basename, '%s-detail' % basename]
exception_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
for methodname in dir(viewset):
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'):
list_links.append(view_name)
retrieve_links.append(view_name)

View File

@ -18,33 +18,33 @@ class LogApiMixin(object):
message = _('Added.')
self.log(request, message, ADDITION, instance=self.serializer.instance)
return response
def perform_create(self, serializer):
""" stores serializer for accessing instance on create() """
super(LogApiMixin, self).perform_create(serializer)
self.serializer = serializer
def update(self, request, *args, **kwargs):
from django.contrib.admin.models import CHANGE
response = super(LogApiMixin, self).update(request, *args, **kwargs)
message = _('Changed data')
self.log(request, message, CHANGE)
return response
def partial_update(self, request, *args, **kwargs):
from django.contrib.admin.models import CHANGE
response = super(LogApiMixin, self).partial_update(request, *args, **kwargs)
message = _('Changed %s') % response.data
self.log(request, message, CHANGE)
return response
def destroy(self, request, *args, **kwargs):
from django.contrib.admin.models import DELETION
message = _('Deleted')
self.log(request, message, DELETION)
response = super(LogApiMixin, self).destroy(request, *args, **kwargs)
return response
def log(self, request, message, action, instance=None):
from django.contrib.admin.models import LogEntry
instance = instance or self.get_object()
@ -64,21 +64,21 @@ class LinkHeaderRouter(DefaultRouter):
APIRoot = import_class(settings.ORCHESTRA_API_ROOT_VIEW)
APIRoot.router = self
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 """
if base_name is None:
base_name = self.get_default_base_name(viewset)
insert_links(viewset, base_name)
self.registry.append((prefix, viewset, base_name))
if basename is None:
basename = self.get_default_basename(viewset)
insert_links(viewset, basename)
self.registry.append((prefix, viewset, basename))
def get_viewset(self, prefix_or_model):
for _prefix, viewset, __ in self.registry:
if _prefix == prefix_or_model or viewset.queryset.model == prefix_or_model:
return viewset
msg = "%s does not have a regiestered viewset" % prefix_or_model
raise KeyError(msg)
def insert(self, prefix_or_model, name, field, **kwargs):
""" Dynamically add new fields to an existing serializer """
viewset = self.get_viewset(prefix_or_model)