Commit c714b71b authored by Christophe Henry's avatar Christophe Henry

feat: add mecanism to disable exposing some models

> feat: enabled usage of metamodel's verbose_plural_name as a path when defined
parent 3f5a2e14
Pipeline #6361 passed with stage
in 1 minute and 29 seconds
......@@ -4,4 +4,5 @@ __version__ = '0.0.0'
options.DEFAULT_NAMES += (
'lookup_field', 'rdf_type', 'rdf_context', 'auto_author', 'owner_field', 'view_set', 'container_path',
'permission_classes', 'serializer_fields', 'nested_fields', 'depth', 'anonymous_perms', 'authenticated_perms',
'owner_perms', 'is_api_exposed'
import validators
import re
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models.base import ModelBase
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse_lazy, get_resolver
from django.urls import get_resolver, reverse_lazy
from django.utils.datastructures import MultiValueDictKeyError
from django.utils.decorators import classonlymethod
......@@ -31,7 +32,11 @@ class Model(models.Model):
def get_container_path(cls):
path = getattr(cls._meta, 'container_path', getattr(cls.Meta, 'container_path', None))
if path is None:
path = "{}s".format(cls._meta.object_name.lower())
plural_name = getattr(cls._meta, 'verbose_name_plural',
getattr(cls.Meta, 'verbose_name_plural', None))
path = (re.sub(r'\s', '', str(plural_name))
if plural_name is not None
else "{}s".format(cls._meta.object_name.lower()))
return cls.__clean_path(path)
......@@ -91,6 +96,7 @@ class Model(models.Model):
default_permissions = ('add', 'change', 'delete', 'view', 'control')
abstract = True
depth = 0
is_api_exposed = True
def resolve_id(cls, id):
......@@ -33,6 +33,12 @@ model_classes = {cls.__name__: cls for cls in Model.__subclasses__()}
for class_name in model_classes:
model_class = model_classes[class_name]
is_api_exposed = Model.get_meta(model_class, 'is_api_exposed', True)
# Skip models that should not be exposed through API
if not is_api_exposed:
path = __clean_path(model_class.get_container_path())
urls_fct = model_class.get_view_set().urls
urlpatterns.append(url(r'^' + path, include(
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment