Explorar o código

[indexer] Add install examples view

Abraham Elmahrek %!s(int64=11) %!d(string=hai) anos
pai
achega
d14f4d2d21

+ 8 - 0
apps/about/src/about/templates/admin_wizard.mako

@@ -107,6 +107,14 @@ ${ header.menubar() }
                 </a>
               </li>
           % endif
+          % if 'indexer' in app_names:
+              <li>
+                <a href="#" class="installBtn" data-loading-text="${ _('Installing...') }"
+                   data-sample-url="${ url('indexer:install_examples') }">
+                  <i class="fa fa-download"></i> ${ apps['indexer'].nice_name }
+                </a>
+              </li>
+          % endif
           % if 'search' in app_names:
               <li>
                 <a href="#" class="installBtn" data-loading-text="${ _('Installing...') }"

+ 2 - 1
desktop/libs/indexer/src/indexer/urls.py

@@ -18,7 +18,8 @@
 from django.conf.urls.defaults import patterns, url
 
 urlpatterns = patterns('indexer.views',
-  url(r'^$', 'collections', name='collections')
+  url(r'^$', 'collections', name='collections'),
+  url(r'^install_examples$', 'install_examples', name='install_examples'),
 )
 
 urlpatterns += patterns('indexer.api',

+ 21 - 0
desktop/libs/indexer/src/indexer/views.py

@@ -16,12 +16,33 @@
 # limitations under the License.
 
 import logging
+import json
+
+from django.http import HttpResponse
+from django.utils.translation import ugettext as _
 
 from desktop.lib.django_util import render
 
+from indexer.management.commands import indexer_install_examples
+
 
 LOG = logging.getLogger(__name__)
 
 
 def collections(request, is_redirect=False):
   return render('collections.mako', request, {})
+
+def install_examples(request, is_redirect=False):
+  result = {'status': -1, 'message': ''}
+
+  if request.method != 'POST':
+    result['message'] = _('A POST request is required.')
+  else:
+    try:
+      indexer_install_examples.Command().handle_noargs()
+      result['status'] = 0
+    except Exception, e:
+      LOG.exception(e)
+      result['message'] = str(e)
+
+  return HttpResponse(json.dumps(result), mimetype="application/json")