def add_children(self): """ Add all the children to root. Read all the available models from the global all_models, get the resource subtree, and add them as children of this root resource """ for model_class, model_info in all_models.items(): name = model_info['url'] # If the model is "User", we want the URL to be "users" self[name] = model_info['resource_collection']()
def add_children(self): """ Add all the children to root. Read all the available models from the global all_models, get the resource subtree, and add them as children of this root resource """ for model_class, model_info in all_models.items(): name = model_info[ 'url'] # If the model is "User", we want the URL to be "users" self[name] = model_info['resource_collection']()
def _add_views(config): """ We add all the views for the models to the Pyramid config. It is important for this method to run that all the models have been properly imported. :param config: the pyramid config to add the views to """ for model_class, model_info in all_models.items(): (item_context, item_view) = model_info['item_view'] (collection_context, collection_view) = model_info['collection_view'] config.add_view(item_view, context=item_context, request_method='GET', attr='read', renderer='json') config.add_view(item_view, context=item_context, request_method='PATCH', attr='update', renderer='json') config.add_view(item_view, context=item_context, request_method='DELETE', attr='delete', renderer='json') config.add_view(collection_view, context=collection_context, request_method='POST', attr='add', renderer='json') config.add_view(collection_view, context=collection_context, request_method='GET', attr='list', renderer='json') config.add_view(collection_view, context=collection_context, request_method='DELETE', attr='empty', renderer='json')