Example #1
0
def admin_collection_properties(request, collection_id):
    hue_collection = Collection.objects.get(id=collection_id)
    solr_collection = SolrApi(SOLR_URL.get(),
                              request.user).collection_or_core(hue_collection)

    if request.method == 'POST':
        collection_form = CollectionForm(request.POST, instance=hue_collection)
        if collection_form.is_valid():
            searcher = SearchController(request.user)
            hue_collection = collection_form.save(commit=False)
            hue_collection.is_core_only = not searcher.is_collection(
                hue_collection.name)
            hue_collection.save()
            return redirect(
                reverse('search:admin_collection_properties',
                        kwargs={'collection_id': hue_collection.id}))
        else:
            request.error(
                _('Errors on the form: %s.') % collection_form.errors)
    else:
        collection_form = CollectionForm(instance=hue_collection)

    return render(
        'admin_collection_properties.mako', request, {
            'solr_collection': solr_collection,
            'hue_collection': hue_collection,
            'collection_form': collection_form,
        })
Example #2
0
def admin_collections_import(request):
  if request.method == 'POST':
    searcher = SearchController(request.user)
    imported = []
    not_imported = []
    status = -1
    message = ""
    importables = json.loads(request.POST["selected"])
    for imp in importables:
      try:
        searcher.add_new_collection(imp)
        imported.append(imp['name'])
      except Exception, e:
        not_imported.append(imp['name'] + ": " + unicode(str(e), "utf8"))

    if len(imported) == len(importables):
      status = 0;
      message = _('Collection(s) or core(s) imported successfully!')
    elif len(not_imported) == len(importables):
      status = 2;
      message = _('There was an error importing the collection(s) or core(s)')
    else:
      status = 1;
      message = _('Collection(s) or core(s) partially imported')

    result = {
      'status': status,
      'message': message,
      'imported': imported,
      'notImported': not_imported
    }

    return HttpResponse(json.dumps(result), mimetype="application/json")
Example #3
0
def admin_collections_import(request):
  if request.method == 'POST':
    searcher = SearchController(request.user)
    imported = []
    not_imported = []
    status = -1
    message = ""
    importables = json.loads(request.POST["selected"])
    for imp in importables:
      try:
        searcher.add_new_collection(imp)
        imported.append(imp['name'])
      except Exception, e:
        not_imported.append(imp['name'] + ": " + unicode(str(e), "utf8"))

    if len(imported) == len(importables):
      status = 0;
      message = _('Collection(s) or core(s) imported successfully!')
    elif len(not_imported) == len(importables):
      status = 2;
      message = _('There was an error importing the collection(s) or core(s)')
    else:
      status = 1;
      message = _('Collection(s) or core(s) partially imported')

    result = {
      'status': status,
      'message': message,
      'imported': imported,
      'notImported': not_imported
    }

    return HttpResponse(json.dumps(result), mimetype="application/json")
Example #4
0
def admin_collection_copy(request):
    if request.method != 'POST':
        raise PopupException(_('POST request required.'))

    id = request.POST.get('id')
    searcher = SearchController()
    response = {'id': searcher.copy_collection(id)}

    return HttpResponse(json.dumps(response), mimetype="application/json")
Example #5
0
File: views.py Project: tp0101/hue
def admin_collection_delete(request):
    if request.method != "POST":
        raise PopupException(_("POST request required."))

    collections = json.loads(request.POST.get("collections"))
    searcher = SearchController(request.user)
    response = {"result": searcher.delete_collections([collection["id"] for collection in collections])}

    return HttpResponse(json.dumps(response), mimetype="application/json")
Example #6
0
def admin_collection_copy(request):
    if request.method != "POST":
        raise PopupException(_("POST request required."))

    collections = json.loads(request.POST.get("collections"))
    searcher = SearchController(request.user)
    response = {"result": searcher.copy_collections([collection["id"] for collection in collections])}

    return JsonResponse(response)
Example #7
0
def admin_collection_copy(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  id = request.POST.get('id')
  searcher = SearchController(request.user)
  response = {
    'id': searcher.copy_collection(id)
  }

  return HttpResponse(json.dumps(response), mimetype="application/json")
Example #8
0
def index(request):
  hue_collections = SearchController(request.user).get_search_collections()
  collection_id = request.GET.get('collection')

  if not hue_collections or not collection_id:
    return admin_collections(request, True)

  try:
    collection = hue_collections.get(id=collection_id)
  except Exception, e:
    raise PopupException(e, title=_("Dashboard does not exist or you don't have the permission to access it."))
Example #9
0
def admin_collection_delete(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  collections = json.loads(request.POST.get('collections'))
  searcher = SearchController(request.user)
  response = {
    'result': searcher.delete_collections([collection['id'] for collection in collections])
  }

  return HttpResponse(json.dumps(response), mimetype="application/json")
Example #10
0
def admin_collection_copy(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  collections = json.loads(request.POST.get('collections'))
  searcher = SearchController(request.user)
  response = {
    'result': searcher.copy_collections([collection['id'] for collection in collections])
  }

  return JsonResponse(response)
Example #11
0
def index(request):
  hue_collections = SearchController(request.user).get_search_collections()
  collection_id = request.GET.get('collection')

  if not hue_collections or not collection_id:
    return admin_collections(request, True)

  try:
    collection = hue_collections.get(id=collection_id)
  except Exception, e:
    raise PopupException(e, title=_("Dashboard does not exist or you don't have the permission to access it."))
Example #12
0
File: views.py Project: QLGu/hue
def admin_collection_copy(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  collections = json.loads(request.POST.get('collections'))
  searcher = SearchController(request.user)
  response = {
    'result': searcher.copy_collections([collection['id'] for collection in collections])
  }

  return JsonResponse(response)
Example #13
0
File: views.py Project: bitsom/hue
def admin_collection_delete(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  collections = json.loads(request.POST.get('collections'))
  searcher = SearchController(request.user)
  response = {
    'result': searcher.delete_collections([collection['id'] for collection in collections])
  }

  return HttpResponse(json.dumps(response), mimetype="application/json")
Example #14
0
def admin_collections(request, is_redirect=False):
    existing_hue_collections = SearchController(
        request.user).get_search_collections()

    if request.GET.get('format') == 'json':
        collections = []
        for collection in existing_hue_collections:
            massaged_collection = {
                'id':
                collection.id,
                'name':
                collection.name,
                'label':
                collection.label,
                'enabled':
                collection.enabled,
                'isCoreOnly':
                collection.is_core_only,
                'absoluteUrl':
                collection.get_absolute_url(),
                'owner':
                collection.owner and collection.owner.username,
                'isOwner':
                collection.owner == request.user or request.user.is_superuser
            }
            collections.append(massaged_collection)
        return JsonResponse(collections, safe=False)

    return render(
        'admin_collections.mako', request, {
            'existing_hue_collections': existing_hue_collections,
            'is_redirect': is_redirect
        })
Example #15
0
def index(request):
  hue_collections = SearchController(request.user).get_search_collections()

  if not hue_collections:
    if request.user.is_superuser:
      return admin_collections(request, True)
    else:
      return no_collections(request)

  init_collection = initial_collection(request, hue_collections)

  search_form = QueryForm(request.GET, initial_collection=init_collection)
  response = {}
  error = {}
  solr_query = {}

  if search_form.is_valid():
    try:
      collection_id = search_form.cleaned_data['collection']
      hue_collection = Collection.objects.get(id=collection_id)

      solr_query = search_form.solr_query_dict
      response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)

      solr_query['total_pages'] = int(math.ceil((float(response['response']['numFound']) / float(solr_query['rows']))))
      solr_query['search_time'] = response['responseHeader']['QTime']
    except Exception, e:
      error['title'] = force_unicode(e.title) if hasattr(e, 'title') else ''
      error['message'] = force_unicode(str(e))
Example #16
0
def new_search(request, is_embeddable=False):
  collections = SearchController(request.user).get_all_indexes()
  if not collections:
    return no_collections(request)

  collection = Collection2(user=request.user, name=collections[0])
  query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}

  template = 'search.mako'
  if is_embeddable:
    template = 'search_embeddable.mako'

  return render(template, request, {
    'collection': collection,
    'query': query,
    'initial': json.dumps({
         'collections': collections,
         'layout': [
              {"size":2,"rows":[{"widgets":[]}],"drops":["temp"],"klass":"card card-home card-column span2"},
              {"size":10,"rows":[{"widgets":[
                  {"size":12,"name":"Filter Bar","widgetType":"filter-widget", "id":"99923aef-b233-9420-96c6-15d48293532b",
                   "properties":{},"offset":0,"isLoading":True,"klass":"card card-widget span12"}]},
                                 {"widgets":[
                  {"size":12,"name":"Grid Results","widgetType":"resultset-widget", "id":"14023aef-b233-9420-96c6-15d48293532b",
                   "properties":{},"offset":0,"isLoading":True,"klass":"card card-widget span12"}]}],
                 "drops":["temp"],"klass":"card card-home card-column span10"},
         ],
         'is_latest': LATEST.get(),
     }),
    'is_owner': True,
    'can_edit_index': can_edit_index(request.user)
  })
Example #17
0
def browse(request, name, is_mobile=False):
  collections = SearchController(request.user).get_all_indexes()
  if not collections:
    return no_collections(request)

  collection = Collection2(user=request.user, name=name)
  query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}

  template = 'search.mako'
  if is_mobile:
    template = 'search_m.mako'

  return render(template, request, {
    'collection': collection,
    'query': query,
    'initial': json.dumps({
      'autoLoad': True,
      'collections': collections,
      'layout': [
          {"size":12,"rows":[{"widgets":[
              {"size":12,"name":"Grid Results","id":"52f07188-f30f-1296-2450-f77e02e1a5c0","widgetType":"resultset-widget",
               "properties":{},"offset":0,"isLoading":True,"klass":"card card-widget span12"}]}],
          "drops":["temp"],"klass":"card card-home card-column span10"}
      ],
      'is_latest': LATEST.get()
    }),
    'is_owner': True,
    'can_edit_index': can_edit_index(request.user),
    'mobile': is_mobile
  })
Example #18
0
def new_search(request):
    collections = SearchController(request.user).get_all_indexes()
    if not collections:
        return no_collections(request)

    collection = Collection(name=collections[0], label=collections[0])
    query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}

    return render(
        'search.mako', request, {
            'collection':
            collection,
            'query':
            query,
            'initial':
            json.dumps({
                'collections':
                collections,
                'layout': [
                    {
                        "size": 2,
                        "rows": [{
                            "widgets": []
                        }],
                        "drops": ["temp"],
                        "klass": "card card-home card-column span2"
                    },
                    {
                        "size":
                        10,
                        "rows": [{
                            "widgets": [{
                                "size": 12,
                                "name": "Filter Bar",
                                "widgetType": "filter-widget",
                                "properties": {},
                                "offset": 0,
                                "isLoading": True,
                                "klass": "card card-widget span12"
                            }]
                        }, {
                            "widgets": [{
                                "size": 12,
                                "name": "Grid Results",
                                "widgetType": "resultset-widget",
                                "properties": {},
                                "offset": 0,
                                "isLoading": True,
                                "klass": "card card-widget span12"
                            }]
                        }],
                        "drops": ["temp"],
                        "klass":
                        "card card-home card-column span10"
                    },
                ]
            }),
            'is_owner':
            True
        })
Example #19
0
 def get_collections(self):
     try:
         from search.search_controller import SearchController
         return SearchController(self.user).get_all_indexes()
     except Exception, e:
         LOG.warn('Error get_collections: %s' % e)
         solr_collections = []
Example #20
0
def admin_collections(request, is_redirect=False, is_mobile=False):
    existing_hue_collections = SearchController(
        request.user).get_search_collections()

    if request.GET.get('format') == 'json':
        collections = []
        for collection in existing_hue_collections:
            massaged_collection = collection.to_dict()
            if request.GET.get('is_mobile'):
                massaged_collection['absoluteUrl'] = reverse(
                    'search:index_m') + '?collection=%s' % collection.id
            massaged_collection['isOwner'] = collection.doc.get().can_write(
                request.user)
            collections.append(massaged_collection)
        return JsonResponse(collections, safe=False)

    template = 'admin_collections.mako'
    if is_mobile:
        template = 'admin_collections_m.mako'

    return render(
        template, request, {
            'is_embeddable': request.GET.get('is_embeddable', False),
            'existing_hue_collections': existing_hue_collections,
            'is_redirect': is_redirect
        })
Example #21
0
def admin_collections_import(request):
    if request.method == 'POST':
        searcher = SearchController(request.user)
        status = 0
        err_message = _('Error')
        result = {'status': status, 'message': err_message}
        importables = json.loads(request.POST["selected"])
        for imp in importables:
            try:
                searcher.add_new_collection(imp)
                status += 1
            except Exception, e:
                err_message += unicode(str(e), "utf8") + "\n"
            result['message'] = _('Imported successfully') if status == len(
                importables) else _('Imported with errors: ') + err_message
        return HttpResponse(json.dumps(result), mimetype="application/json")
Example #22
0
File: views.py Project: branchp/hue
def admin_collections_import(request):
  if request.method == 'POST':
    searcher = SearchController(request.user)
    status = 0
    err_message = _('Error')
    result = {
      'status': status,
      'message': err_message
    }
    importables = json.loads(request.POST["selected"])
    for imp in importables:
      try:
        searcher.add_new_collection(imp)
        status += 1
      except Exception, e:
        err_message += unicode(str(e), "utf8") + "\n"
      result['message'] = status == len(importables) and _('Imported successfully') or _('Imported with errors: ') + err_message
    return HttpResponse(json.dumps(result), mimetype="application/json")
Example #23
0
File: views.py Project: tp0101/hue
def get_collections(request):
    result = {'status': -1, 'message': ''}

    try:
        result['collection'] = SearchController(request.user).get_all_indexes()
        result['status'] = 0

    except Exception, e:
        result['message'] = unicode(str(e), "utf8")
Example #24
0
  def decorate(request, *args, **kwargs):

    collection_json = json.loads(request.POST.get('collection', '{}'))

    if collection_json['id']:
      try:
        SearchController(request.user).get_search_collections().get(id=collection_json['id'])
      except Collection.DoesNotExist:
        message = _("Dashboard does not exist or you don't have the permission to access it.")
        raise PopupException(message)

    return view_func(request, *args, **kwargs)
Example #25
0
File: views.py Project: atupal/hue
def admin_collection_properties(request, collection_id):
  hue_collection = Collection.objects.get(id=collection_id)
  solr_collection = SolrApi(SOLR_URL.get(), request.user).collection_or_core(hue_collection)

  if request.method == 'POST':
    collection_form = CollectionForm(request.POST, instance=hue_collection, user=request.user)
    if collection_form.is_valid():
      searcher = SearchController(request.user)
      hue_collection = collection_form.save(commit=False)
      hue_collection.is_core_only = not searcher.is_collection(hue_collection.name)
      hue_collection.save()
      return redirect(reverse('search:admin_collection_properties', kwargs={'collection_id': hue_collection.id}))
    else:
      request.error(_('Errors on the form: %s.') % collection_form.errors)
  else:
    collection_form = CollectionForm(instance=hue_collection)

  return render('admin_collection_properties.mako', request, {
    'solr_collection': solr_collection,
    'hue_collection': hue_collection,
    'collection_form': collection_form,
  })
Example #26
0
def index(request):
  hue_collections = SearchController(request.user).get_search_collections()
  collection_id = request.GET.get('collection')

  if not hue_collections or not collection_id:
    return admin_collections(request, True)

  try:
    collection_doc = Document2.objects.get(id=collection_id)
    collection_doc.doc.get().can_read_or_exception(request.user)
    collection = Collection2(request.user, document=collection_doc)
  except Exception, e:
    raise PopupException(e, title=_("Dashboard does not exist or you don't have the permission to access it."))
Example #27
0
def get_collections(request):
  result = {'status': -1, 'message': ''}

  try:
    result['collection'] = SearchController(request.user).get_all_indexes()
    result['status'] = 0

  except Exception, e:
    if 'does not have privileges' in str(e):
      result['status'] = 0
      result['collection'] = [json.loads(request.POST.get('collection'))['name']]
    else:
      result['message'] = unicode(str(e), "utf8")
Example #28
0
def index(request):
  hue_collections = SearchController(request.user).get_search_collections()
  collection_id = request.GET.get('collection')

  if not hue_collections or not collection_id:
    if request.user.is_superuser:
      return admin_collections(request, True)
    else:
      return no_collections(request)

  try:
    collection = Collection.objects.get(id=collection_id) # TODO perms HUE-1987
  except Exception, e:
    raise PopupException(e, title=_('Error while accessing the collection'))
Example #29
0
def admin_collections(request, is_redirect=False):
  existing_hue_collections = SearchController(request.user).get_search_collections()

  if request.GET.get('format') == 'json':
    collections = []
    for collection in existing_hue_collections:
      massaged_collection = collection.to_dict()
      massaged_collection['isOwner'] = collection.doc.get().can_write(request.user)
      collections.append(massaged_collection)
    return JsonResponse(collections, safe=False)

  return render('admin_collections.mako', request, {
    'existing_hue_collections': existing_hue_collections,
    'is_redirect': is_redirect
  })
Example #30
0
def browse(request, name):
    collections = SearchController(request.user).get_all_indexes()
    if not collections:
        return no_collections(request)

    collection = Collection(name=name, label=name)
    query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}

    return render(
        'search.mako', request, {
            'collection':
            collection,
            'query':
            query,
            'initial':
            json.dumps({
                'autoLoad':
                True,
                'collections':
                collections,
                'layout': [{
                    "size":
                    12,
                    "rows": [{
                        "widgets": [{
                            "size": 12,
                            "name": "Grid Results",
                            "id": "52f07188-f30f-1296-2450-f77e02e1a5c0",
                            "widgetType": "resultset-widget",
                            "properties": {},
                            "offset": 0,
                            "isLoading": True,
                            "klass": "card card-widget span12"
                        }]
                    }],
                    "drops": ["temp"],
                    "klass":
                    "card card-home card-column span10"
                }]
            }),
            'is_owner':
            True
        })
Example #31
0
def download(request, format):
  hue_collections = SearchController(request.user).get_search_collections()

  if not hue_collections:
    raise PopupException(_("No collection to download."))

  init_collection = initial_collection(request, hue_collections)

  search_form = QueryForm(request.GET, initial_collection=init_collection)

  if search_form.is_valid():
    try:
      collection_id = search_form.cleaned_data['collection']
      hue_collection = Collection.objects.get(id=collection_id)

      solr_query = search_form.solr_query_dict
      response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)

      LOG.debug('Download results for query %s' % smart_str(solr_query))

      return export_download(response, format)
    except Exception, e:
      raise PopupException(_("Could not download search results: %s") % e)
Example #32
0
 def datasets(self, show_all=False):
   return SearchController(self.user).get_all_indexes(show_all=show_all)
Example #33
0
     err_message = _('Error')
     result = {'status': status, 'message': err_message}
     importables = json.loads(request.POST["selected"])
     for imp in importables:
         try:
             searcher.add_new_collection(imp)
             status += 1
         except Exception, e:
             err_message += unicode(str(e), "utf8") + "\n"
         result['message'] = status == len(importables) and _(
             'Imported successfully'
         ) or _('Imported with errors: ') + err_message
     return HttpResponse(json.dumps(result), mimetype="application/json")
 else:
     if request.GET.get('format') == 'json':
         searcher = SearchController()
         new_solr_collections = searcher.get_new_collections()
         massaged_collections = []
         for coll in new_solr_collections:
             massaged_collections.append({
                 'type': 'collection',
                 'name': coll
             })
         new_solr_cores = searcher.get_new_cores()
         massaged_cores = []
         for core in new_solr_cores:
             massaged_cores.append({'type': 'core', 'name': core})
         response = {
             'newSolrCollections': list(massaged_collections),
             'newSolrCores': list(massaged_cores)
         }
Example #34
0
      message = _('There was an error importing the collection(s) or core(s)')
    else:
      status = 1;
      message = _('Collection(s) or core(s) partially imported')

    result = {
      'status': status,
      'message': message,
      'imported': imported,
      'notImported': not_imported
    }

    return HttpResponse(json.dumps(result), mimetype="application/json")
  else:
    if request.GET.get('format') == 'json':
      searcher = SearchController(request.user)
      new_solr_collections = searcher.get_new_collections()
      massaged_collections = []
      for coll in new_solr_collections:
        massaged_collections.append({
          'type': 'collection',
          'name': coll
        })
      new_solr_cores = searcher.get_new_cores()
      massaged_cores = []
      for core in new_solr_cores:
        massaged_cores.append({
          'type': 'core',
          'name': core
        })
      response = {
Example #35
0
      message = _('There was an error importing the collection(s) or core(s)')
    else:
      status = 1;
      message = _('Collection(s) or core(s) partially imported')

    result = {
      'status': status,
      'message': message,
      'imported': imported,
      'notImported': not_imported
    }

    return HttpResponse(json.dumps(result), mimetype="application/json")
  else:
    if request.GET.get('format') == 'json':
      searcher = SearchController(request.user)
      new_solr_collections = searcher.get_new_collections()
      massaged_collections = []
      for coll in new_solr_collections:
        massaged_collections.append({
          'type': 'collection',
          'name': coll
        })
      new_solr_cores = searcher.get_new_cores()
      massaged_cores = []
      for core in new_solr_cores:
        massaged_cores.append({
          'type': 'core',
          'name': core
        })
      response = {