Exemplo n.º 1
0
def score_functions(request):
    #TODO: make it part of index/package configuration
    account = request.user.get_profile().account
    if request.method == 'GET':
        index_code = request.GET['index_code']
        index = Index.objects.get(code=index_code)

        functions = get_functions(index)

        form = ScoreFunctionForm()

        context = {
            'form': form,
            'account': request.user.get_profile().account,
            'navigation_pos': 'dashboard',
            'functions': functions,
            'index_code': index_code,
            'functions_available': len(functions) < functions_number,
        }

        return render('score_functions.html', request, context_dict=context)
    else:
        form = ScoreFunctionForm(data=request.POST)

        if form.is_valid():
            index_code = request.POST['index_code']
            index = Index.objects.get(code=index_code)
            name = form.cleaned_data['name']
            definition = form.cleaned_data['definition']

            client = ApiClient(account.get_private_apiurl()).get_index(
                index.name)
            try:
                client.add_function(int(name), definition)
            except InvalidDefinition, e:
                index = Index.objects.get(code=index_code)
                functions = get_functions(index)
                form = ScoreFunctionForm(initial={
                    'name': name,
                    'definition': definition
                })
                messages.error(request, 'Problem processing your formula: %s',
                               str(e))

                context = {
                    'form': form,
                    'account': request.user.get_profile().account,
                    'navigation_pos': 'dashboard',
                    'functions': functions,
                    'index_code': index_code,
                    'functions_available': len(functions) < functions_number,
                }

                return render('score_functions.html',
                              request,
                              context_dict=context)
Exemplo n.º 2
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})
Exemplo n.º 3
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})
Exemplo n.º 4
0
def score_functions(request):
    #TODO: make it part of index/package configuration
    account = request.user.get_profile().account
    if request.method == 'GET':
        index_code = request.GET['index_code']
        index = Index.objects.get(code=index_code)
    
        functions = get_functions(index)
    
        form = ScoreFunctionForm()
     
        context = {
          'form': form,
          'account': request.user.get_profile().account,
          'navigation_pos': 'dashboard',
          'functions': functions,
          'index_code': index_code,
          'functions_available': len(functions) < functions_number,
        }
        
        return render('score_functions.html', request, context_dict=context)
    else:
        form = ScoreFunctionForm(data=request.POST)
    
        if form.is_valid():
            index_code = request.POST['index_code']
            index = Index.objects.get(code=index_code)
            name = form.cleaned_data['name']
            definition = form.cleaned_data['definition']       
    
            client = ApiClient(account.get_private_apiurl()).get_index(index.name)
            try:
                client.add_function(int(name), definition)
            except InvalidDefinition, e: 
                index = Index.objects.get(code=index_code)
                functions = get_functions(index)
                form = ScoreFunctionForm(initial={'name': name, 'definition': definition})
                messages.error(request, 'Problem processing your formula: %s', str(e))
              
                context = {
                    'form': form,
                    'account': request.user.get_profile().account,
                    'navigation_pos': 'dashboard',
                    'functions': functions,
                    'index_code': index_code,
                    'functions_available': len(functions) < functions_number,
                }
    
                return render('score_functions.html', request, context_dict=context)