+ providers = []
+ for app_label, models in self.model_registry.items():
+ app_provider = {
+ 'namespace': 'Gilbert.api.models.%s' % app_label,
+ 'url': reverse('%s:models' % self.namespace, current_app=self.app_name, kwargs={'app_label': app_label}),
+ 'type': 'remoting',
+ }
+ model_actions = {}
+ for model_name, admin in models.items():
+ model_methods = []
+ for method in [admin.get_method(method_name) for method_name in admin.methods]:
+ if method.restricted and not self.has_permission(request):
+ continue
+ model_methods.append({
+ 'name': method.name,
+ 'len': method.argc,
+ })
+ if model_methods:
+ model_actions[model_name] = model_methods
+ if model_actions:
+ app_provider['actions'] = model_actions
+ providers.append(app_provider)
+
+ plugin_provider = {
+ 'namespace': 'Gilbert.api',
+ 'url': reverse('%s:router' % self.namespace, current_app=self.app_name),
+ 'type': 'remoting',
+ }
+ plugin_actions = {}
+ for plugin_name, plugin in self.plugin_registry.items():
+ plugin_methods = []
+ for method in [plugin.get_method(method_name) for method_name in plugin.methods]:
+ if method.restricted and not self.has_permission(request):
+ continue
+ plugin_methods.append({
+ 'name': method.name,
+ 'len': method.argc,
+ })
+ if plugin_methods:
+ plugin_actions[plugin_name] = plugin_methods
+ if plugin_actions:
+ plugin_provider['actions'] = plugin_actions
+ providers.append(plugin_provider)
+
+ return HttpResponse(''.join(['Ext.Direct.addProvider('+json.dumps(provider, separators=(',', ':'))+');' for provider in providers]), mimetype='text/javascript')