Esempio n. 1
0
def collections_import(request):
    if request.method != 'POST':
        raise PopupException(_('POST request required.'))

    response = {'status': -1}

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

    if collection:
        searcher = CollectionManagerController(request.user)
        unique_key, fields = searcher.get_fields(collection.get('name'))

        # Create collection and metadata.
        hue_collection, created = Collection.objects.get_or_create(
            name=collection.get('name'),
            solr_properties='{}',
            is_enabled=True,
            user=request.user)
        properties_dict = hue_collection.properties_dict
        properties_dict['data_type'] = 'separated'
        properties_dict['field_order'] = [field_name for field_name in fields]
        hue_collection.properties = json.dumps(properties_dict)
        hue_collection.save()

        response['status'] = 0
        response['message'] = _('Collection created!')
    else:
        response['message'] = _('Collection missing.')

    return HttpResponse(json.dumps(response), mimetype="application/json")
Esempio n. 2
0
File: api.py Progetto: Lt-Pone/hue
def collections_import(request):
  if request.method != 'POST':
    raise PopupException(_('POST request required.'))

  response = {'status': -1}

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

  if collection:
    searcher = CollectionManagerController(request.user)
    unique_key, fields = searcher.get_fields(collection.get('name'))

    # Create collection and metadata.
    hue_collection, created = Collection.objects.get_or_create(name=collection.get('name'), solr_properties='{}', is_enabled=True, user=request.user)
    properties_dict = hue_collection.properties_dict
    properties_dict['data_type'] = 'separated'
    properties_dict['field_order'] = [field_name for field_name in fields]
    hue_collection.properties = json.dumps(properties_dict)
    hue_collection.save()

    response['status'] = 0
    response['message'] = _('Collection created!')
  else:
    response['message'] = _('Collection missing.')

  return JsonResponse(response)
Esempio n. 3
0
def collections_fields(request, collection):
  if request.method != 'GET':
    raise PopupException(_('GET request required.'))

  response = {}

  searcher = CollectionManagerController(request.user)
  unique_key, fields = searcher.get_fields(collection)

  response['status'] = 0
  response['fields'] = [(field, fields[field]['type'], fields[field].get('indexed', None), fields[field].get('stored', None)) for field in fields]
  response['unique_key'] = unique_key

  return JsonResponse(response)