def storage(): dates_info = {} start_str = request.args.get('start_date', datetime.now().strftime(DATE_FORMAT)) start = datetime.strptime(start_str, DATE_FORMAT).date() m_dict = defaultdict(list) dates_list = [] for x in range(0, 30): current = start + timedelta(days=x) m_dict[current.month].append(current) dates_list.append(current) dates_info['dates'] = dates_list dates_info['months'] = [(m, len(d_list)) for m, d_list in m_dict.items()] medium_id = int(request.args.get('selected_medium', 0)) select_medium = [(m.id, m.name) for m in Medium.all()] select_medium.insert(0, (0, u'全部媒体')) positions_info = AdPosition.all_positions_info_by_date() if medium_id: medium = Medium.get(medium_id) positions_info = medium.positions_info_by_date() return tpl( 'storage.html', dates_info=dates_info, medium=select_medium, medium_id=medium_id, positions_info=positions_info, start_date=start_str, per_start_date=(start - timedelta(days=30)).strftime(DATE_FORMAT), next_start_date=(start + timedelta(days=30)).strftime(DATE_FORMAT))
def validate(self): if Form.validate(self): if not self.estimate_num.hidden: if self.ad_type.data == AD_TYPE_NORMAL: if self.max_order_num.data > self.estimate_num.data: self.max_order_num.errors.append( u"最大预订不能大于预估量(如果新添加了广告单元, 请先保存, 然后根据计算所得调整)") return False elif self.ad_type.data == AD_TYPE_CPD: if self.cpd_num.data > self.estimate_num.data: self.cpd_num.errors.append(u"CPD量不能大于预估量") return False units = AdUnit.gets(self.units.data) medium = Medium.get(self.medium.data) if not units: self.units.errors.append(u"所含广告单元不能为空") return False for u in units: if u.medium != medium: self.units.errors.append(u"%s不属于%s" % (u.display_name, medium.name)) return False return True else: return False
def validate(self): if Form.validate(self): if not self.estimate_num.hidden: if self.ad_type.data == AD_TYPE_NORMAL: if self.max_order_num.data > self.estimate_num.data: self.max_order_num.errors.append( u"最大预订不能大于预估量(如果新添加了广告单元, 请先保存, 然后根据计算所得调整)") return False elif self.ad_type.data == AD_TYPE_CPD: if self.cpd_num.data > self.estimate_num.data: self.cpd_num.errors.append(u"CPD量不能大于预估量") return False units = AdUnit.gets(self.units.data) medium = Medium.get(self.medium.data) if not units: self.units.errors.append(u"所含广告单元不能为空") return False for u in units: if u.medium != medium: self.units.errors.append( u"%s不属于%s" % (u.display_name, medium.name)) return False return True else: return False
def new_position(): form = PositionForm(request.form) form.estimate_num.hidden = True form.cpd_num.hidden = True form.max_order_num.hidden = True # the medium and size field will be set value at the same time: any data post to server side if form.medium.data and form.size.data: form_size = AdSize.get(form.size.data) form.units.choices = [(x.id, x.display_name) for x in AdUnit.query.filter_by( medium_id=form.medium.data, size=form_size)] if request.method == 'POST' and form.validate(): ad_position = AdPosition.add(name=form.name.data, description=form.description.data, size=AdSize.get(form.size.data), standard=form.standard.data, status=form.status.data, medium=Medium.get(form.medium.data), level=form.level.data, ad_type=form.ad_type.data, launch_strategy=form.launch_strategy.data, price=form.price.data) ad_position.units = AdUnit.gets(form.units.data) ad_position.cpd_num = sum([x.estimate_num for x in ad_position.units]) ad_position.max_order_num = sum( [x.estimate_num for x in ad_position.units]) ad_position.save() flash(u'新建展示位置成功!', 'success') return redirect( url_for("medium.position_detail", position_id=ad_position.id)) return tpl('position.html', form=form, title=u"新建展示位置")
def index(): if not g.user.is_super_admin(): abort(403) form = ClientOrderForm(request.form) mediums = [(m.id, m.name) for m in Medium.all()] if request.method == 'POST' and form.validate(): if ClientOrder.query.filter_by(contract=request.values.get('contract')).count() > 0: flash(u'合同号已存在', 'danger') return redirect(url_for('util_insert_orders.index')) order = ClientOrder.add(agent=Agent.get(form.agent.data), client=Client.get(form.client.data), campaign=form.campaign.data, money=int("%.0f" % (form.money.data or 0)), client_start=form.client_start.data, client_end=form.client_end.data, reminde_date=form.reminde_date.data, direct_sales=User.gets(form.direct_sales.data), agent_sales=User.gets(form.agent_sales.data), contract_type=form.contract_type.data, resource_type=form.resource_type.data, sale_type=form.sale_type.data, contract=request.values.get('contract', ''), creator=g.user, contract_status=2, create_time=datetime.now()) order.add_comment(g.user, u"导入了客户订单:%s - %s - %s" % ( order.agent.name, order.client.name, order.campaign )) medium_ids = request.values.getlist('medium') medium_moneys = request.values.getlist('medium_money') medium_moneys2 = request.values.getlist('medium_money2') medium_contracts = request.values.getlist('medium_contract') if medium_ids and medium_moneys and len(medium_ids) == len(medium_moneys): for x in range(len(medium_ids)): medium = Medium.get(medium_ids[x]) mo = Order.add(campaign=order.campaign, medium=medium, sale_money=int("%.0f" % (form.money.data or 0)), medium_money=int(medium_moneys[x] or 0), medium_money2=int(medium_moneys2[x] or 0), medium_contract=medium_contracts[x], medium_start=order.client_start, medium_end=order.client_end, creator=g.user) order.medium_orders = order.medium_orders + [mo] order.add_comment(g.user, u"导入了媒体订单: %s %s元" % (medium.name, mo.sale_money)) order.save() flash(u'导入客户订单成功!', 'success') insert_executive_report(order, '') return redirect(order.info_path()) else: form.client_start.data = datetime.now().date() form.client_end.data = datetime.now().date() form.reminde_date.data = datetime.now().date() return tpl('insert_order.html', form=form, mediums=mediums)
def position_detail(position_id): position = AdPosition.get(position_id) if not position: abort(404) form = PositionForm(request.form) form.units.choices = [(x.id, x.display_name) for x in position.suitable_units] if request.method == 'POST': if form.validate(): position.name = form.name.data position.description = form.description.data position.size = AdSize.get(form.size.data) position.standard = form.standard.data position.status = form.status.data position.units = AdUnit.gets(form.units.data) position.medium = Medium.get(form.medium.data) position.level = form.level.data position.ad_type = form.ad_type.data position.cpd_num = form.cpd_num.data position.max_order_num = form.max_order_num.data position.price = form.price.data position.launch_strategy = form.launch_strategy.data position.save() flash(u'保存成功!', 'success') else: flash(u'保存失败!', 'danger') return tpl('position.html', form=form, title=position.display_name, position=position) else: form.name.data = position.name form.description.data = position.description form.size.data = position.size.id form.standard.data = position.standard form.status.data = position.status form.units.data = [x.id for x in position.units] form.medium.data = position.medium.id form.level.data = position.level form.ad_type.data = position.ad_type form.cpd_num.data = position.cpd_num or 0 form.max_order_num.data = position.max_order_num form.price.data = position.price form.estimate_num.data = position.estimate_num form.launch_strategy.data = position.launch_strategy form.estimate_num.readonly = True sortby = request.args.get('sortby', '') orderby = request.args.get('orderby', '') reverse = orderby != 'asc' items = [o for o in position.order_items] schedules = AdItem.items_sort_scheduels(items, sortby, reverse) return tpl('position.html', form=form, title=position.display_name, position=position, schedules=schedules, orderby=orderby)
def info(mid): medium = Medium.get(mid) reminder_emails = [(u.name, u.email) for u in User.all_active()] return tpl('/mediums/files/info.html', medium=medium, ATTACHMENT_TYPE_MEDIUM_INTRODUCE=ATTACHMENT_TYPE_MEDIUM_INTRODUCE, ATTACHMENT_TYPE_MEDIUM_PRODUCT=ATTACHMENT_TYPE_MEDIUM_PRODUCT, ATTACHMENT_TYPE_MEDIUM_DATA=ATTACHMENT_TYPE_MEDIUM_DATA, ATTACHMENT_TYPE_MEDIUM_NEW_PRODUCT=ATTACHMENT_TYPE_MEDIUM_NEW_PRODUCT, reminder_emails=reminder_emails)
def new_invoice( order_id, redirect_epoint='saler_client_order_medium_rebate_invoice.index'): order = ClientOrder.get(order_id) if not order: abort(404) form = MediumRebateInvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] form.medium.choices = [(medium.id, medium.name) for medium in order.mediums] if request.method == 'POST' and form.validate(): medium = Medium.get(form.medium.data) # if float(form.money.data) > float(order.get_medium_rebate_money(medium) - # order.get_medium_rebate_invoice_apply_sum(medium) - # order.get_medium_rebate_invoice_pass_sum(medium)): # flash(u"新建发票失败,您申请的发票超过了媒体:%s 返点金额: %s" % (medium.name, order.get_medium_rebate_money(medium)), 'danger') # return redirect(url_for(redirect_epoint, order_id=order_id)) invoice = MediumRebateInvoice.add(client_order=order, medium=Medium.get(form.medium.data), company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, invoice_type=form.invoice_type.data, invoice_status=INVOICE_STATUS_NORMAL, creator=g.user, invoice_num=" ", back_time=form.back_time.data) invoice.save() order.add_comment(g.user, u"添加发票申请信息:%s" % (u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=6) else: for k in form.errors: flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for(redirect_epoint, order_id=order_id))
def unit_detail(unit_id): unit = AdUnit.get(unit_id) if not unit: abort(404) form = UnitForm(request.form) if request.method == 'POST': if form.validate(): unit.name = form.name.data unit.description = form.description.data unit.size = AdSize.get(form.size.data) unit.margin = form.margin.data unit.target = form.target.data unit.status = form.status.data unit.positions = AdPosition.gets(form.positions.data) unit.medium = Medium.get(form.medium.data) unit.estimate_num = form.estimate_num.data unit.save() flash(u'保存成功!', 'success') if form.medium.data: form.positions.choices = [ (x.id, x.display_name) for x in AdPosition.query.filter_by(medium_id=form.medium.data) ] return tpl('unit.html', form=form, title=unit.display_name, unit=unit) else: form.name.data = unit.name form.description.data = unit.description form.size.data = unit.size.id form.margin.data = unit.margin form.target.data = unit.target form.status.data = unit.status form.positions.data = [x.id for x in unit.positions] form.positions.choices = [ (x.id, x.display_name) for x in AdPosition.query.filter_by(medium_id=unit.medium.id) ] form.medium.data = unit.medium.id form.estimate_num.data = unit.estimate_num sortby = request.args.get('sortby', '') orderby = request.args.get('orderby', '') reverse = orderby != 'asc' items = [o for o in unit.order_items] schedules = AdItem.items_sort_scheduels(items, sortby, reverse) return tpl('unit.html', form=form, title=unit.display_name, unit=unit, schedules=schedules, orderby=orderby)
def files_upload(mid): medium = Medium.get(mid) type = int(request.values.get('type', 5)) try: request.files['file'].filename.encode('gb2312') except: flash(u'文件名中包含非正常字符,请使用标准字符', 'danger') return redirect(url_for('mediums_files.info', mid=mid)) filename = all_files_set.save(request.files['file']) medium.add_medium_files(g.user, filename, type) flash(ATTACHMENT_TYPE[type] + u' 上传成功', 'success') return redirect(url_for('mediums_files.info', mid=mid))
def validate(self): if Form.validate(self): positions = AdPosition.gets(self.positions.data) medium = Medium.get(self.medium.data) for p in positions: if p.medium != medium: self.positions.errors.append( u"%s不属于%s" % (p.display_name, medium.name)) return False return True else: return False
def validate(self): if Form.validate(self): positions = AdPosition.gets(self.positions.data) medium = Medium.get(self.medium.data) for p in positions: if p.medium != medium: self.positions.errors.append(u"%s不属于%s" % (p.display_name, medium.name)) return False return True else: return False
def new_invoice(order_id, redirect_epoint='finance_client_order_medium_rebate_invoice.info'): order = ClientOrder.get(order_id) if not order: abort(404) form = MediumRebateInvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] form.medium.choices = [(medium.id, medium.name) for medium in order.mediums] if request.method == 'POST' and form.validate(): medium = Medium.get(form.medium.data) # if float(form.money.data) > float(order.get_medium_rebate_money(medium) - # order.get_medium_rebate_invoice_apply_sum(medium) - # order.get_medium_rebate_invoice_pass_sum(medium)): # flash(u"新建发票失败,您申请的发票超过了媒体:%s 返点金额: %s" % (medium.name, order.get_medium_rebate_money(medium)), 'danger') # return redirect(url_for(redirect_epoint, order_id=order_id)) invoice = MediumRebateInvoice.add(client_order=order, medium=Medium.get(form.medium.data), company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, invoice_type=form.invoice_type.data, invoice_status=INVOICE_STATUS_PASS, creator=g.user, invoice_num=form.invoice_num.data, create_time=request.values.get( 'create_time', datetime.datetime.now().strftime('%Y-%m-%d')), back_time=form.back_time.data) invoice.save() order.add_comment(g.user, u"添加发票申请信息:%s" % ( u'发票内容: %s; 发票金额: %s元' % (invoice.detail, str(invoice.money))), msg_channel=6) else: for k in form.errors: flash(u"新建发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for(redirect_epoint, order_id=order_id))
def medium_detail(medium_id): if not (g.user.is_media_leader() or g.user.is_super_leader() or g.user.is_media() or g.user.is_finance()): abort(403) medium = Medium.get(medium_id) if not medium: abort(404) if request.method == 'POST': medium.name = request.values.get('name', '') medium.medium_group_id = int(request.values.get('medium_group_id', 100)) medium.save() flash(u'保存成功!', 'success') return tpl('/client/medium/info.html', title=u"媒体-" + medium.name, status='update', medium=medium, medium_groups=MediumGroup.all())
def update(type, cid): if not (g.user.is_planner() or g.user.is_operater()): abort(403) case = Case.get(cid) mediums_form = MediumsForm(request.form) mediums_form.mediums.data = [u.id for u in case.mediums] if request.method == 'POST': name = request.values.get('name', '') url = request.values.get('url', '') brand = request.values.get('brand', '') industry = request.values.get('industry', '') desc = request.values.get('desc', '') tags = request.values.get('tags', '').split(',') is_win = int(request.values.get('is_win', 0)) pwd = request.values.get('pwd', '') case.name = name case.url = url case.medium = Medium.get(1) case.mediums = Medium.gets(request.values.getlist('mediums')) case.brand = brand case.industry = industry case.desc = desc case.is_win = is_win case.creator = g.user case.create_time = datetime.datetime.now() case.pwd = pwd case.save() TagCase.query.filter_by(case=case).delete() for k in tags: if k: tag = Tag.query.filter_by(name=k) if tag.count() > 0: tag = tag.first() else: tag = Tag.add(name=k) tag = Tag.get(tag.id) TagCase.add(tag=tag, case=case) flash(u'修改成功', 'success') return redirect(url_for('mediums_planning.update', type=type, cid=cid)) return tpl('/mediums/planning/update.html', title=CASE_TYPE_CN[int(type)], mediums=Medium.all(), type=type, case=case, mediums_form=mediums_form, INDUSTRY=INDUSTRY)
def create(): form = NewMediumResourceForm(request.form) if request.method == 'POST' and form.validate(): if MediumResource.query.filter_by(number=form.number.data).count() > 0: flash(u'资源标号已存在', 'danger') return tpl('/mediums/resource/create.html', form=form) body = [] custom_ids = request.values.get('custom_ids', '') for x in custom_ids.split('|'): key = request.values.get('custom_key_' + str(x), '') value = request.values.get('custom_value_' + str(x), '') body.append({'c_key': key, 'c_value': value}) MediumResource.add(medium=Medium.get(form.medium.data), type=form.type.data, number=form.number.data, shape=form.shape.data, product=form.product.data, resource_type=form.resource_type.data, page_postion=form.page_postion.data, ad_position=form.ad_position.data, cpm=form.cpm.data, b_click=form.b_click.data, click_rate=form.click_rate.data, buy_unit=form.buy_unit.data, buy_threshold=form.buy_threshold.data, money=form.money.data, b_directional=form.b_directional.data, directional_type=form.directional_type.data, directional_money=form.directional_money.data, discount=form.discount.data, ad_size=form.ad_size.data, materiel_format=form.materiel_format.data, less_buy=form.less_buy.data, b_give=form.b_give.data, give_desc=form.give_desc.data, b_check_exposure=form.b_check_exposure.data, b_check_click=form.b_check_click.data, b_out_link=form.b_out_link.data, b_in_link=form.b_in_link.data, description=form.description.data, create_time=datetime.datetime.now(), update_time=datetime.datetime.now(), body=json.dumps(body)) flash(u'添加成功', 'success') return redirect(url_for('mediums_resource.index')) return tpl('/mediums/resource/create.html', form=form)
def create(type): if not (g.user.is_planner() or g.user.is_operater()): abort(403) mediums_form = MediumsForm(request.form) if request.method == 'POST': name = request.values.get('name', '') url = request.values.get('url', '') brand = request.values.get('brand', '') industry = request.values.get('industry', '') desc = request.values.get('desc', '') pwd = request.values.get('pwd', '') tags = request.values.get('tags', '').split(',') is_win = int(request.values.get('is_win', 0)) if Case.query.filter_by(name=name, type=type).count() > 0: flash(u'名称已存在', 'danger') return redirect(url_for('mediums_planning.create', type=type)) case = Case.add(name=name, url=url, medium=Medium.get(1), mediums=Medium.gets(request.values.getlist('mediums')), brand=brand, industry=industry, desc=desc, creator=g.user, type=type, is_win=is_win, pwd=pwd) case = Case.get(case.id) for k in tags: if k: tag = Tag.query.filter_by(name=k) if tag.count() > 0: tag = tag.first() else: tag = Tag.add(name=k) tag = Tag.get(tag.id) TagCase.add(tag=tag, case=case) flash(u'添加成功', 'success') return redirect(url_for('mediums_planning.index', type=type)) return tpl('/mediums/planning/create.html', title=CASE_TYPE_CN[int(type)], mediums=Medium.all(), type=type, mediums_form=mediums_form, INDUSTRY=INDUSTRY)
def medium_rebate_create(medium_id): medium = Medium.get(medium_id) if request.method == 'POST': rebate = float(request.values.get('rebate', 0)) year = request.values.get( 'year', datetime.datetime.now().strftime('%Y')) now_year = datetime.datetime.strptime(year, '%Y').date() if MediumRebate.query.filter_by(medium=medium, year=now_year).count() > 0: flash(u'该执行年返点信息已存在!', 'danger') return tpl('/client/medium/rebate/create.html', medium=medium) MediumRebate.add(medium=medium, rebate=rebate, year=now_year, creator=g.user, create_time=datetime.datetime.now()) flash(u'添加成功!', 'success') return redirect(url_for('client.medium_rebate', medium_id=medium_id)) return tpl('/client/medium/rebate/create.html', medium=medium)
def new_invoice(order_id, redirect_endpoint='saler_client_order_medium_invoice.index'): order = ClientOrder.get(order_id) if not order: abort(404) form = MediumInvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] form.medium.choices = [(order.id, order.client.name) for k in order.mediums] form.bool_invoice.choices = MEDIUM_INVOICE_BOOL_INVOICE_CN.items() # if order.mediums_money2 < order.mediums_invoice_sum + float(form.money.data): # flash(u'新建打款发票失败,发票超过媒体总金额!', 'danger') # return redirect(url_for(redirect_endpoint, order_id=order_id)) if request.method == 'POST': invoice = MediumInvoice.add( client_order=order, medium=Medium.get(form.medium.data), company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, pay_money=form.money.data, invoice_type=form.invoice_type.data, invoice_status=MEDIUM_INVOICE_STATUS_NORMAL, creator=g.user, invoice_num=form.invoice_num.data, add_time=form.add_time.data, bool_invoice=form.bool_invoice.data) invoice.save() flash(u'新建打款发票(%s)成功!' % form.company.data, 'success') order.add_comment( g.user, u"添加打款发票申请信息:%s" % (u'发票内容: %s; 发票金额: %s元; 发票号: %s' % (invoice.detail, str(invoice.money), invoice.invoice_num)), msg_channel=3) else: for k in form.errors: flash(u"新建打款发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for(redirect_endpoint, order_id=order_id))
def agent_medium_rebate_create(agent_id): agent = Agent.get(agent_id) if request.method == 'POST': rebate = float(request.values.get('rebate', 0)) year = request.values.get( 'year', datetime.datetime.now().strftime('%Y')) now_year = datetime.datetime.strptime(year, '%Y').date() medium_name = request.values.get('medium_name', '') AgentMediumRebate.add(agent=agent, medium=Medium.get(1), medium_name=medium_name, rebate=rebate, year=now_year, creator=g.user, create_time=datetime.datetime.now()) flash(u'添加成功!', 'success') agent.add_comment(g.user, u"新建了媒体返点信息: 所属媒体:%s 执行年:%s 返点信息:%s%%" % (medium_name, year, str(rebate)), msg_channel=9) return redirect(url_for('client.agent_rebate', agent_id=agent_id)) return tpl('/client/agent/rebate/medium/create.html', agent=agent, medium_groups=MediumGroup.all())
def unit_to_position(unit_id): unit = AdUnit.get(unit_id) form = PositionForm(request.form) form.estimate_num.hidden = True form.cpd_num.hidden = True form.max_order_num.hidden = True form.medium.hidden = True form.units.hidden = True if request.method == 'POST': if form.validate(): position = AdPosition.add(name=form.name.data, description=form.description.data, size=AdSize.get(form.size.data), standard=form.standard.data, status=form.status.data, medium=Medium.get(form.medium.data), level=form.level.data, ad_type=form.ad_type.data, price=form.price.data) position.units = AdUnit.gets(form.units.data) position.cpd_num = sum([x.estimate_num for x in position.units]) position.max_order_num = sum( [x.estimate_num for x in position.units]) position.save() return redirect( url_for("medium.position_detail", position_id=position.id)) else: form.name.data = unit.name form.description.data = unit.description form.medium.data = unit.medium.id form.size.data = unit.size.id form.status.data = unit.status form.units.data = [unit.id] form.size.hidden = True return tpl('position.html', form=form, title=u"创建广告单元(%s)对应的展示位置" % unit.name)
def new_unit(): form = UnitForm(request.form) if form.medium.data: form.positions.choices = [ (x.id, x.display_name) for x in AdPosition.query.filter_by(medium_id=form.medium.data) ] if request.method == 'POST' and form.validate(): adUnit = AdUnit.add(name=form.name.data, description=form.description.data, size=AdSize.get(form.size.data), margin=form.margin.data, target=form.target.data, status=form.status.data, medium=Medium.get(form.medium.data), estimate_num=form.estimate_num.data) adUnit.positions = AdPosition.gets(form.positions.data) adUnit.save() return redirect(url_for("medium.unit_to_position", unit_id=adUnit.id)) return tpl('unit.html', form=form, title=u"新建广告单元")
def new_invoice(order_id, redirect_endpoint='saler_client_order_medium_invoice.index'): order = ClientOrder.get(order_id) if not order: abort(404) form = MediumInvoiceForm(request.form) form.client_order.choices = [(order.id, order.client.name)] form.medium.choices = [(order.id, order.client.name) for k in order.mediums] form.bool_invoice.choices = MEDIUM_INVOICE_BOOL_INVOICE_CN.items() # if order.mediums_money2 < order.mediums_invoice_sum + float(form.money.data): # flash(u'新建打款发票失败,发票超过媒体总金额!', 'danger') # return redirect(url_for(redirect_endpoint, order_id=order_id)) if request.method == 'POST': invoice = MediumInvoice.add(client_order=order, medium=Medium.get(form.medium.data), company=form.company.data, tax_id=form.tax_id.data, address=form.address.data, phone=form.phone.data, bank_id=form.bank_id.data, bank=form.bank.data, detail=form.detail.data, money=form.money.data, pay_money=form.money.data, invoice_type=form.invoice_type.data, invoice_status=MEDIUM_INVOICE_STATUS_NORMAL, creator=g.user, invoice_num=form.invoice_num.data, add_time=form.add_time.data, bool_invoice=form.bool_invoice.data) invoice.save() flash(u'新建打款发票(%s)成功!' % form.company.data, 'success') order.add_comment(g.user, u"添加打款发票申请信息:%s" % ( u'发票内容: %s; 发票金额: %s元; 发票号: %s' % (invoice.detail, str(invoice.money), invoice.invoice_num)), msg_channel=3) else: for k in form.errors: flash(u"新建打款发票失败,%s" % (form.errors[k][0]), 'danger') return redirect(url_for(redirect_endpoint, order_id=order_id))
def storage(): dates_info = {} start_str = request.args.get('start_date', datetime.now().strftime(DATE_FORMAT)) start = datetime.strptime(start_str, DATE_FORMAT).date() m_dict = defaultdict(list) dates_list = [] for x in range(0, 30): current = start + timedelta(days=x) m_dict[current.month].append(current) dates_list.append(current) dates_info['dates'] = dates_list dates_info['months'] = [(m, len(d_list)) for m, d_list in m_dict.items()] medium_id = int(request.args.get('selected_medium', 0)) select_medium = [(m.id, m.name) for m in Medium.all()] select_medium.insert(0, (0, u'全部媒体')) positions_info = AdPosition.all_positions_info_by_date() if medium_id: medium = Medium.get(medium_id) positions_info = medium.positions_info_by_date() return tpl('storage.html', dates_info=dates_info, medium=select_medium, medium_id=medium_id, positions_info=positions_info, start_date=start_str, per_start_date=(start - timedelta(days=30)).strftime(DATE_FORMAT), next_start_date=(start + timedelta(days=30)).strftime(DATE_FORMAT))
def client_medium_upload(): medium_id = request.values.get('medium') medium = Medium.get(medium_id) return attachment_upload(medium, FILE_TYPE_MEDIUM)
def update(mtype, pid): if mtype == 'pc': product = MediumProductPC.get(pid) form = NewMediumProductPCForm(request.form) form.name.data = product.name form.medium.data = product.medium.id form.register_count.data = product.register_count form.alone_count_by_day.data = product.alone_count_by_day form.active_count_by_day.data = product.active_count_by_day form.alone_count_by_month.data = product.alone_count_by_month form.active_count_by_month.data = product.active_count_by_month form.pv_by_day.data = product.pv_by_day form.pv_by_month.data = product.pv_by_month form.access_time.data = product.access_time form.ugc_count.data = product.ugc_count form.cooperation_type.data = product.cooperation_type form.divide_into.data = product.divide_into form.policies.data = product.policies form.delivery.data = product.delivery form.special.data = product.special form.sex_distributed.data = product.sex_distributed form.age_distributed.data = product.age_distributed form.area_distributed.data = product.area_distributed form.education_distributed.data = product.education_distributed form.income_distributed.data = product.income_distributed form.product_position.data = product.product_position elif mtype == 'app': product = MediumProductApp.get(pid) form = NewMediumProductAppForm(request.form) form.medium.data = product.medium.id form.name.data = product.name form.install_count.data = product.install_count form.activation_count.data = product.activation_count form.register_count.data = product.register_count form.active_count_by_day.data = product.active_count_by_day form.active_count_by_month.data = product.active_count_by_month form.pv_by_day.data = product.pv_by_day form.pv_by_month.data = product.pv_by_month form.open_rate_by_day.data = product.open_rate_by_day form.access_time.data = product.access_time form.ugc_count.data = product.ugc_count form.cooperation_type.data = product.cooperation_type form.divide_into.data = product.divide_into form.policies.data = product.policies form.delivery.data = product.delivery form.special.data = product.special form.sex_distributed.data = product.sex_distributed form.age_distributed.data = product.age_distributed form.area_distributed.data = product.area_distributed form.education_distributed.data = product.education_distributed form.income_distributed.data = product.income_distributed form.product_position.data = product.product_position elif mtype == 'down': product = MediumProductDown.get(pid) form = NewMediumProductDownForm(request.form) form.medium.data = product.medium.id form.name.data = product.name form.medium.data = product.medium.id form.name.data = product.name form.location.data = product.location form.subject.data = product.subject form.before_year_count.data = product.before_year_count form.now_year_count.data = product.now_year_count form.cooperation_type.data = product.cooperation_type form.divide_into.data = product.divide_into form.policies.data = product.policies form.delivery.data = product.delivery form.special.data = product.special form.sex_distributed.data = product.sex_distributed form.age_distributed.data = product.age_distributed form.area_distributed.data = product.area_distributed form.education_distributed.data = product.education_distributed form.income_distributed.data = product.income_distributed form.product_position.data = product.product_position product.c_body = json.loads(product.body) if request.method == 'POST' and form.validate(): body = [] custom_ids = request.values.get('custom_ids', '') for x in custom_ids.split('|'): key = request.values.get('custom_key_' + str(x), '') value = request.values.get('custom_value_' + str(x), '') body.append({'c_key': key, 'c_value': value}) if mtype == 'pc': form = NewMediumProductPCForm(request.form) if product.name != form.name.data and MediumProductPC.query.filter_by( name=form.name.data).count() > 0: flash(u'产品名称已存在', 'danger') return tpl('/mediums/product/update.html', form=form, mtype=mtype) product.name = form.name.data product.medium = Medium.get(form.medium.data) product.register_count = form.register_count.data product.alone_count_by_day = form.alone_count_by_day.data product.active_count_by_day = form.active_count_by_day.data product.alone_count_by_month = form.alone_count_by_month.data product.active_count_by_month = form.active_count_by_month.data product.pv_by_day = form.pv_by_day.data product.pv_by_month = form.pv_by_month.data product.access_time = form.access_time.data product.ugc_count = form.ugc_count.data product.cooperation_type = form.cooperation_type.data product.divide_into = form.divide_into.data product.policies = form.policies.data product.delivery = form.delivery.data product.special = form.special.data product.sex_distributed = form.sex_distributed.data product.age_distributed = form.age_distributed.data product.area_distributed = form.area_distributed.data product.education_distributed = form.education_distributed.data product.income_distributed = form.income_distributed.data product.product_position = form.product_position.data product.body = json.dumps(body) product.save() elif mtype == 'app': form = NewMediumProductAppForm(request.form) if product.name != form.name.data and MediumProductApp.query.filter_by( name=form.name.data).count() > 0: flash(u'产品名称已存在', 'danger') return tpl('/mediums/product/update.html', form=form, mtype=mtype) product.medium = Medium.get(form.medium.data) product.name = form.name.data product.create_time = datetime.datetime.now() product.update_time = datetime.datetime.now() product.install_count = form.install_count.data product.activation_count = form.activation_count.data product.register_count = form.register_count.data product.active_count_by_day = form.active_count_by_day.data product.active_count_by_month = form.active_count_by_month.data product.pv_by_day = form.pv_by_day.data product.pv_by_month = form.pv_by_month.data product.open_rate_by_day = form.open_rate_by_day.data product.access_time = form.access_time.data product.ugc_count = form.ugc_count.data product.cooperation_type = form.cooperation_type.data product.divide_into = form.divide_into.data product.policies = form.policies.data product.delivery = form.delivery.data product.special = form.special.data product.sex_distributed = form.sex_distributed.data product.age_distributed = form.age_distributed.data product.area_distributed = form.area_distributed.data product.education_distributed = form.education_distributed.data product.income_distributed = form.income_distributed.data product.product_position = form.product_position.data product.body = json.dumps(body) product.save() elif mtype == 'down': form = NewMediumProductDownForm(request.form) if product.name != form.name.data and MediumProductDown.query.filter_by( name=form.name.data).count() > 0: flash(u'产品名称已存在', 'danger') return tpl('/mediums/product/update.html', form=form, mtype=mtype) product.medium = Medium.get(form.medium.data) product.name = form.name.data product.update_time = datetime.datetime.now() product.start_time = request.values.get('start_time', '') product.end_time = request.values.get('end_time', '') product.business_start_time = request.values.get( 'business_start_time', '') product.business_end_time = request.values.get( 'business_end_time', '') product.location = form.location.data product.subject = form.subject.data product.before_year_count = form.before_year_count.data product.now_year_count = form.now_year_count.data product.cooperation_type = form.cooperation_type.data product.divide_into = form.divide_into.data product.policies = form.policies.data product.delivery = form.delivery.data product.special = form.special.data product.sex_distributed = form.sex_distributed.data product.age_distributed = form.age_distributed.data product.area_distributed = form.area_distributed.data product.education_distributed = form.education_distributed.data product.income_distributed = form.income_distributed.data product.product_position = form.product_position.data product.body = json.dumps(body) product.save() flash(u'修改成功', 'success') return redirect( url_for('mediums_product.update', mtype=mtype, pid=product.id)) return tpl('/mediums/product/update.html', form=form, mtype=mtype, product=product)
def create(mtype): if mtype == 'pc': form = NewMediumProductPCForm(request.form) elif mtype == 'app': form = NewMediumProductAppForm(request.form) elif mtype == 'down': form = NewMediumProductDownForm(request.form) if request.method == 'POST' and form.validate(): body = [] custom_ids = request.values.get('custom_ids', '') for x in custom_ids.split('|'): key = request.values.get('custom_key_' + str(x), '') value = request.values.get('custom_value_' + str(x), '') body.append({'c_key': key, 'c_value': value}) if mtype == 'pc': if MediumProductPC.query.filter_by( name=form.name.data).count() > 0: flash(u'产品名称已存在', 'danger') return tpl('/mediums/product/create.html', form=form, mtype=mtype) MediumProductPC.add( medium=Medium.get(form.medium.data), name=form.name.data, create_time=datetime.datetime.now(), update_time=datetime.datetime.now(), register_count=form.register_count.data, alone_count_by_day=form.alone_count_by_day.data, active_count_by_day=form.active_count_by_day.data, alone_count_by_month=form.alone_count_by_month.data, active_count_by_month=form.active_count_by_month.data, pv_by_day=form.pv_by_day.data, pv_by_month=form.pv_by_month.data, access_time=form.access_time.data, ugc_count=form.ugc_count.data, cooperation_type=form.cooperation_type.data, divide_into=form.divide_into.data, policies=form.policies.data, delivery=form.delivery.data, special=form.special.data, sex_distributed=form.sex_distributed.data, age_distributed=form.age_distributed.data, area_distributed=form.area_distributed.data, education_distributed=form.education_distributed.data, income_distributed=form.income_distributed.data, product_position=form.product_position.data, body=json.dumps(body)) elif mtype == 'app': if MediumProductApp.query.filter_by( name=form.name.data).count() > 0: flash(u'产品名称已存在', 'danger') return tpl('/mediums/product/create.html', form=form, mtype=mtype) MediumProductApp.add( medium=Medium.get(form.medium.data), name=form.name.data, create_time=datetime.datetime.now(), update_time=datetime.datetime.now(), install_count=form.install_count.data, activation_count=form.activation_count.data, register_count=form.register_count.data, active_count_by_day=form.active_count_by_day.data, active_count_by_month=form.active_count_by_month.data, pv_by_day=form.pv_by_day.data, pv_by_month=form.pv_by_month.data, open_rate_by_day=form.open_rate_by_day.data, access_time=form.access_time.data, ugc_count=form.ugc_count.data, cooperation_type=form.cooperation_type.data, divide_into=form.divide_into.data, policies=form.policies.data, delivery=form.delivery.data, special=form.special.data, sex_distributed=form.sex_distributed.data, age_distributed=form.age_distributed.data, area_distributed=form.area_distributed.data, education_distributed=form.education_distributed.data, income_distributed=form.income_distributed.data, product_position=form.product_position.data, body=json.dumps(body)) elif mtype == 'down': if MediumProductDown.query.filter_by( name=form.name.data).count() > 0: flash(u'产品名称已存在', 'danger') return tpl('/mediums/product/create.html', form=form, mtype=mtype) MediumProductDown.add( medium=Medium.get(form.medium.data), name=form.name.data, create_time=datetime.datetime.now(), update_time=datetime.datetime.now(), start_time=request.values.get('start_time', ''), end_time=request.values.get('end_time', ''), business_start_time=request.values.get('business_start_time', ''), business_end_time=request.values.get('business_end_time', ''), location=form.location.data, subject=form.subject.data, before_year_count=form.before_year_count.data, now_year_count=form.now_year_count.data, cooperation_type=form.cooperation_type.data, divide_into=form.divide_into.data, policies=form.policies.data, delivery=form.delivery.data, special=form.special.data, sex_distributed=form.sex_distributed.data, age_distributed=form.age_distributed.data, area_distributed=form.area_distributed.data, education_distributed=form.education_distributed.data, income_distributed=form.income_distributed.data, product_position=form.product_position.data, body=json.dumps(body)) flash(u'添加成功', 'success') return redirect(url_for('mediums_product.index', mtype=mtype)) return tpl('/mediums/product/create.html', form=form, mtype=mtype)
def info_last(mid, type): medium = Medium.get(mid) reminder_emails = [(u.name, u.email) for u in User.all_active()] return tpl('/mediums/files/info_last.html', medium=medium, type=int(type), title=ATTACHMENT_TYPE[int(type)], reminder_emails=reminder_emails)
def tax_info(medium_id): medium = Medium.get(medium_id) return jsonify(medium.tax_info)
def update(pid): resource = MediumResource.get(pid) form = NewMediumResourceForm(request.form) form.medium.data = resource.medium.id form.type.data = resource.type form.number.data = resource.number form.shape.data = resource.shape form.product.data = resource.product form.resource_type.data = resource.resource_type form.page_postion.data = resource.page_postion form.ad_position.data = resource.ad_position form.cpm.data = resource.cpm form.b_click.data = resource.b_click form.click_rate.data = resource.click_rate form.buy_unit.data = resource.buy_unit form.buy_threshold.data = resource.buy_threshold form.money.data = resource.money form.b_directional.data = resource.b_directional form.directional_type.data = resource.directional_type form.directional_money.data = resource.directional_money form.discount.data = resource.discount form.ad_size.data = resource.ad_size form.materiel_format.data = resource.materiel_format form.less_buy.data = resource.less_buy form.b_give.data = resource.b_give form.give_desc.data = resource.give_desc form.b_check_exposure.data = resource.b_check_exposure form.b_check_click.data = resource.b_check_click form.b_out_link.data = resource.b_out_link form.b_in_link.data = resource.b_in_link form.description.data = resource.description resource.c_body = json.loads(resource.body) if request.method == 'POST' and form.validate(): body = [] custom_ids = request.values.get('custom_ids', '') for x in custom_ids.split('|'): key = request.values.get('custom_key_' + str(x), '') value = request.values.get('custom_value_' + str(x), '') body.append({'c_key': key, 'c_value': value}) form = NewMediumResourceForm(request.form) if resource.number != form.number.data and MediumResource.query.filter_by(number=form.number.data).count() > 0: flash(u'资源编号已存在', 'danger') return tpl('/mediums/resource/update.html', form=form, resource=resource) resource.medium = Medium.get(form.medium.data) resource.type = form.type.data resource.number = form.number.data resource.shape = form.shape.data resource.product = form.product.data resource.resource_type = form.resource_type.data resource.page_postion = form.page_postion.data resource.ad_position = form.ad_position.data resource.cpm = form.cpm.data resource.b_click = form.b_click.data resource.click_rate = form.click_rate.data resource.buy_unit = form.buy_unit.data resource.buy_threshold = form.buy_threshold.data resource.money = form.money.data resource.b_directional = form.b_directional.data resource.directional_type = form.directional_type.data resource.directional_money = form.directional_money.data resource.discount = form.discount.data resource.ad_size = form.ad_size.data resource.materiel_format = form.materiel_format.data resource.less_buy = form.less_buy.data resource.b_give = form.b_give.data resource.give_desc = form.give_desc.data resource.b_check_exposure = form.b_check_exposure.data resource.b_check_click = form.b_check_click.data resource.b_out_link = form.b_out_link.data resource.b_in_link = form.b_in_link.data resource.description = form.description.data resource.body = json.dumps(body) resource.update_time = datetime.datetime.now() resource.save() flash(u'修改成功', 'success') return redirect(url_for('mediums_resource.update', pid=resource.id)) return tpl('/mediums/resource/update.html', resource=resource, form=form)
def test_medium(session): medium = add_medium('testmedium') medium2 = Medium.get(medium.id) assert medium2.name == 'testmedium'
def medium_rebate(medium_id): medium = Medium.get(medium_id) rebates = MediumRebate.query.filter_by(medium=medium) return tpl('/client/medium/rebate/index.html', medium=medium, rebates=rebates)
def medium_info(mid): medium = Medium.get(mid) if not medium: return jsonify({'data': {}}) return jsonify({'data': _medium_to_dict(medium)})