def new_team(): form = NewTeamForm(request.form) if request.method == 'POST' and form.validate(): db_team_name = Team.name_exist(form.name.data) if not db_team_name: team = Team.add(name=form.name.data, type=form.type.data, location=form.location.data, admins=User.gets(form.admins.data)) flash(u'新建团队(%s)成功!' % team.name, 'success') else: flash(u'新建团队(%s)失败,团队名称已经存在!' % form.name.data, 'danger') return tpl('new_team.html', form=form) if request.values.get('next'): return redirect(request.values.get('next')) return redirect(url_for("user.team_detail", team_id=team.id)) return tpl('new_team.html', form=form)
def user_detail(user_id): user = User.get(user_id) if not user: abort(404) form = NewUserForm(request.form) if request.method == 'POST': c_user = User.get_by_email(email=form.email.data.lower()) if c_user and form.email.data.lower() != user.email: flash(u'保存保存失败,该邮箱已存在!', 'danger') return redirect(url_for('user.user_detail', user_id=user_id)) if form.validate(vali_email=False): if g.user.team.is_admin() or g.user.is_HR() or g.user.is_HR_leader(): # 只有管理员才有权限修改 username email team status user.name = form.name.data user.email = form.email.data user.team = Team.get(form.team.data) user.status = form.status.data user.team_leaders = User.gets(form.team_leaders.data) user.birthday = form.birthday.data user.recruited_date = form.recruited_date.data user.positive_date = form.positive_date.data user.quit_date = form.quit_date.data user.cellphone = form.cellphone.data user.position = form.position.data user.sn = form.sn.data elif g.user.id == user.id: user.birthday = form.birthday.data user.recruited_date = form.recruited_date.data user.cellphone = form.cellphone.data user.position = form.position.data user.save() flash(u'保存成功!', 'success') return redirect(url_for('user.user_detail', user_id=user_id)) else: form.name.data = user.name form.email.data = user.email form.team.data = user.team_id form.status.data = user.status form.cellphone.data = user.cellphone form.position.data = user.position form.team_leaders.data = [u.id for u in user.team_leaders] form.birthday.data = user.birthday or DEFAULT_BIRTHDAY form.recruited_date.data = user.recruited_date or DEFAULT_RECRUITED_DATE form.positive_date.data = user.positive_date or DEFAULT_RECRUITED_DATE form.quit_date.data = user.quit_date or DEFAULT_RECRUITED_DATE form.sn.data = user.sn or '' if not (g.user.team.is_admin() or g.user.is_HR() or g.user.is_HR_leader()): form.name.readonly = True form.email.readonly = True form.team.readonly = True form.status.readonly = True form.sn.readonly = True form.status.choices = [(user.status, USER_STATUS_CN[user.status])] form.team_leaders.disabled = True form.team.choices = [(user.team_id, user.team.name)] form.team_leaders.choices = [(u.id, u.name) for u in user.team_leaders] return tpl('user_detail.html', user=user, form=form, DEFAULT_PASSWORD=DEFAULT_PASSWORD)
def __init__(self, medium_group, name, owner=1, level=100, abbreviation=None, tax_num="", address="", phone_num="", bank="", bank_num=""): self.medium_group = medium_group self.name = name self.owner = Team.get(owner) self.level = level self.abbreviation = abbreviation or "" self.tax_num = tax_num self.address = address self.phone_num = phone_num self.bank = bank self.bank_num = bank_num
def medium_detail(medium_id): medium = searchAdMedium.get(medium_id) if not medium: abort(404) if request.method == 'POST': medium.name = request.values.get('name', '') medium.owner = Team.get(1) medium.abbreviation = request.values.get('abbreviation', '') medium.tax_num = request.values.get('tax_num', '') medium.address = request.values.get('address', '') medium.phone_num = request.values.get('phone_num', '') medium.bank = request.values.get('bank', '') medium.bank_num = request.values.get('bank_num', '') medium.save() flash(u'保存成功!', 'success') return tpl('/searchAdclient/medium/searchAd_info.html', title=u"媒体-" + medium.name, medium=medium, status="update", FILE_TYPE_CN=FILE_TYPE_CN)
def team_detail(team_id): team = Team.get(team_id) if not team: abort(404) form = NewTeamForm(request.form) if request.method == 'POST': if form.validate(): team.name = form.name.data team.type = form.type.data team.location = form.location.data team.admins = User.gets(form.admins.data) team.save() flash(u'保存成功!', 'success') else: form.name.data = team.name form.type.data = team.type form.location.data = team.location form.admins.data = [u.id for u in team.admins] return tpl('team_detail.html', team=team, form=form)
def new_medium(): if request.method == 'POST': db_medium_name = searchAdMedium.name_exist(request.values.get('name', '')) if not db_medium_name: medium = searchAdMedium.add( name=request.values.get('name', ''), owner=Team.get(1), abbreviation=request.values.get('abbreviation', ''), tax_num=request.values.get('tax_num', ''), address=request.values.get('address', ''), phone_num=request.values.get('phone_num', ''), bank=request.values.get('bank', ''), bank_num=request.values.get('bank_num', '')) medium.save() flash(u'新建媒体(%s)成功!' % medium.name, 'success') else: flash(u'新建媒体(%s)失败, 名称已经被占用!' % request.values.get('name', ''), 'danger') return tpl('/searchAdclient/medium/searchAd_info.html', title=u"新建媒体") return redirect(url_for("searchAd_client.medium_detail", medium_id=medium.id)) return tpl('/searchAdclient/medium/searchAd_info.html', title=u"新建媒体", medium=None)
def new_user(): form = NewUserForm(request.form) if request.method == 'POST': if form.validate(): db_user_name = User.name_exist(form.name.data) if not db_user_name: user = User.add(form.name.data, form.email.data, DEFAULT_PASSWORD, Team.get(form.team.data), form.status.data, team_leaders=User.gets(form.team_leaders.data), birthday=form.birthday.data, recruited_date=form.recruited_date.data, positive_date=form.positive_date.data, quit_date=form.quit_date.data, cellphone=form.cellphone.data, position=form.position.data, sn=form.sn.data) flash(u'新建用户(%s)成功!' % user.name, 'success') else: flash(u'新建用户(%s)失败,用户名已经存在!' % form.name.data, 'danger') return tpl('new_user.html', form=form) return redirect(url_for("user.users")) return tpl('new_user.html', form=form)
import os import sys sys.path.insert(0, os.path.abspath('.')) from app import app from libs.db import db db.create_all() from models.user import (User, Team, TEAM_TYPE_SUPER_ADMIN, TEAM_TYPE_MEDIUM, TEAM_TYPE_LEADER, TEAM_TYPE_DIRECT_SELLER) from models.medium import Medium, MediumGroup from models.client import Client, Agent, Group from models.order import Order from config import DEFAULT_PASSWORD admin_team = Team.add(u'管理员', type=TEAM_TYPE_SUPER_ADMIN) medium_team = Team.add(u'媒体', type=TEAM_TYPE_MEDIUM) leader_team = Team.add('ledaer', type=TEAM_TYPE_LEADER) sale_team = Team.add('ledaer', type=TEAM_TYPE_DIRECT_SELLER) user = User.add(name="admin", email="*****@*****.**", password=DEFAULT_PASSWORD, team=admin_team) leader = User.add(name="leader", email="*****@*****.**", password=DEFAULT_PASSWORD, team=leader_team) saler = User.add(name="saler", email="*****@*****.**", password=DEFAULT_PASSWORD, team=sale_team) medium_group = MediumGroup.add(name='测试媒体供应商', tax_num="", address="", phone_num="", bank="", bank_num="", level=100) medium = Medium.add(medium_group, u"测试媒体", owner=medium_team) client = Client.add(u"测试客户", 0)
def when_create_team(session): Team.add(name='OneTeam')
def add_team(name): team = Team.add(name) return team
def _into_order(param): group = Group.query.filter_by(name=u'默认集团').first() if not group: group = Group.add(name=u'默认集团') group.save() agent = Agent.query.filter_by(name=param['agent_name']).first() if not agent: agent = Agent.add( name=param['agent_name'], group=group, tax_num='', address='', phone_num='', bank='', bank_num='', ) client = Client.query.filter_by(name=param['client_name']).first() if not client: client = Client.add(name=param['client_name'], industry=1) # client.save() medium = Medium.query.filter_by(name=param['medium_name']).first() if not medium: medium = Medium.add(name=param['medium_name'], abbreviation=param['medium_name'], tax_num='', address='', phone_num='', bank='', bank_num='', owner=Team.query.filter_by(type=8).first()) team_huabei = Team.query.filter_by(name=u'导入渠道销售团队华北').first() if not team_huabei: team_huabei = Team.add( name=u'导入渠道销售团队华北', type=4, location=1, admins=[], ) team_huanan = Team.query.filter_by(name=u'导入渠道销售团队华南').first() if not team_huanan: team_huanan = Team.add( name=u'导入渠道销售团队华南', type=4, location=3, admins=[], ) team_huadong = Team.query.filter_by(name=u'导入渠道销售团队华东').first() if not team_huadong: team_huadong = Team.add( name=u'导入渠道销售团队华东', type=4, location=2, admins=[], ) team_qita = Team.query.filter_by(name=u'导入渠道销售团队其他').first() if not team_qita: team_qita = Team.add( name=u'导入渠道销售团队其他', type=4, location=0, admins=[], ) if not param['agent_sale_name']: agents = [] else: agent_names = param['agent_sale_name'].split(' ') agents = [] if param['location'] == u'华北': team = team_huabei elif param['location'] == u'华东': team = team_huadong elif param['location'] == u'华南': team = team_huanan else: team = team_qita for k in agent_names: name = k.strip() p_name = p.get_pinyin(name, '').lower() email = p_name + '@inad.com' user = User.query.filter_by(email=email).first() if not user: user = User.add(name, email, 'pwd@inad', team, 1) agents.append(user.id) if param['contract_type'].find(u'非标') >= 0: contract_type = 1 else: contract_type = 0 if param['resource_type'].find(u'硬广') >= 0: resource_type = 0 elif param['resource_type'].find(u'互动') >= 0: resource_type = 1 else: resource_type = 4 if param['sale_type'] == u'代理': sale_type = 0 else: sale_type = 1 if ClientOrder.query.filter_by(agent=agent, client=client, campaign=param['campaign'], status=1).first(): return order = ClientOrder.add( agent=agent, client=client, campaign=param['campaign'], money=param['money'], client_start=param['medium_start'], client_end=param['medium_end'], reminde_date=param['reminde_date'], direct_sales=[], agent_sales=User.gets(agents), contract_type=contract_type, resource_type=resource_type, sale_type=sale_type, creator=g.user, create_time=datetime.datetime.now(), ) order.add_comment( g.user, u"新建了客户订单:%s - %s - %s" % (order.agent.name, order.client.name, order.campaign)) mo = Order.add(campaign=order.campaign, medium=medium, sale_money=param['money'], medium_money=param['medium_money'], medium_money2=param['medium_money2'], medium_start=param['medium_start'], medium_end=param['medium_end'], creator=g.user) order.add_comment(g.user, u"新建了媒体订单: %s %s元" % (medium.name, mo.sale_money)) order.medium_orders = [mo] order.save() return
def __init__(self, *args, **kwargs): super(NewUserForm, self).__init__(*args, **kwargs) self.status.choices = USER_STATUS_CN.items() self.team.choices = [(t.id, t.name) for t in Team.all()] self.team_leaders.choices = [(m.id, m.name) for m in User.all()]
def __init__(self, *args, **kwargs): super(NewMediumForm, self).__init__(*args, **kwargs) self.owner.choices = [(t.id, t.name) for t in Team.all() if t.is_medium()] self.level.choices = LEVEL_CN.items()
def __init__(self, *args, **kwargs): super(NewMediumForm, self).__init__(*args, **kwargs) self.owner.choices = [(t.id, t.name) for t in Team.all() if t.is_medium()]
import os import sys sys.path.insert(0, os.path.abspath('.')) from app import app from libs.db import db db.create_all() from models.user import (User, Team, TEAM_TYPE_SUPER_ADMIN, TEAM_TYPE_MEDIUM, TEAM_TYPE_LEADER, TEAM_TYPE_DIRECT_SELLER) from models.medium import Medium, MediumGroup from models.client import Client, Agent, Group from models.order import Order from config import DEFAULT_PASSWORD admin_team = Team.add(u'管理员', type=TEAM_TYPE_SUPER_ADMIN) medium_team = Team.add(u'媒体', type=TEAM_TYPE_MEDIUM) leader_team = Team.add('ledaer', type=TEAM_TYPE_LEADER) sale_team = Team.add('ledaer', type=TEAM_TYPE_DIRECT_SELLER) user = User.add(name="admin", email="*****@*****.**", password=DEFAULT_PASSWORD, team=admin_team) leader = User.add(name="leader", email="*****@*****.**", password=DEFAULT_PASSWORD, team=leader_team) saler = User.add(name="saler", email="*****@*****.**", password=DEFAULT_PASSWORD,
def teams(): teams = Team.all() return tpl('teams.html', teams=teams)