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)
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)
def modify_password(): form = ResetPasswordForm() if form.validate_on_submit(): if form.new_password.data != form.confirm_password.data: flash_error(u'两次输入密码不一致') else: success = False error_msg = u'非常抱歉服务器出错了, 请稍后重试或者联系系统管理员.' if g.user.system == 'ucenter': try: success = uc_change_password(g.user.id, form.original_password.data, form.new_password.data) except Exception as e: if hasattr(e, 'message'): error_msg = e.message else: result = bmw_change_password(g.user.id, form.original_password.data, form.new_password.data) if isinstance(result, dict): if 'status' in result and result['status'] == 0: success = True if 'message' in result: error_msg = result['message'] if success: flash_success(u'密码修改成功') else: flash_error(error_msg) return render_template('settings/security.html', selected_menu=MODIFY_PASSWORD, form=form)
def edit(selected_menu, campaign=None): current_user = g.user store_id = get_or_set_store_id() from application.forms.campaign import CampaignForm form = None campaign_cars = [] if campaign: campaign_cars = campaign.related_cars.split(',') form = CampaignForm(obj=campaign) else: form = CampaignForm() lookup = Lookup.find_by_name_and_store(store_id, 'intent-car') if lookup: cars = LookupValue.find_all_by_lookup_id(lookup.id) form.related_cars.choices = [(car.code, car.value) for car in cars] if form.related_cars.choices is None: form.related_cars.choices = [] if request.method == 'GET': form.related_cars.data = campaign_cars if request.method == 'POST' and form.validate_on_submit(): if campaign is None: campaign = Campaign() campaign.store_id = store_id form.populate_obj(campaign) campaign.related_cars = u','.join(form.related_cars.data) campaign.save_and_flush() flash_success(gettext(u'campaign saved')) return redirect(url_for('campaigns.campaigns')) # form. # campaign = form.po # if form.validate_on_submit(): # json_r = uc_login(form.username.data, form.password.data) # # if json_r and json_r['status'] == 0 and get_user_type(json_r) == 6: # user = save_user_from_uc(json_r) # add_user(user) # return redirect(referer or url_for('user.dashboard')) # # flash_error(gettext(u'login failed')) return render_template('campaigns/edit.html', selected_menu=selected_menu, campaign=campaign, form=form, back_url=back_url(url_for('campaigns.campaigns')))
def app_detail(app_name): app = AppMeta.find_by_name(app_name) notes = ReleaseHistory.find_all_by_app_name(app_name) form = AppUpgradeForm() if form.validate(): app.upgrade(form.version.data, form.version_num.data, form.note.data) flash_success(u'成功提交升级信息') return redirect( url_for('ops.app_detail', app_name=app_name, back_url=back_url(url_for('ops.apps'))), code=303) return render_template('ops/app_detail.html', selected_menu=APPS_MGMT_SUMMARY, app=app, notes=notes, form=form, back_url=back_url(url_for('ops.apps')))
def view_details(cid): current_user = g.user store_id = get_or_set_store_id() customer = Customer.find_by_id_and_store(cid, store_id) if not customer: abort(404) orders = Order.find_all_by_customer_sales(customer.id) appts = Appointment.find_all_by_customer_sales(customer.id) receptions = Reception.find_all_by_customer_sales(customer.id) calllogs = Calllog.find_all_by_customer_id(customer.id) form = CustomerReassignForm() form.saleses_list.choices = get_sales_selection(store_id) if current_user.is_receptionist() or ( current_user.is_sales() and current_user.is_role_in_store_id(store_id, 'manager') == False and customer.sales_id != current_user.id): abort(401) if request.method == 'GET': form.saleses_list.data = customer.sales_id if request.method == 'POST' and ( form.saleses_list.data not in ('None', customer.sales_id) and current_user.is_role_in_store_id(store_id, 'manager')): customer.reassign(int(form.saleses_list.data)) customer.save_and_flush() flash_success(u'重新分配成功') return redirect(url_for('customers.view_details', cid=cid, back_url=back_url( url_for('customers.customers'))), code=303) return render_template('customers/detail.html', selected_menu=CUSTOMER_MGMT, customer=customer, orders=orders, appts=appts, receptions=receptions, calllogs=calllogs, form=form, back_url=back_url(url_for('customers.customers')))
def import_inv(): if request.method == 'POST': upload_file = request.files['upload_file'] if not upload_file or not allowed_file(upload_file.filename): flash_error(u'导入文件不存在或者不是合法的文件类型') else: origin_file_name = upload_file.filename store_id = get_or_set_store_id() gen_file_name = gen_inv_upload_file_path(store_id, origin_file_name) upload_file.save(gen_file_name) import_his = InvImportHistory() import_his.origin_file = origin_file_name import_his.import_file = os.path.relpath( gen_file_name, current_app.config['INV_UPLOAD_FOLDER']) db.session.add(import_his) Inventory.save_from_excel(gen_file_name, store_id) flash_success(u'导入成功') return redirect(url_for('inventories.inventories'))
def cancel_order(): current_user = g.user store_id = get_or_set_store_id() form = OrderCancelForm() if form.order_id.data is None or int(form.order_id.data) < 1: flash_error(u'订单信息错误,请选择需要取消的订单') else: order = Order.find_by_id_and_store(form.order_id.data, store_id) if not order: abort(404) if order and order.status not in ('delivered', 'cancelled'): order.status = 'cancelled' order.save_and_flush() flash_success(u'订单已取消') elif order: flash_error(u'订单已交车或已取消') else: flash_error(u'找不到需要取消的订单') return redirect(url_for('orders.orders'))