def delete(mtype, pid): if mtype == 'pc': MediumProductPC.get(pid).delete() elif mtype == 'app': MediumProductApp.get(pid).delete() elif mtype == 'down': MediumProductDown.get(pid).delete() return jsonify({'id': pid})
def index(): page = int(request.values.get('p', 1)) medium_id = int(request.values.get('medium_id', 0)) product_id = int(request.values.get('product_id', 0)) type = int(request.values.get('type', 0)) number = request.values.get('number', '') filters = {} if medium_id: filters['medium_id'] = medium_id if product_id: filters['product'] = product_id if type: filters['type'] = type if filters: resources = MediumResource.query.filter_by(**filters) else: resources = MediumResource.all() if number: resources = resources.filter( MediumResource.number.startswith(number.strip())) paginator = Paginator(list(resources), 50) try: resources = paginator.page(page) except: resources = paginator.page(paginator.num_pages) for k in resources.object_list: if k.type == 1: k.product_obj = MediumProductPC.get(k.product) elif k.type == 2: k.product_obj = MediumProductApp.get(k.product) elif k.type == 3: k.product_obj = MediumProductDown.get(k.product) return tpl('/mediums/resource/index.html', resources=resources, mediums=Medium.all(), type=type, product_id=product_id, number=number, medium_id=medium_id, params="&medium_id=%s&number=%s&type=%s&product_id=%s" % (medium_id, number, type, product_id))
def info(mtype, pid): if mtype == 'pc': product = MediumProductPC.get(pid) elif mtype == 'app': product = MediumProductApp.get(pid) elif mtype == 'down': product = MediumProductDown.get(pid) product.c_body = json.loads(product.body) return tpl('/mediums/product/info.html', mtype=mtype, product=product)
def info(pid): resource = MediumResource.get(pid) resource.c_body = json.loads(resource.body) if resource.type == 1: resource.product_obj = MediumProductPC.get(resource.product) elif resource.type == 2: resource.product_obj = MediumProductApp.get(resource.product) elif resource.type == 3: resource.product_obj = MediumProductDown.get(resource.product) return tpl('/mediums/resource/info.html', resource=resource)
def __init__(self, *args, **kwargs): super(NewMediumResourceForm, self).__init__(*args, **kwargs) self.medium.choices = [(k.id, k.name) for k in Medium.all()] self.type.choices = [(1, u'PC端'), (2, u'移动端'), (3, u'线下活动')] self.shape.choices = [(1, u'互联网')] self.product.choices = [(k.id, k.name) for k in list(MediumProductPC.all( )) + list(MediumProductApp.all()) + list(MediumProductDown.all())] self.resource_type.choices = [ (1, u'硬广'), (2, u'互动'), (3, u'特殊'), (4, u'其他')] self.b_click.choices = [(0, u'否'), (1, u'是')] self.buy_unit.choices = [ (0, u'无'), (1, u'CPM'), (2, u'千份(周)'), (3, u'期'), (4, u'千份'), (5, u'天')] self.b_directional.choices = [(0, u'否'), (1, u'是')] self.directional_type.choices = [ (0, u'无'), (1, u'地域'), (2, u'话题'), (3, u'地域、话题'), (10, u'其他')] self.less_buy.choices = [(0, u'无限制'), (1, u'不低于1000CPM')] self.b_give.choices = [(0, u'否'), (1, u'是')] self.b_check_exposure.choices = [(0, u'否'), (1, u'是')] self.b_check_click.choices = [(0, u'否'), (1, u'是')] self.b_out_link.choices = [(0, u'否'), (1, u'是')] self.b_in_link.choices = [(0, u'否'), (1, u'是')]
def __init__(self, *args, **kwargs): super(NewMediumResourceForm, self).__init__(*args, **kwargs) self.medium.choices = [(k.id, k.name) for k in Medium.all()] self.type.choices = [(1, u'PC端'), (2, u'移动端'), (3, u'线下活动')] self.shape.choices = [(1, u'互联网')] self.product.choices = [ (k.id, k.name) for k in list(MediumProductPC.all()) + list(MediumProductApp.all()) + list(MediumProductDown.all()) ] self.resource_type.choices = [(1, u'硬广'), (2, u'互动'), (3, u'特殊'), (4, u'其他')] self.b_click.choices = [(0, u'否'), (1, u'是')] self.buy_unit.choices = [(0, u'无'), (1, u'CPM'), (2, u'千份(周)'), (3, u'期'), (4, u'千份'), (5, u'天')] self.b_directional.choices = [(0, u'否'), (1, u'是')] self.directional_type.choices = [(0, u'无'), (1, u'地域'), (2, u'话题'), (3, u'地域、话题'), (10, u'其他')] self.less_buy.choices = [(0, u'无限制'), (1, u'不低于1000CPM')] self.b_give.choices = [(0, u'否'), (1, u'是')] self.b_check_exposure.choices = [(0, u'否'), (1, u'是')] self.b_check_click.choices = [(0, u'否'), (1, u'是')] self.b_out_link.choices = [(0, u'否'), (1, u'是')] self.b_in_link.choices = [(0, u'否'), (1, u'是')]
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 index(mtype): page = int(request.values.get('p', 1)) medium_id = int(request.values.get('medium_id', 0)) reg_count = request.values.get('reg_count', '') or 0 active_count = request.values.get('active_count', '') or 0 pv_count = request.values.get('pv_count', '') or 0 time_count = request.values.get('time_count', '') or 0 location = request.values.get('location', '') now_year_count = request.values.get('now_year_count', '') or 0 filters = {} if medium_id: filters['medium_id'] = medium_id if mtype == 'pc': if filters: products = MediumProductPC.query.filter_by(**filters) else: products = MediumProductPC.all() if reg_count: products = products.filter( MediumProductPC.register_count >= int(reg_count)) if active_count: products = products.filter( MediumProductPC.active_count_by_day >= int(active_count)) if pv_count: products = products.filter( MediumProductPC.pv_by_day >= int(pv_count)) if time_count: products = products.filter( MediumProductPC.access_time >= int(time_count)) elif mtype == 'app': if filters: products = MediumProductApp.query.filter_by(**filters) else: products = MediumProductApp.all() if reg_count: products = products.filter( MediumProductApp.register_count >= int(reg_count)) if active_count: products = products.filter( MediumProductApp.active_count_by_day >= int(active_count)) if pv_count: products = products.filter( MediumProductApp.pv_by_day >= int(pv_count)) if time_count: products = products.filter( MediumProductApp.access_time >= int(time_count)) elif mtype == 'down': if location: filters['location'] = location if filters: products = MediumProductDown.query.filter_by(**filters) else: products = MediumProductDown.all() if now_year_count: products = products.filter( MediumProductDown.now_year_count >= int(now_year_count)) paginator = Paginator(list(products), 50) try: products = paginator.page(page) except: products = paginator.page(paginator.num_pages) mediums = Medium.all() params = "&medium_id=%s" % (str(medium_id)) if mtype in ['pc', 'app']: params += "®_count=%s&active_count=%s&pv_count=%s&time_count=%s" % ( reg_count or '', active_count or '', pv_count or '', time_count or '') else: params += "&location=%s&now_year_count=%s" % (location, now_year_count or '') return tpl('/mediums/product/index.html', mtype=mtype, products=products, mediums=mediums, medium_id=medium_id, params=params, reg_count=reg_count or '', active_count=active_count or '', pv_count=pv_count or '', time_count=time_count or '', location=location, now_year_count=now_year_count or '', MEDIUM_RESOURCE_TYPE_INT=MEDIUM_RESOURCE_TYPE_INT)
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)