示例#1
0
def overview():
    from application.forms.ops import TimePeriodForm
    search_form = TimePeriodForm(request.args)
    query = dict()
    if search_form.start.data and search_form.start.data != '':
        query['start_date'] = search_form.start.data
    if search_form.end.data and search_form.end.data != '':
        query['end_date'] = search_form.end.data

    query['store_filter'] = 'all'

    result = []
    if validate(query):
        start = query['start_date']
        end = query['end_date']

        stores = Store.find_all()
        stores = sorted(stores, key=lambda s: s.name)
        for store in stores:
            if store.id > 0:
                stats_data = get_store_stats(start, end, store.id, ALL_STATS)
                stats_data['online_days'] = get_radar_online_days(start, end, store.id)
                if stats_data['rx_count'] > 0:
                    stats_data['incomplete_rx_percent'] = str(
                        stats_data['incomplete_rx_count'] * 100 / stats_data['rx_count']) + '%'
                else:
                    stats_data['incomplete_rx_percent'] = 'N/A'
                result.append((store.id, store.name, stats_data))

    return render_template('ops/overview.html', selected_menu=OPS_OVERVIEW, form=search_form, stats=result)
示例#2
0
def download_overview():
    # TODO: refactor to remove duplications with overview method.
    from application.docgen.docgen import generate_ops_overview_excel, OUTPUT_FOLDER
    from application.forms.ops import TimePeriodForm
    search_form = TimePeriodForm(request.args)
    query = dict()
    if search_form.start.data and search_form.start.data != '':
        query['start_date'] = search_form.start.data
    if search_form.end.data and search_form.end.data != '':
        query['end_date'] = search_form.end.data

    query['store_filter'] = 'all'

    result = []
    if validate(query):
        start = query['start_date']
        end = query['end_date']

        stores = Store.find_all()
        stores = sorted(stores, key=lambda s: s.name)
        for store in stores:
            if store.id > 0:
                stats_data = get_store_stats(start, end, store.id, ALL_STATS)
                stats_data['online_days'] = get_radar_online_days(start, end, store.id)
                if stats_data['rx_count'] > 0:
                    stats_data['incomplete_rx_percent'] = str(
                        stats_data['incomplete_rx_count'] * 100 / stats_data['rx_count']) + '%'
                else:
                    stats_data['incomplete_rx_percent'] = 'N/A'
                result.append((store.id, store.name, stats_data))
        generated_filename = generate_ops_overview_excel(start, end, result)
        # TODO: change a more efficient way to serve static file.
        return send_from_directory(OUTPUT_FOLDER, generated_filename)

    return render_template('ops/overview.html', selected_menu=OPS_OVERVIEW, form=search_form, stats=result)
示例#3
0
def lookupvalues_add(lookup_id):
    from application.models.lookup import Lookup
    from application.createlookupvalues import add_lookupvalue, check_looupvalue

    lookup_by_store_and_name = Lookup.get_description_by_store_id(lookup_id)
    descriptions = get_stores_descriptions_and_lookupvalues(lookup_id)
    version = lookup_by_store_and_name.version

    store_name = Store.find_storename_by_store_id(lookup_by_store_and_name.store_id).name

    if request.method == 'POST':
        changevalues = convert_changevalues(request.form)
        message = check_looupvalue(lookup_id, changevalues)
        if message:
            flash_error(message)
            return redirect(url_for('ops.lookupvalues_add', lookup_id=lookup_id), code=303)

        count = add_lookupvalue(lookup_id, version, changevalues)
        if count is None:
            flash_error(u"更新失败!")
        elif count == 0:
            flash_info(u"未发生更新!")
        else:
            flash_success(u"成功更新%s条信息!" % count)

        return redirect(url_for('ops.lookupvalues_add', lookup_id=lookup_id), code=303)

    return render_template('ops/lookupvalues_add.html', store_name=store_name, lookup_by_id=lookup_by_store_and_name,
                           descriptions=descriptions, lookup_id=lookup_id)
示例#4
0
def lookupvalues_upload(store_id):
    from application.forms.ops import CreateLookupvalueForm
    from application.createlookupvalues import generate_lookup, generate_lookupvalue
    from application.nutils.excel import load_excel

    store_name = Store.find_storename_by_store_id(store_id).name

    form = CreateLookupvalueForm()

    redirect_url = redirect(
        url_for('ops.lookupvalues_upload', store_id=store_id), code=303)

    if form.validate_on_submit():
        filename = secure_filename(form.lookupvalue_file.data.filename)
        if check_filename(filename, store_id):
            lookupvalues_file = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
            form.lookupvalue_file.data.save(lookupvalues_file)

            lookupvalues_data = load_excel(lookupvalues_file)

            lookup_ids = generate_lookup(store_id)

            if generate_lookupvalue(lookup_ids, lookupvalues_data):
                flash_success(u"店面信息导入完成")
                return redirect_url

        else:
            flash_error(u'上传的文件名错误')
            return redirect_url

    return render_template('ops/lookupvalues_upload.html', storename=store_name, form=form)
示例#5
0
def lookupvalues():
    from application.forms.ops import LookupvalueForm
    from application.models.lookup import LookupValue

    selections = remove_empty_storename(get_stores_selection())

    search_lookupvalue = LookupvalueForm(request.args)
    search_lookupvalue.store_filter.choices = selections

    lookup_id = request.args.get('lookup_filter', None)
    descriptions = get_stores_descriptions_and_lookupvalues(lookup_id)

    if search_lookupvalue.store_filter.data and search_lookupvalue.store_filter.data not in ('None', 'all'):
        store_id = search_lookupvalue.store_filter.data
        store_name = Store.find_storename_by_store_id(store_id).name

        from application.models.lookup import Lookup
        id_and_description = Lookup.get_descriptions_by_store_id(store_id)
        search_lookupvalue.lookup_filter.choices = [(lookup.id, lookup.description) for lookup in id_and_description]
    else:
        store_id = ''
        store_name = ''
        search_lookupvalue.lookup_filter.choices = {}

    if lookup_id and lookup_id is not None:
        lookupvalueslist = LookupValue.find_all_by_lookup_id_by_order(lookup_id)
    else:
        lookupvalueslist = []

    return render_template('ops/lookupvalue.html', selected_menu=LOOKUPVALUE_MGMT_SUMMARY, form=search_lookupvalue,
                           lookupvalues=lookupvalueslist, descriptions=descriptions, storename=store_name,
                           lookup_id=lookup_id, store_id=store_id)
示例#6
0
文件: ops_api.py 项目: sungitly/isr
def ops_stats_daily(store_id):
    now = datetime.datetime.now()
    start_date = request.args.get('start', None)
    if start_date:
        start_date = parse(start_date)
    else:
        start_date = get_last_monday(now)

    end_date = request.args.get('end', None)
    if end_date:
        end_date = parse(end_date)
    else:
        end_date = get_last_sunday(now)

    stores = Store.find_all_by_stores_ids([store_id])

    result = dict()
    if stores and len(stores) > 0:
        store = stores[0]
        stats_data = get_store_daily_stats(start_date, end_date, store.id,
                                           ALL_STATS)
        result['store_id'] = store.id
        result['storename'] = store.name
        result['data'] = stats_data
        return result
示例#7
0
def get_stores_selection():
    from application.models.store import Store

    selections = [('', u'选择4S店')]
    # stores = User.find_all_stores()
    stores = Store.find_all()
    for store in stores:
        selections.append((store.id, store.name))
    return selections
示例#8
0
def create_stores():
    """
    ms
    :param request_user_id:
    :return:
    """
    request_params = request.get_json()
    name = request_params.get('name')
    category = request_params.get('category')

    # day가 제대로 입력이 안된 경우
    if name is None:
        return jsonify(
            userMessage="가게 이름을 기입해주세요."
        ), 400

    # category가 제대로 입력이 안된 경우
    if category is None:
        return jsonify(
            userMessage="카테고리 정보를 기입해주세요."
        ), 400

    # 이미 등록되어있는지 확인
    q = db.session.query(Store).filter(Store.name == name, Store.category == category)
    if q.count() > 0:
        return jsonify(
            userMessage="이미 기입되어 있는 내용입니다."
        ), 409

    try:
        for key in request_params.keys():
            request_params[SerializableModelMixin.to_snakecase(key)] = request_params.pop(key)

        store = Store(**request_params)
        db.session.add(store)
        db.session.commit()

        return jsonify(
            data=store.serialize()
        ), 200
    except:
        return jsonify(
            userMessage="오류가 발생했습니다. 관리자에게 문의해주세요."
        ), 403
示例#9
0
文件: ops_api.py 项目: sungitly/isr
def ops_stats():
    now = datetime.datetime.now()
    start_date = request.args.get('start', get_last_monday(now))
    end_date = request.args.get('end', get_last_sunday(now))
    store_ids = parse_comma_seperated_args(request.args.get('store_id', None))

    if len(store_ids) == 0:
        stores = Store.find_all()
    else:
        stores = Store.find_all_by_stores_ids(store_ids)

    result = []
    for store in stores:
        if store.id > 0:
            stats_data = get_store_stats(start_date, end_date, store.id,
                                         ALL_STATS)
            result.append((store.id, store.name, stats_data))

    return result
示例#10
0
def create_stores():
    """
    ms
    :param request_user_id:
    :return:
    """
    request_params = request.get_json()
    name = request_params.get('name')
    category = request_params.get('category')

    # day가 제대로 입력이 안된 경우
    if name is None:
        return jsonify(userMessage="가게 이름을 기입해주세요."), 400

    # category가 제대로 입력이 안된 경우
    if category is None:
        return jsonify(userMessage="카테고리 정보를 기입해주세요."), 400

    # 이미 등록되어있는지 확인
    q = db.session.query(Store).filter(Store.name == name,
                                       Store.category == category)
    if q.count() > 0:
        return jsonify(userMessage="이미 기입되어 있는 내용입니다."), 409

    try:
        for key in request_params.keys():
            request_params[SerializableModelMixin.to_snakecase(
                key)] = request_params.pop(key)

        store = Store(**request_params)
        db.session.add(store)
        db.session.commit()

        return jsonify(data=store.serialize()), 200
    except:
        return jsonify(userMessage="오류가 발생했습니다. 관리자에게 문의해주세요."), 403