コード例 #1
0
def insert_new_document():
    # assemble a dict
    new_document = dict()
    new_document['document_hash'] = create_rec_hash()
    new_document['factory_no'] = request.form.get('factory_no')
    new_document['date'] = request.form.get('date')
    new_document['time'] = request.form.get('time')
    new_document['datetime'] = request.form.get('datetime')
    new_document['elec_indicator'] = request.form.get('elec_indicator')
    new_document['employee_no'] = request.form.get('employee_no')
    new_document['employee_name'] = request.form.get('employee_name')

    oid = mongo.db.Elec_Collection.insert_one(new_document).inserted_id
    rid = str(oid)

    # return redirect(url_for('get_competition_by__id', rid=rid))
    # return the success info
    return get_document_by__id(rid=rid)
コード例 #2
0
def post():
    form = PostForm()
    # 处理 POST 的逻辑
    if form.validate_on_submit():
        # 发起请求的数据库操作 url
        insert_url = 'http://' + Config.DB_CONNECTOR_URL + '/insert-post/' + create_rec_hash()
        # 发送 POST 请求的数据
        post_data = {
            'username': form.username.data,
            'post': form.comment.data,
            'postTime': get_current_time()
        }
        # 发出 POST 请求
        result = requests.post(insert_url, data=post_data)
        if result.status_code is 200:
            # flash('Comment post success!{}'.format(form.username.data, form.comment.data))
            flash('Comment post success!')
        else:
            flash('Comment post failed!')
        return redirect('/')
コード例 #3
0
ファイル: api.py プロジェクト: datascicamp/CompetitionPart
def insert_new_competition():
    # Revert list-like string to list
    comp_scenario_list = str_to_right_type(request.form.get('comp_scenario'))
    comp_data_feature_list = str_to_right_type(
        request.form.get('data_feature'))

    # Revert dict-like string to dict
    comp_host_list = str_to_right_type(request.form.get('comp_host'))

    # assemble a dict
    new_competition = dict()
    new_competition['comp_record_hash'] = create_rec_hash()
    new_competition['comp_title'] = request.form.get('comp_title')
    new_competition['comp_subtitle'] = request.form.get('comp_subtitle')
    new_competition['comp_range'] = request.form.get('comp_range')
    new_competition['comp_url'] = request.form.get('comp_url')
    new_competition['comp_description'] = request.form.get('comp_description')
    new_competition['comp_host'] = comp_host_list
    new_competition['prize_amount'] = request.form.get('prize_amount')
    new_competition['prize_currency'] = request.form.get('prize_currency')
    new_competition['publish_time'] = request.form.get('publish_time')
    new_competition['update_time'] = request.form.get('update_time')
    new_competition['deadline'] = request.form.get('deadline')
    new_competition['timezone'] = request.form.get('timezone')
    # for multiple competition scenarios
    new_competition['comp_scenario'] = comp_scenario_list
    # for multiple competition data features
    new_competition['data_feature'] = comp_data_feature_list
    new_competition['contributor_id'] = request.form.get('contributor_id')
    new_competition['contributor_name'] = request.form.get('contributor_name')

    oid = mongo.db.Competition.insert_one(new_competition).inserted_id
    rid = str(oid)

    # return redirect(url_for('get_competition_by__id', rid=rid))
    # return the success info
    return get_competition_by__id(rid=rid)