def search(): """ 客户搜索 :return: """ template_name = 'customer/search_modal.html' # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('Customer Search') # 搜索条件 form = CustomerSearchForm(request.form) form.owner_uid.choices = DEFAULT_SEARCH_CHOICES_INT + [ (user.id, user.name) for user in get_user_rows(**{'status_delete': STATUS_DEL_NO}) ] # app.logger.info('') search_condition = [ Customer.status_delete == STATUS_DEL_NO, ] if request.method == 'POST': # 表单校验失败 if not form.validate_on_submit(): flash(_('Search Failure'), 'danger') # 单独处理csrf_token if hasattr(form, 'csrf_token') and getattr(form, 'csrf_token').errors: map(lambda x: flash(x, 'danger'), form.csrf_token.errors) else: if form.company_type.data != DEFAULT_SEARCH_CHOICES_INT_OPTION: search_condition.append( Customer.company_type == form.company_type.data) if form.company_name.data: search_condition.append( Customer.company_name.like('%%%s%%' % form.company_name.data)) # 翻页数据 pagination = get_customer_pagination(form.page.data, PER_PAGE_BACKEND_MODAL, *search_condition) # 渲染模板 return render_template(template_name, form=form, pagination=pagination, **document_info)
def lists(): """ 客户列表 :return: """ template_name = 'customer/lists.html' # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('customer lists') # 搜索条件 form = CustomerSearchForm(request.form) form.owner_uid.choices = DEFAULT_SEARCH_CHOICES_INT + [ (user.id, user.name) for user in get_user_rows(**{'status_delete': STATUS_DEL_NO}) ] # app.logger.info('') search_condition = [ Customer.status_delete == STATUS_DEL_NO, ] if request.method == 'POST': # 表单校验失败 if not form.validate_on_submit(): flash(_('Search Failure'), 'danger') # 单独处理csrf_token if hasattr(form, 'csrf_token') and getattr(form, 'csrf_token').errors: map(lambda x: flash(x, 'danger'), form.csrf_token.errors) else: if form.company_name.data: search_condition.append( Customer.company_name.like('%%%s%%' % form.company_name.data)) if form.company_type.data != DEFAULT_SEARCH_CHOICES_INT_OPTION: search_condition.append( Customer.company_type == form.company_type.data) if form.owner_uid.data != DEFAULT_SEARCH_CHOICES_INT_OPTION: search_condition.append( Customer.owner_uid == form.owner_uid.data) if form.start_create_time.data: search_condition.append( Customer.create_time >= form.start_create_time.data) if form.end_create_time.data: search_condition.append( Customer.create_time <= form.end_create_time.data) # 处理导出 if form.op.data == OPERATION_EXPORT: # 检查导出权限 if not permission_customer_section_export.can(): abort(403) column_names = Customer.__table__.columns.keys() query_sets = get_customer_rows(*search_condition) return excel.make_response_from_query_sets( query_sets=query_sets, column_names=column_names, file_type='csv', file_name='%s.csv' % _('customer lists')) # 批量删除 if form.op.data == OPERATION_DELETE: # 检查删除权限 if not permission_customer_section_del.can(): abort(403) customer_ids = request.form.getlist('customer_id') # 检查删除权限 permitted = True for customer_id in customer_ids: # TODO 资源删除权限验证 if False: ext_msg = _('Permission Denied') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break # 检查是否正在使用 # 1、报价 if count_quotation(**{ 'customer_cid': customer_id, 'status_delete': STATUS_DEL_NO }): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break # 2、订单 if count_sales_order(**{ 'customer_cid': customer_id, 'status_delete': STATUS_DEL_NO }): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break # 3、敏感型号 if count_production_sensitive(**{ 'customer_cid': customer_id, 'status_delete': STATUS_DEL_NO }): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break if permitted: result_total = True for customer_id in customer_ids: current_time = datetime.utcnow() customer_data = { 'status_delete': STATUS_DEL_OK, 'delete_time': current_time, 'update_time': current_time, } result = edit_customer(customer_id, customer_data) if result: # 发送删除信号 signal_data = { 'customer_id': customer_id, 'status_delete': STATUS_DEL_OK, 'current_time': current_time, } signal_customer_status_delete.send(app, **signal_data) result_total = result_total and result if result_total: flash(_('Del Success'), 'success') else: flash(_('Del Failure'), 'danger') # 翻页数据 pagination = get_customer_pagination(form.page.data, PER_PAGE_BACKEND, *search_condition) # 渲染模板 return render_template(template_name, form=form, pagination=pagination, **document_info)
def lists(): """ 用户列表 :return: """ template_name = 'user/lists.html' # 文档信息 document_info = DOCUMENT_INFO.copy() document_info['TITLE'] = _('user lists') # 搜索条件 form = UserSearchForm(request.form) search_condition = [ User.status_delete == STATUS_DEL_NO, ] if request.method == 'POST': # 表单校验失败 if not form.validate_on_submit(): flash(_('Search Failure'), 'danger') # 单独处理csrf_token if hasattr(form, 'csrf_token') and getattr(form, 'csrf_token').errors: map(lambda x: flash(x, 'danger'), form.csrf_token.errors) else: if form.name.data: search_condition.append(User.name == form.name.data) if form.role_id.data != DEFAULT_SEARCH_CHOICES_INT_OPTION: search_condition.append(User.role_id == form.role_id.data) if form.start_create_time.data: search_condition.append(User.create_time >= form.start_create_time.data) if form.end_create_time.data: search_condition.append(User.create_time <= form.end_create_time.data) # 处理导出 if form.op.data == OPERATION_EXPORT: # 检查导出权限 if not permission_user_section_export.can(): abort(403) column_names = User.__table__.columns.keys() query_sets = get_user_rows(*search_condition) return excel.make_response_from_query_sets( query_sets=query_sets, column_names=column_names, file_type='csv', file_name='%s.csv' % _('user lists') ) # 批量删除 if form.op.data == OPERATION_DELETE: # 检查删除权限 if not permission_user_section_del.can(): abort(403) user_ids = request.form.getlist('user_id') # 检查删除权限 permitted = True for user_id in user_ids: # 检查是否正在使用 # 1、报价 if count_quotation(**{'uid': user_id, 'status_delete': STATUS_DEL_NO}): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break # 2、销售订单 if count_sales_order(**{'uid': user_id, 'status_delete': STATUS_DEL_NO}): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break # 3、销售出货 if count_delivery(**{'uid': user_id, 'status_delete': STATUS_DEL_NO}): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break # 4、询价 if count_enquiry(**{'uid': user_id, 'status_delete': STATUS_DEL_NO}): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break # 5、采购订单 if count_buyer_order(**{'uid': user_id, 'status_delete': STATUS_DEL_NO}): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break # 6、采购进货 if count_purchase(**{'uid': user_id, 'status_delete': STATUS_DEL_NO}): ext_msg = _('Currently In Use') flash(_('Del Failure, %(ext_msg)s', ext_msg=ext_msg), 'danger') permitted = False break if permitted: result_total = True for user_id in user_ids: current_time = datetime.utcnow() user_data = { 'status_delete': STATUS_DEL_OK, 'delete_time': current_time, 'update_time': current_time, } result = edit_user(user_id, user_data) result_total = result_total and result if result_total: flash(_('Del Success'), 'success') else: flash(_('Del Failure'), 'danger') # 翻页数据 pagination = get_user_pagination(form.page.data, PER_PAGE_BACKEND, *search_condition) # 渲染模板 return render_template( template_name, form=form, pagination=pagination, **document_info )
def get_sales_user_list(): sales_user_list = deepcopy(DEFAULT_SEARCH_CHOICES_INT) user_list = get_user_rows(**{'role_id': TYPE_ROLE_SALES}) sales_user_list.extend([(0, '-')]) sales_user_list.extend([(user.id, user.name) for user in user_list]) return sales_user_list