Ejemplo n.º 1
0
def _save_query(question, jieba_segment, fool_segment, jieba_keywords,
                fool_keywords, fool_search_result, jieba_search_result):
    database = 'Unicom'
    collection = 'query'

    document = {
        'question': question,
        'jiebaSegment': jieba_segment,
        'foolSegment': fool_segment,
        'jiebaKeywords': jieba_keywords,
        'foolKeywords': fool_keywords,
        'foolSearchResult': fool_search_result,
        'jiebaSearchResult': jieba_search_result,
    }

    try:
        conn = get_mongo_collection(database, collection)
        conn.insert_one(document)
    except Exception as err:
        print(err)
        return False, err

    return True
Ejemplo n.º 2
0
# Create your views here.
@login_required(login_url='/accounts/login/')
@permission_required('myapp.can_see_mongodb_query', login_url='/')
def mongodb_query(request):
    try:
        favword = request.COOKIES['myfavword']
    except Exception, e:
        pass
    dblist = mongo.get_mongodb_list(request.user.username)
    #dblist = ['ymmSmsLogYm','table2','table3','table4']
    if request.method == 'POST':
        form = AddForm(request.POST)

        #instancetag = request.POST['instancetag']
        choosedb = request.POST['choosedb']
        tblist = mongo.get_mongo_collection(choosedb, request.user.username)
        try:
            if request.POST.has_key('gettblist'):

                return render(request, 'mongodb_query.html', locals())
            elif request.POST.has_key('query'):
                #return HttpResponse(tablename)
                choosed_tb = request.POST['choosed_tb']
                if form.is_valid():
                    a = form.cleaned_data['a']
                    func.log_mongo_op(a, choosedb, choosed_tb, request)
                    msg = "error"
                    data_list, msg = mongo.get_mongo_data(
                        a, choosedb, choosed_tb, request.user.username)
                # print data_list
                return render(request, 'mongodb_query.html', locals())