コード例 #1
0
def api_register_index(request):
    apikey = request.GET['api_key']
    index_name = request.GET['index_name']
    
    try:
        account = Account.objects.get(apikey=apikey)
    except Account.DoesNotExist: #@UndefinedVariable
        return HttpResponse('{"status":"ERROR", "message":"Invalid account"}')
    
    if len(account.indexes.all()) >= account.package.max_indexes:
        return HttpResponse('{"status":"ERROR", "message":"Account limit reached"}')
    else:
        index = Index()
        index.populate_for_account(account);
        index.name = index_name
        index.creation_time = datetime.datetime.now()
        index.language_code = 'en'
        try:
                index.save()
        except IntegrityError, ie:
                print('integrityError in api_register_index.', ie)
                return HttpResponse('{"status":"ERROR", "message":"You already have and Index with that name or code."}')
        
        index.base_port = STARTING_BASE_PORT + 10 * index.id
        index.code = get_index_code(index.id)
        index.save()
        start_index(index)
        response = '{"status":"OK", "index_code":"%s"}' % (index.code)
        return HttpResponse(response)
コード例 #2
0
def api_register_index(request):
    apikey = request.GET['api_key']
    index_name = request.GET['index_name']

    try:
        account = Account.objects.get(apikey=apikey)
    except Account.DoesNotExist:  #@UndefinedVariable
        return HttpResponse('{"status":"ERROR", "message":"Invalid account"}')

    if len(account.indexes.all()) >= account.package.max_indexes:
        return HttpResponse(
            '{"status":"ERROR", "message":"Account limit reached"}')
    else:
        index = Index()
        index.populate_for_account(account)
        index.name = index_name
        index.creation_time = datetime.datetime.now()
        index.language_code = 'en'
        try:
            index.save()
        except IntegrityError, ie:
            print('integrityError in api_register_index.', ie)
            return HttpResponse(
                '{"status":"ERROR", "message":"You already have and Index with that name or code."}'
            )

        index.base_port = STARTING_BASE_PORT + 10 * index.id
        index.code = get_index_code(index.id)
        index.save()
        start_index(index)
        response = '{"status":"OK", "index_code":"%s"}' % (index.code)
        return HttpResponse(response)
コード例 #3
0
    def _getDbIndices(self, cur, table_id):
        indices = []

        db_indices = cur.execute(
            """ SELECT * from dbd$indices
                                    WHERE table_id = :id""", {
                "id": table_id
            }).fetchall()

        for index in db_indices:
            tmp = Index()

            for item in self._getDbIndexDetails(cur, index[0]):
                tmp.fields.append(item.name)

            if index[2] is not None:
                tmp.name = str(index[2].encode('utf-8'))
            tmp.fulltext = index[3]
            if index[4] != "simple":
                tmp.uniqueness = index[4]

            indices.append(tmp)

        return indices