# Path: dynamic_rest/meta.py
# def get_model_table(model):
#     try:
#         return model._meta.db_table
#     except BaseException:
#         return None
# 
# Path: dynamic_rest/conf.py
# DYNAMIC_REST = {
#     # DEBUG: enable/disable internal debugging
#     'DEBUG': False,
# 
#     # ENABLE_BROWSABLE_API: enable/disable the browsable API.
#     # It can be useful to disable it in production.
#     'ENABLE_BROWSABLE_API': True,
# 
#     # ENABLE_LINKS: enable/disable relationship links
#     'ENABLE_LINKS': True,
# 
#     # ENABLE_SERIALIZER_CACHE: enable/disable caching of related serializers
#     'ENABLE_SERIALIZER_CACHE': True,
# 
#     # ENABLE_SERIALIZER_OBJECT_CACHE: enable/disable caching of serialized
#     # objects within a serializer instance/context. This can yield
#     # significant performance improvements in cases where the same objects
#     # are sideloaded repeatedly.
#     'ENABLE_SERIALIZER_OBJECT_CACHE': True,
# 
#     # ENABLE_SERIALIZER_OPTIMIZATIONS: enable/disable representation speedups
#     'ENABLE_SERIALIZER_OPTIMIZATIONS': True,
# 
#     # ENABLE_BULK_PARTIAL_CREATION: enable/disable partial creation in bulk
#     'ENABLE_BULK_PARTIAL_CREATION': False,
# 
#     # ENABLE_BULK_UPDATE: enable/disable update in bulk
#     'ENABLE_BULK_UPDATE': True,
# 
#     # ENABLE_PATCH_ALL: enable/disable patch by queryset
#     'ENABLE_PATCH_ALL': False,
# 
#     # DEFER_MANY_RELATIONS: automatically defer many-relations, unless
#     # `deferred=False` is explicitly set on the field.
#     'DEFER_MANY_RELATIONS': False,
# 
#     # LIST_SERIALIZER_CLASS: Globally override the list serializer class.
#     # Default is `DynamicListSerializer` and also can be overridden for
#     # each serializer class by setting `Meta.list_serializer_class`.
#     'LIST_SERIALIZER_CLASS': None,
# 
#     # MAX_PAGE_SIZE: global setting for max page size.
#     # Can be overriden at the viewset level.
#     'MAX_PAGE_SIZE': None,
# 
#     # PAGE_QUERY_PARAM: global setting for the pagination query parameter.
#     # Can be overriden at the viewset level.
#     'PAGE_QUERY_PARAM': 'page',
# 
#     # PAGE_SIZE: global setting for page size.
#     # Can be overriden at the viewset level.
#     'PAGE_SIZE': None,
# 
#     # PAGE_SIZE_QUERY_PARAM: global setting for the page size query parameter.
#     # Can be overriden at the viewset level.
#     'PAGE_SIZE_QUERY_PARAM': 'per_page',
# 
#     # ADDITIONAL_PRIMARY_RESOURCE_PREFIX: String to prefix additional
#     # instances of the primary resource when sideloading.
#     'ADDITIONAL_PRIMARY_RESOURCE_PREFIX': '+',
# 
#     # Enables host-relative links.  Only compatible with resources registered
#     # through the dynamic router.  If a resource doesn't have a canonical
#     # path registered, links will default back to being resource-relative urls
#     'ENABLE_HOST_RELATIVE_LINKS': True,
# 
#     # Enables caching of serializer fields to speed up serializer usage
#     # Needs to also be configured on a per-serializer basis
#     'ENABLE_FIELDS_CACHE': False,
# 
#     # Enables use of hashid fields
#     'ENABLE_HASHID_FIELDS': False,
# 
#     # Salt value to salt hash ids.
#     # Needs to be non-nullable if 'ENABLE_HASHID_FIELDS' is set to True
#     'HASHIDS_SALT': None,
# }
# CLASS_ATTRS = [
#     'LIST_SERIALIZER_CLASS',
# ]
# class Settings(object):
#     def __init__(self, name, defaults, settings, class_attrs=None):
#     def _reload(self, value):
#     def _load_class(self, attr, val):
#     def __getattr__(self, attr):
#     def _settings_changed(self, *args, **kwargs):


import copy
import six
import rest_framework
            import traceback
from collections import OrderedDict
    from django.urls import get_script_prefix
    from django.core.urlresolvers import get_script_prefix
from rest_framework import views
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.routers import DefaultRouter, Route
from dynamic_rest.meta import get_model_table
from dynamic_rest.conf import settings
    from rest_framework.routers import replace_methodname
    # structure, for now it is capped at a single level
    # for UX reasons
    for group_name, endpoints in sorted(
        six.iteritems(directory),
        key=sort_key
    ):
        endpoints_list = []
        for endpoint_name, endpoint in sorted(
            six.iteritems(endpoints),
            key=sort_key
        ):
            if endpoint_name[:1] == '_':
                continue
            endpoint_url = get_url(endpoint.get('_url', None))
            active = is_active_url(path, endpoint_url)
            endpoints_list.append(
                (endpoint_name, endpoint_url, [], active)
            )

        url = get_url(endpoints.get('_url', None))
        active = is_active_url(path, url)
        directory_list.append(
            (group_name, url, endpoints_list, active)
        )
    return directory_list


def modify_list_route(routes):
    # Identify the list route, add PATCH so we can
    # have bulk PATCH requests

# Path: dynamic_rest/meta.py
# def get_model_table(model):
#     try:
#         return model._meta.db_table
#     except BaseException:
#         return None
# 
# Path: dynamic_rest/conf.py
# DYNAMIC_REST = {
#     # DEBUG: enable/disable internal debugging
#     'DEBUG': False,
# 
#     # ENABLE_BROWSABLE_API: enable/disable the browsable API.
#     # It can be useful to disable it in production.
#     'ENABLE_BROWSABLE_API': True,
# 
#     # ENABLE_LINKS: enable/disable relationship links
#     'ENABLE_LINKS': True,
# 
#     # ENABLE_SERIALIZER_CACHE: enable/disable caching of related serializers
#     'ENABLE_SERIALIZER_CACHE': True,
# 
#     # ENABLE_SERIALIZER_OBJECT_CACHE: enable/disable caching of serialized
#     # objects within a serializer instance/context. This can yield
#     # significant performance improvements in cases where the same objects
#     # are sideloaded repeatedly.
#     'ENABLE_SERIALIZER_OBJECT_CACHE': True,
# 
#     # ENABLE_SERIALIZER_OPTIMIZATIONS: enable/disable representation speedups
#     'ENABLE_SERIALIZER_OPTIMIZATIONS': True,
# 
#     # ENABLE_BULK_PARTIAL_CREATION: enable/disable partial creation in bulk
#     'ENABLE_BULK_PARTIAL_CREATION': False,
# 
#     # ENABLE_BULK_UPDATE: enable/disable update in bulk
#     'ENABLE_BULK_UPDATE': True,
# 
#     # ENABLE_PATCH_ALL: enable/disable patch by queryset
#     'ENABLE_PATCH_ALL': False,
# 
#     # DEFER_MANY_RELATIONS: automatically defer many-relations, unless
#     # `deferred=False` is explicitly set on the field.
#     'DEFER_MANY_RELATIONS': False,
# 
#     # LIST_SERIALIZER_CLASS: Globally override the list serializer class.
#     # Default is `DynamicListSerializer` and also can be overridden for
#     # each serializer class by setting `Meta.list_serializer_class`.
#     'LIST_SERIALIZER_CLASS': None,
# 
#     # MAX_PAGE_SIZE: global setting for max page size.
#     # Can be overriden at the viewset level.
#     'MAX_PAGE_SIZE': None,
# 
#     # PAGE_QUERY_PARAM: global setting for the pagination query parameter.
#     # Can be overriden at the viewset level.
#     'PAGE_QUERY_PARAM': 'page',
# 
#     # PAGE_SIZE: global setting for page size.
#     # Can be overriden at the viewset level.
#     'PAGE_SIZE': None,
# 
#     # PAGE_SIZE_QUERY_PARAM: global setting for the page size query parameter.
#     # Can be overriden at the viewset level.
#     'PAGE_SIZE_QUERY_PARAM': 'per_page',
# 
#     # ADDITIONAL_PRIMARY_RESOURCE_PREFIX: String to prefix additional
#     # instances of the primary resource when sideloading.
#     'ADDITIONAL_PRIMARY_RESOURCE_PREFIX': '+',
# 
#     # Enables host-relative links.  Only compatible with resources registered
#     # through the dynamic router.  If a resource doesn't have a canonical
#     # path registered, links will default back to being resource-relative urls
#     'ENABLE_HOST_RELATIVE_LINKS': True,
# 
#     # Enables caching of serializer fields to speed up serializer usage
#     # Needs to also be configured on a per-serializer basis
#     'ENABLE_FIELDS_CACHE': False,
# 
#     # Enables use of hashid fields
#     'ENABLE_HASHID_FIELDS': False,
# 
#     # Salt value to salt hash ids.
#     # Needs to be non-nullable if 'ENABLE_HASHID_FIELDS' is set to True
#     'HASHIDS_SALT': None,
# }
# CLASS_ATTRS = [
#     'LIST_SERIALIZER_CLASS',
# ]
# class Settings(object):
#     def __init__(self, name, defaults, settings, class_attrs=None):
#     def _reload(self, value):
#     def _load_class(self, attr, val):
#     def __getattr__(self, attr):
#     def _settings_changed(self, *args, **kwargs):


# Path: dynamic_rest/routers.py
import copy
import six
import rest_framework
            import traceback
from collections import OrderedDict
    from django.urls import get_script_prefix
    from django.core.urlresolvers import get_script_prefix
from rest_framework import views
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.routers import DefaultRouter, Route
from dynamic_rest.meta import get_model_table
from dynamic_rest.conf import settings
    from rest_framework.routers import replace_methodname

    # structure, for now it is capped at a single level
    # for UX reasons
    for group_name, endpoints in sorted(
        six.iteritems(directory),
        key=sort_key
    ):
        endpoints_list = []
        for endpoint_name, endpoint in sorted(
            six.iteritems(endpoints),
            key=sort_key
        ):
            if endpoint_name[:1] == '_':
                continue
            endpoint_url = get_url(endpoint.get('_url', None))
            active = is_active_url(path, endpoint_url)
            endpoints_list.append(
                (endpoint_name, endpoint_url, [], active)
            )

        url = get_url(endpoints.get('_url', None))
        active = is_active_url(path, url)
        directory_list.append(
            (group_name, url, endpoints_list, active)
        )
    return directory_list


def modify_list_route(routes):
    # Identify the list route, add PATCH so we can
    # have bulk PATCH requests

    if not settings.ENABLE_BULK_UPDATE: