Esempio n. 1
0
def manage_index(request, index_code=None):
    account = request.user.get_profile().account

    index = Index.objects.get(code=index_code)

    if index:
        if index.account == account:
            if request.method == 'GET':
                index = Index.objects.get(code=index_code)

                largest_func = max(
                    [int(f.name) + 1
                     for f in index.scorefunctions.all()] + [5])
                functions = get_functions(index, upto=largest_func)

                context = {
                    'account': request.user.get_profile().account,
                    'navigation_pos': 'dashboard',
                    'functions': functions,
                    'index': index,
                    'index_code': index_code,
                    'largest_func': largest_func
                }

                if 'query' in request.GET:
                    maxim = int(request.GET.get('max', '25'))
                    index_client = ApiClient(
                        account.get_private_apiurl()).get_index(index.name)
                    context['results'] = index_client.search(
                        request.GET['query'], length=max)
                    context['query'] = request.GET['query']
                    context['more'] = maxim + 25

                return render('manage_index.html',
                              request,
                              context_dict=context)
            else:
                if 'definition' in request.POST:
                    name = request.POST['name']
                    definition = request.POST['definition']

                    client = ApiClient(account.get_private_apiurl()).get_index(
                        index.name)
                    try:
                        if definition:
                            client.add_function(int(name), definition)
                        else:
                            client.delete_function(int(name))
                    except InvalidDefinition, e:
                        return HttpResponse('Invalid function', status=400)

                    return JsonResponse({'largest': 5})
                elif 'public_api' in request.POST:
                    index.public_api = request.POST['public_api'] == 'true'
                    index.save()
                    return JsonResponse({'public_api': index.public_api})
Esempio n. 2
0
def remove_function(request):
    account = request.user.get_profile().account
    if request.method == 'GET':
        index_code = request.GET['index_code']
        index = Index.objects.get(code=index_code)
        function_name = request.GET['function_name']
        client = ApiClient(account.get_private_apiurl()).get_index(index.name)
        client.delete_function(function_name)
    
    return HttpResponseRedirect(reverse('score_functions') + '?index_code=' + index_code)
Esempio n. 3
0
def remove_function(request):
    account = request.user.get_profile().account
    if request.method == 'GET':
        index_code = request.GET['index_code']
        index = Index.objects.get(code=index_code)
        function_name = request.GET['function_name']
        client = ApiClient(account.get_private_apiurl()).get_index(index.name)
        client.delete_function(function_name)

    return HttpResponseRedirect(
        reverse('score_functions') + '?index_code=' + index_code)
Esempio n. 4
0
def manage_index(request, index_code=None):
    account = request.user.get_profile().account
    
    index = Index.objects.get(code=index_code)
    
    if index:
        if index.account == account:
            if request.method == 'GET':
                index = Index.objects.get(code=index_code)
            
                largest_func = max([int(f.name) + 1 for f in index.scorefunctions.all()] + [5])
                functions = get_functions(index, upto=largest_func)
             
                context = {
                  'account': request.user.get_profile().account,
                  'navigation_pos': 'dashboard',
                  'functions': functions,
                  'index': index,
                  'index_code': index_code,
                  'largest_func': largest_func
                }

                if 'query' in request.GET:
                    maxim = int(request.GET.get('max', '25'))
                    index_client = ApiClient(account.get_private_apiurl()).get_index(index.name)
                    context['results'] = index_client.search(request.GET['query'], length=max)
                    context['query'] = request.GET['query']
                    context['more'] = maxim + 25

                
                return render('manage_index.html', request, context_dict=context)
            else:
                if 'definition' in request.POST:
                    name = request.POST['name']
                    definition = request.POST['definition']       
                
                    client = ApiClient(account.get_private_apiurl()).get_index(index.name)
                    try:
                        if definition:
                            client.add_function(int(name), definition)
                        else:
                            client.delete_function(int(name))
                    except InvalidDefinition, e: 
                        return HttpResponse('Invalid function', status=400)
                          
                    return JsonResponse({'largest': 5})
                elif 'public_api' in request.POST:
                    index.public_api = request.POST['public_api'] == 'true'
                    index.save()
                    return JsonResponse({'public_api': index.public_api})