From 50f916fa4dc45996a0c2e35394436ee1c45ca509 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Thu, 8 Jul 2021 12:46:55 +0200 Subject: [PATCH] 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 --- orchestra/api/helpers.py | 10 +++++----- orchestra/api/options.py | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/orchestra/api/helpers.py b/orchestra/api/helpers.py index 67594455..53803d9a 100644 --- a/orchestra/api/helpers.py +++ b/orchestra/api/helpers.py @@ -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) diff --git a/orchestra/api/options.py b/orchestra/api/options.py index 8b377564..4d429a03 100644 --- a/orchestra/api/options.py +++ b/orchestra/api/options.py @@ -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)