def construct_endpoint(self, instance, spec, loc, context):
"""
Constructor of '.endpoint' predicate.
It gets the generated views and it maps them with urlpatterns which
will later be used from django.
"""
parent_name = context.get('parent_name')
collections = self.get_structural_elements(instance)
if not collections:
raise utils.DRFAdapterException(
'.endpoint without any collection found.', loc=loc)
router = routers.DefaultRouter()
for collection in collections:
collection_spec = instance.get(collection)
view = collection_spec.get(self.ADAPTER_CONF)
basename = parent_name + '_' + collection
router.register(collection, view, base_name=basename)
self.urls[parent_name] = url(
r'^' + parent_name + '/', include(router.urls))
评论列表
文章目录