コード例 #1
0
ファイル: api.py プロジェクト: rootAir/hue
def search(request):
    response = {}

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

    query['download'] = 'download' in request.POST
    fetch_result = 'fetch_result' in request.POST

    if collection:
        try:
            if fetch_result:
                response = get_engine(request.user, collection).fetch_result(
                    collection, query, facet)
            else:
                response = get_engine(request.user, collection).query(
                    collection, query, facet)
        except RestException, e:
            try:
                message = json.loads(e.message)
                msg = message['error'].get('msg')
                response['error'] = msg if msg else message['error']['trace']
            except Exception, e2:
                LOG.exception('Failed to extract json message: %s' %
                              force_unicode(e2))
                LOG.exception('Failed to parse json response: %s' %
                              force_unicode(e))
                response['error'] = force_unicode(e)
コード例 #2
0
def search(request):
    response = {}

    collection = json.loads(request.POST.get('collection', '{}'))
    query = json.loads(request.POST.get('query', '{}'))
    facet = json.loads(request.POST.get('facet', '{}'))
    cluster = request.POST.get('cluster', '""')

    query['download'] = 'download' in request.POST
    fetch_result = 'fetch_result' in request.POST

    if collection:
        try:
            if fetch_result:
                response = get_engine(request.user,
                                      collection,
                                      facet,
                                      cluster=cluster).fetch_result(
                                          collection, query, facet)
            else:
                response = get_engine(request.user,
                                      collection,
                                      facet,
                                      cluster=cluster).query(
                                          collection, query, facet)
        except RestException, e:
            response.update(extract_solr_exception_message(e))
        except Exception as e:
            raise PopupException(e, title=_('Error while accessing Solr'))

            response['error'] = force_unicode(e)
コード例 #3
0
def index_fields_dynamic(request):
    result = {'status': -1, 'message': 'Error'}

    try:
        name = request.POST.get('name')
        engine = request.POST.get('engine')
        source = request.POST.get('source')

        dynamic_fields = get_engine(request.user, engine,
                                    source=source).luke(name)

        result['message'] = ''
        result['fields'] = [
            Collection2._make_field(name, properties)
            for name, properties in dynamic_fields['fields'].items()
            if 'dynamicBase' in properties
        ]
        result['gridlayout_header_fields'] = [
            Collection2._make_gridlayout_header_field(
                {
                    'name': name,
                    'type': properties.get('type')
                }, True)
            for name, properties in dynamic_fields['fields'].items()
            if 'dynamicBase' in properties
        ]
        result['status'] = 0
    except Exception as e:
        result['message'] = force_unicode(e)

    return JsonResponse(result)
コード例 #4
0
ファイル: views.py プロジェクト: zks888/hue
def index(request, is_mobile=False):
    engine = request.GET.get('engine', 'solr')
    cluster = request.POST.get('cluster', '""')
    collection_id = request.GET.get('collection')

    collections = get_engine(
        request.user, engine,
        cluster=cluster).datasets() if engine != 'report' else ['default']

    if not collections:
        if engine == 'solr':
            return no_collections(request)
        else:
            return importer(request)

    try:
        collection_doc = Document2.objects.get(id=collection_id)
        if USE_NEW_EDITOR.get():
            collection_doc.can_read_or_exception(request.user)
        else:
            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."
              ))
コード例 #5
0
def get_stats(request):
    result = {'status': -1, 'message': 'Error'}

    try:
        collection = json.loads(request.POST.get('collection', '{}'))
        query = json.loads(request.POST.get('query', '{}'))
        analysis = json.loads(request.POST.get('analysis', '{}'))

        field = analysis['name']
        facet = analysis['stats']['facet']

        result['stats'] = get_engine(request.user,
                                     collection).stats(collection['name'],
                                                       [field], query, facet)
        result['status'] = 0
        result['message'] = ''

    except Exception as e:
        LOG.exception('Failed to get stats for field')
        result['message'] = force_unicode(e)
        if 'not currently supported' in result['message']:
            result['status'] = 1
            result['message'] = _('This field type does not support stats')

    return JsonResponse(result)
コード例 #6
0
ファイル: views.py プロジェクト: zengyuanman/hue
def browse(request, name, is_mobile=False):
  engine = request.GET.get('engine', 'solr')
  collections = get_engine(request.user, engine).datasets()
  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(),
      'engines': get_engines(request.user)
    }),
    'is_owner': True,
    'can_edit_index': can_edit_index(request.user),
    'mobile': is_mobile
  })
コード例 #7
0
ファイル: views.py プロジェクト: georgegrace1987/Hue_Practice
def new_search(request):
    engine = request.GET.get('engine', 'solr')
    cluster = request.POST.get('cluster', '""')

    collections = get_engine(
        request.user, engine,
        cluster=cluster).datasets() if engine != 'report' else ['default']

    if not collections:
        if engine == 'solr':
            return no_collections(request)
        else:
            return importer(request)

    collection = Collection2(user=request.user,
                             name=collections[0],
                             engine=engine)
    query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}
    layout = DEFAULT_LAYOUT if engine != 'report' else REPORT_LAYOUT

    if request.GET.get('format', 'plain') == 'json':
        return JsonResponse({
            'collection': collection.get_props(request.user),
            'query': query,
            'initial': {
                'collections': collections,
                'layout': layout,
                'qb_layout': QUERY_BUILDER_LAYOUT,
                'text_search_layout': TEXT_SEARCH_LAYOUT,
                'is_latest': _get_latest(),
                'engines': get_engines(request.user)
            }
        })
    else:
        return render(
            'search.mako', request, {
                'collection':
                collection,
                'query':
                query,
                'initial':
                json.dumps({
                    'collections': collections,
                    'layout': layout,
                    'qb_layout': QUERY_BUILDER_LAYOUT,
                    'text_search_layout': TEXT_SEARCH_LAYOUT,
                    'is_latest': _get_latest(),
                    'engines': get_engines(request.user)
                }),
                'is_owner':
                True,
                'is_embeddable':
                request.GET.get('is_embeddable', False),
                'can_edit_index':
                can_edit_index(request.user),
                'is_report':
                engine == 'report'
            })
コード例 #8
0
 def fields_data(self, user, name, engine='solr'):
     api = get_engine(user, engine)
     try:
         schema_fields = api.fields(name)
         schema_fields = schema_fields['schema']['fields']
     except Exception, e:
         LOG.warn('/luke call did not succeed: %s' % e)
         fields = api.schema_fields(name)
         schema_fields = Collection2._make_luke_from_schema_fields(fields)
コード例 #9
0
ファイル: models.py プロジェクト: zkenstein/hue
 def fields_data(self, user, name, engine='solr', source='data'):
   api = get_engine(user, engine, source=source)
   try:
     schema_fields = api.fields(name)
     schema_fields = schema_fields['schema']['fields']
   except Exception, e:
     LOG.warn('/luke call did not succeed: %s' % e)
     try:
       fields = api.schema_fields(name)
       schema_fields = Collection2._make_luke_from_schema_fields(fields)
     except Exception, e:
       LOG.error('Could not access collection: %s' % e)
       return []
コード例 #10
0
ファイル: models.py プロジェクト: zimiao552147572/hue
  def fields_data(self, user, name, engine='solr', source='data'):
    api = get_engine(user, engine, source=source)
    try:
      schema_fields = api.fields(name)
      schema_fields = schema_fields['schema']['fields']
    except Exception as e:
      LOG.warn('/luke call did not succeed: %s' % e)
      try:
        fields = api.schema_fields(name)
        schema_fields = Collection2._make_luke_from_schema_fields(fields)
      except Exception as e:
        LOG.error('Could not access collection: %s' % e)
        return []

    return sorted([self._make_field(field, attributes) for field, attributes in schema_fields.items()], key=lambda f: f['name'])
コード例 #11
0
def nested_documents(request):
  result = {'status': -1, 'message': 'Error'}

  response = {}

  collection = json.loads(request.POST.get('collection', '{}'))
  query = {'qs': [{'q': '_root_:*'}], 'fqs': [], 'start': 0, 'limit': 0}

  try:
    response = get_engine(request.user, collection).query(collection, query)
    result['has_nested_documents'] = response['response']['numFound'] > 0
    result['status'] = 0
  except Exception, e:
    LOG.exception('Failed to list nested documents')
    result['message'] = force_unicode(e)
    result['has_nested_documents'] = False
コード例 #12
0
def get_collections(request):
  result = {'status': -1, 'message': ''}

  try:
    collection = json.loads(request.POST.get('collection'))
    show_all = json.loads(request.POST.get('show_all'))

    result['collection'] = get_engine(request.user, collection).datasets(show_all=show_all)
    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'] = force_unicode(e)
コード例 #13
0
ファイル: views.py プロジェクト: Edisnel/hue
def new_search(request):
    engine = request.GET.get('engine', 'solr')
    collections = get_engine(request.user, engine).datasets()
    if not collections:
        return no_collections(request)

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

    if request.GET.get('format', 'plain') == 'json':
        return JsonResponse({
            'collection': collection.get_props(request.user),
            'query': query,
            'initial': {
                'collections': collections,
                'layout': DEFAULT_LAYOUT,
                'is_latest': LATEST.get(),
                'engines': get_engines(request.user)
            }
        })
    else:
        return render(
            'search.mako', request, {
                'collection':
                collection,
                'query':
                query,
                'initial':
                json.dumps({
                    'collections': collections,
                    'layout': DEFAULT_LAYOUT,
                    'is_latest': LATEST.get(),
                    'engines': get_engines(request.user)
                }),
                'is_owner':
                True,
                'is_embeddable':
                request.GET.get('is_embeddable', False),
                'can_edit_index':
                can_edit_index(request.user)
            })
コード例 #14
0
def get_document(request):
  result = {'status': -1, 'message': 'Error'}

  try:
    collection = json.loads(request.POST.get('collection', '{}'))
    doc_id = request.POST.get('id')

    if doc_id:
      result['doc'] = get_engine(request.user, collection).get(collection, doc_id)
      if result['doc']['doc']:
        result['status'] = 0
        result['message'] = ''
      else:
        result['status'] = 1
        result['message'] = _('No document was returned by Solr.')
    else:
      result['message'] = _('This document does not have any index id.')
      result['status'] = 1

  except Exception, e:
    result['message'] = force_unicode(e)
コード例 #15
0
def _create_facet(collection, user, facet_id, facet_label, facet_field,
                  widget_type, window_size):
    properties = {
        'sort': 'desc',
        'canRange': False,
        'stacked': False,
        'limit': 10,
        'mincount': 0,
        'missing': False,
        'isDate': False,
        'slot': 0,
        'aggregate': {
            'function': 'unique',
            'formula': '',
            'plain_formula': '',
            'percentile': 50
        }
    }
    template = {
        "showFieldList": True,
        "showGrid": False,
        "showChart": True,
        "chartSettings": {
            'chartType':
            'pie' if widget_type == 'pie2-widget' else
            ('timeline' if widget_type == 'timeline-widget' else
             ('gradientmap' if widget_type == 'gradient-map-widget' else 'bars'
              )),
            'chartSorting':
            'none',
            'chartScatterGroup':
            None,
            'chartScatterSize':
            None,
            'chartScope':
            'world',
            'chartX':
            None,
            'chartYSingle':
            None,
            'chartYMulti': [],
            'chartData': [],
            'chartMapLabel':
            None,
            'chartSelectorType':
            'bar'
        },
        "fieldsAttributes": [],
        "fieldsAttributesFilter": "",
        "filteredAttributeFieldsAll": True,
        "fields": [],
        "fieldsSelected": [],
        "leafletmap": {
            'latitudeField': None,
            'longitudeField': None,
            'labelField': None
        },  # Use own?
        'leafletmapOn': False,
        'isGridLayout': False,
        "hasDataForChart": True,
        "rows": 25,
    }
    if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'):
        facet_type = 'pivot'
    elif widget_type == 'document-widget':
        # SQL query, 1 solr widget
        if collection['selectedDocument'].get('uuid'):
            properties['statementUuid'] = collection['selectedDocument'].get(
                'uuid')
            doc = Document2.objects.get_by_uuid(
                user=user,
                uuid=collection['selectedDocument']['uuid'],
                perm_type='read')
            snippets = doc.data_dict.get('snippets', [])
            properties['result'] = {
                'handle': {
                    'statement_id':
                    0,
                    'statements_count':
                    1,
                    'previous_statement_hash':
                    hashlib.sha224(str(uuid.uuid4())).hexdigest()
                }
            }
            if snippets:
                properties['engine'] = snippets[0]['type']
        else:
            properties['statementUuid'] = ''
        properties['statement'] = ''
        properties['uuid'] = facet_field
        properties['facets'] = [{
            'canRange': False,
            'field': 'blank',
            'limit': 10,
            'mincount': 0,
            'sort': 'desc',
            'aggregate': {
                'function': 'count'
            },
            'isDate': False,
            'type': 'field'
        }]
        facet_type = 'statement'
    else:
        api = get_engine(user, collection)
        range_properties = _new_range_facet(api, collection, facet_field,
                                            widget_type, window_size)

        if range_properties:
            facet_type = 'range'
            properties.update(range_properties)
            properties['initial_gap'] = properties['gap']
            properties['initial_start'] = properties['start']
            properties['initial_end'] = properties['end']
        else:
            facet_type = 'field'

        if widget_type in ('bucket-widget', 'pie2-widget', 'timeline-widget',
                           'tree2-widget', 'text-facet-widget', 'hit-widget',
                           'gradient-map-widget'):
            # properties = {'canRange': False, 'stacked': False, 'limit': 10} # TODO: Lighter weight top nested facet

            properties['facets_form'] = NESTED_FACET_FORM
            # Not supported on dim 2 currently
            properties['facets_form']['type'] = 'field'
            properties['facets_form']['canRange'] = False
            properties['facets_form']['isFacetForm'] = True

            facet = NESTED_FACET_FORM.copy()
            facet['field'] = facet_field
            facet['limit'] = 10
            facet['fieldLabel'] = facet_field
            facet['multiselect'] = True

            if widget_type == 'text-facet-widget':
                properties['type'] = facet_type
                if USE_GRIDSTER.get():
                    properties['limit'] = facet['limit'] = 100

            if range_properties:
                # TODO: timeline still uses properties from top properties
                facet.update(range_properties)
                facet['initial_gap'] = facet['gap']
                facet['initial_start'] = facet['start']
                facet['initial_end'] = facet['end']
                facet['stacked'] = False
                facet['type'] = 'range'
            else:
                facet['type'] = facet_type

            if collection.get('engine', 'solr') != 'solr':
                facet['sort'] = 'default'

            properties['facets'] = [facet]
            properties['domain'] = {'blockParent': [], 'blockChildren': []}
            properties['compare'] = COMPARE_FACET
            properties['filter'] = QUERY_FACET

            if widget_type == 'hit-widget':
                facet_type = 'function'
                facet['aggregate']['function'] = 'unique'
            else:
                facet_type = 'nested'
                facet['aggregate']['function'] = 'count'

            if widget_type == 'pie2-widget':
                properties['scope'] = 'stack'
                properties['timelineChartType'] = 'bar'
            elif widget_type == 'tree2-widget':
                properties['scope'] = 'tree'
                properties['facets_form']['limit'] = 5
                properties['isOldPivot'] = True
            elif widget_type == 'gradient-map-widget':
                properties['scope'] = 'world'
                facet['limit'] = 100
            else:
                properties['scope'] = 'stack'
                properties['timelineChartType'] = 'bar'

    if widget_type in ('tree-widget', 'heatmap-widget',
                       'map-widget') and widget_type != 'gradient-map-widget':
        properties['mincount'] = 1
        properties['facets'] = []
        properties['stacked'] = True
        properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 5}

        if widget_type == 'map-widget':
            properties['scope'] = 'world'
            properties['limit'] = 100
        else:
            properties[
                'scope'] = 'stack' if widget_type == 'heatmap-widget' else 'tree'

    if widget_type == 'histogram-widget':
        properties['enableSelection'] = True
        properties['timelineChartType'] = 'bar'
        properties['extraSeries'] = []

    return {
        'id': facet_id,
        'label': facet_label,
        'field': facet_field,
        'type': facet_type,
        'widgetType': widget_type,
        'properties': properties,
        # Hue 4+
        'template': template,
        'queryResult': {}
    }
コード例 #16
0
ファイル: api.py プロジェクト: xiaole-max/hue
def _create_facet(collection, user, facet_id, facet_label, facet_field,
                  widget_type):
    properties = {
        'sort': 'desc',
        'canRange': False,
        'stacked': False,
        'limit': 10,
        'mincount': 0,
        'isDate': False,
        'aggregate': {
            'function': 'unique',
            'ops': [],
            'percentiles': [{
                'value': 50
            }]
        }
    }

    if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'):
        facet_type = 'pivot'
    elif widget_type == 'gradient-map-widget':
        facet_type = 'nested'
        properties['facets'] = []
        properties['domain'] = {'blockParent': [], 'blockChildren': []}
        properties['facets_form'] = {
            'field': '',
            'mincount': 1,
            'limit': 10,
            'aggregate': {
                'function': 'unique',
                'ops': [],
                'percentiles': [{
                    'value': 50
                }]
            }
        }
        properties['scope'] = 'world'
        properties['limit'] = 100
    else:
        api = get_engine(user, collection)
        range_properties = _new_range_facet(api, collection, facet_field,
                                            widget_type)

        if range_properties:
            facet_type = 'range'
            properties.update(range_properties)
            properties['initial_gap'] = properties['gap']
            properties['initial_start'] = properties['start']
            properties['initial_end'] = properties['end']
        else:
            facet_type = 'field'

        if widget_type in ('bucket-widget', 'pie2-widget', 'timeline-widget',
                           'tree2-widget', 'text-facet-widget', 'hit-widget'):
            if widget_type == 'text-facet-widget':
                properties['type'] = facet_type

            if widget_type == 'hit-widget':
                facet_type = 'function'
            else:
                facet_type = 'nested'

            properties['facets_form'] = {
                'field': '',
                'mincount': 1,
                'limit': 10,
                'aggregate': {
                    'function': 'unique',
                    'ops': [],
                    'percentiles': [{
                        'value': 50
                    }]
                }
            }
            properties['facets'] = []
            properties['domain'] = {'blockParent': [], 'blockChildren': []}

            if widget_type == 'pie2-widget':
                properties['scope'] = 'stack'
                properties['timelineChartType'] = 'bar'
            elif widget_type == 'tree2-widget':
                properties['scope'] = 'tree'
                properties['facets_form']['limit'] = 5
                properties['isOldPivot'] = True
            else:
                properties['scope'] = 'stack'
                properties['timelineChartType'] = 'bar'

    if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'):
        properties['mincount'] = 1
        properties['facets'] = []
        properties['stacked'] = True
        properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 5}

        if widget_type == 'map-widget':
            properties['scope'] = 'world'
            properties['limit'] = 100
        else:
            properties[
                'scope'] = 'stack' if widget_type == 'heatmap-widget' else 'tree'

    if widget_type == 'histogram-widget':
        properties['enableSelection'] = True
        properties['timelineChartType'] = 'bar'
        properties['extraSeries'] = []

    return {
        'id': facet_id,
        'label': facet_label,
        'field': facet_field,
        'type': facet_type,
        'widgetType': widget_type,
        'properties': properties,
        # Hue 4+
        'template': {
            "showFieldList": True,
            "showGrid": False,
            "showChart": True,
            "chartSettings": {
                'chartType':
                'pie' if widget_type == 'pie2-widget' else
                ('timeline' if widget_type == 'timeline-widget' else
                 ('gradientmap'
                  if widget_type == 'gradient-map-widget' else 'bars')),
                'chartSorting':
                'none',
                'chartScatterGroup':
                None,
                'chartScatterSize':
                None,
                'chartScope':
                'world',
                'chartX':
                None,
                'chartYSingle':
                None,
                'chartYMulti': [],
                'chartData': [],
                'chartMapLabel':
                None,
            },
            "fieldsAttributes": [],
            "fieldsAttributesFilter": "",
            "filteredAttributeFieldsAll": True,
            "fields": [],
            "fieldsSelected": [],
            "leafletmap": {
                'latitudeField': None,
                'longitudeField': None,
                'labelField': None
            },  # Use own?
            'leafletmapOn': False,
            'isGridLayout': False,
            "hasDataForChart": True,
            "rows": 25,
        },
        'queryResult': {}
    }
コード例 #17
0
ファイル: views.py プロジェクト: georgegrace1987/Hue_Practice
def browse(request, name, is_mobile=False):
    engine = request.GET.get('engine', 'solr')
    source = request.GET.get('source', 'data')

    if engine == 'solr':
        name = re.sub('^default\.', '', name)

    database = name.split('.', 1)[0]
    collections = get_engine(request.user, engine,
                             source=source).datasets(database=database)

    if not collections and engine == 'solr':
        return no_collections(request)

    collection = Collection2(user=request.user,
                             name=name,
                             engine=engine,
                             source=source)
    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"
                }],
                'qb_layout':
                QUERY_BUILDER_LAYOUT,
                'text_search_layout':
                TEXT_SEARCH_LAYOUT,
                'is_latest':
                _get_latest(),
                'engines':
                get_engines(request.user)
            }),
            'is_owner':
            True,
            'is_embeddable':
            request.GET.get('is_embeddable', False),
            'can_edit_index':
            can_edit_index(request.user),
            'mobile':
            is_mobile
        })
コード例 #18
0
def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_type):
  properties = {
    'sort': 'desc',
    'canRange': False,
    'stacked': False,
    'limit': 10,
    'mincount': 1,
    'isDate': False,
    'aggregate': {'function': 'unique', 'formula': '', 'plain_formula': '', 'percentile': 50}
  }

  if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'):
    facet_type = 'pivot'
  elif widget_type == 'document-widget':
    properties['uuid'] = facet_field
    properties['subfacet'] = {}
  else:
    api = get_engine(user, collection)
    range_properties = _new_range_facet(api, collection, facet_field, widget_type)

    if range_properties:
      facet_type = 'range'
      properties.update(range_properties)
      properties['initial_gap'] = properties['gap']
      properties['initial_start'] = properties['start']
      properties['initial_end'] = properties['end']
    else:
      facet_type = 'field'

    if widget_type in ('bucket-widget', 'pie2-widget', 'timeline-widget', 'tree2-widget', 'text-facet-widget', 'hit-widget', 'gradient-map-widget'):
      # properties = {'canRange': False, 'stacked': False, 'limit': 10} # TODO: Lighter weight top nested facet

      if widget_type == 'text-facet-widget':
        properties['type'] = facet_type

      properties['facets_form'] = NESTED_FACET_FORM
      # Not supported on dim 2 currently
      properties['facets_form']['type'] = 'field'
      properties['facets_form']['canRange'] = False
      properties['facets_form']['isFacetForm'] = True

      facet = NESTED_FACET_FORM.copy()
      facet['field'] = facet_field
      facet['limit'] = 10

      if range_properties:
        # TODO: timeline still uses properties from top properties
        facet.update(range_properties)
        facet['initial_gap'] = facet['gap']
        facet['initial_start'] = facet['start']
        facet['initial_end'] = facet['end']
        facet['stacked'] = False
        facet['type'] = 'range'
      else:
        facet['type'] = facet_type

      if collection.get('engine', 'solr') != 'solr':
        facet['sort'] = 'default'

      properties['facets'] = [facet]
      properties['domain'] = {'blockParent': [], 'blockChildren': []}

      if widget_type == 'hit-widget':
        facet_type = 'function'
        facet['aggregate']['function'] = 'unique'
      else:
        facet_type = 'nested'
        facet['aggregate']['function'] = 'count'

      if widget_type == 'pie2-widget':
        properties['scope'] = 'stack'
        properties['timelineChartType'] = 'bar'
      elif widget_type == 'tree2-widget':
        properties['scope'] = 'tree'
        properties['facets_form']['limit'] = 5
        properties['isOldPivot'] = True
      elif widget_type == 'gradient-map-widget':
        properties['scope'] = 'world'
        facet['limit'] = 100
      else:
        properties['scope'] = 'stack'
        properties['timelineChartType'] = 'bar'

  if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget') and widget_type != 'gradient-map-widget':
    properties['mincount'] = 1
    properties['facets'] = []
    properties['stacked'] = True
    properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 5}

    if widget_type == 'map-widget':
      properties['scope'] = 'world'
      properties['limit'] = 100
    else:
      properties['scope'] = 'stack' if widget_type == 'heatmap-widget' else 'tree'

  if widget_type == 'histogram-widget':
    properties['enableSelection'] = True
    properties['timelineChartType'] = 'bar'
    properties['extraSeries'] = []

  return {
    'id': facet_id,
    'label': facet_label,
    'field': facet_field,
    'type': facet_type,
    'widgetType': widget_type,
    'properties': properties,
    # Hue 4+
    'template': {
        "showFieldList": True,
        "showGrid": False,
        "showChart": True,
        "chartSettings" : {
          'chartType': 'pie' if widget_type == 'pie2-widget' else ('timeline' if widget_type == 'timeline-widget' else ('gradientmap' if widget_type == 'gradient-map-widget' else 'bars')),
          'chartSorting': 'none',
          'chartScatterGroup': None,
          'chartScatterSize': None,
          'chartScope': 'world',
          'chartX': None,
          'chartYSingle': None,
          'chartYMulti': [],
          'chartData': [],
          'chartMapLabel': None,
        },
        "fieldsAttributes": [],
        "fieldsAttributesFilter": "",
        "filteredAttributeFieldsAll": True,
        "fields": [],
        "fieldsSelected": [],
        "leafletmap": {'latitudeField': None, 'longitudeField': None, 'labelField': None}, # Use own?
        'leafletmapOn': False,
        'isGridLayout': False,
        "hasDataForChart": True,
        "rows": 25,
    },
    'queryResult': {}
  }
コード例 #19
0
ファイル: views.py プロジェクト: georgegrace1987/Hue_Practice
def index(request, is_mobile=False):
    engine = request.GET.get('engine', 'solr')
    cluster = request.POST.get('cluster', '""')
    collection_id = request.GET.get('collection')

    collections = get_engine(
        request.user, engine,
        cluster=cluster).datasets() if engine != 'report' else ['default']

    if not collections:
        if engine == 'solr':
            return no_collections(request)
        else:
            return importer(request)

    try:
        collection_doc = Document2.objects.get(id=collection_id)
        if USE_NEW_EDITOR.get():
            collection_doc.can_read_or_exception(request.user)
        else:
            collection_doc.doc.get().can_read_or_exception(request.user)
        collection = Collection2(request.user, document=collection_doc)
    except Exception as e:
        raise PopupException(
            e,
            title=
            _("Dashboard does not exist or you don't have the permission to access it."
              ))

    query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}

    if request.method == 'GET':
        if 'q' in request.GET:
            query['qs'][0]['q'] = antixss(request.GET.get('q', ''))
        if 'qd' in request.GET:
            query['qd'] = antixss(request.GET.get('qd', ''))

    template = 'search.mako'
    if is_mobile:
        template = 'search_m.mako'
    engine = collection.data['collection'].get('engine', 'solr')

    return render(
        template, request, {
            'collection':
            collection,
            'query':
            json.dumps(query),
            'initial':
            json.dumps({
                'collections': collections,
                'layout': DEFAULT_LAYOUT,
                'qb_layout': QUERY_BUILDER_LAYOUT,
                'text_search_layout': TEXT_SEARCH_LAYOUT,
                'is_latest': _get_latest(),
                'engines': get_engines(request.user)
            }),
            'is_owner':
            collection_doc.can_write(request.user) if USE_NEW_EDITOR.get() else
            collection_doc.doc.get().can_write(request.user),
            'can_edit_index':
            can_edit_index(request.user),
            'is_embeddable':
            request.GET.get('is_embeddable', False),
            'mobile':
            is_mobile,
            'is_report':
            collection.data['collection'].get('engine') == 'report'
        })