def test_add_and_get_users(self): bid0 = Board.add("board0", "A") board0 = Board.get(bid0) uid0 = User.add("test1", "password", "*****@*****.**") user0 = User.get(uid0) uid1 = User.add("test2", "password", "*****@*****.**") user1 = User.get(uid0) board0.add_user(user0) assert str(uid0) in board0.get_user_ids() assert str(uid1) not in board0.get_user_ids()
def sync_users(): user_info = api.get_users() for openid in user_info.data['openid']: info = api.get_user_info(openid) info['openid'] = openid info['subscribe_time'] = datetime.fromtimestamp(info.subscribe_time) user = User.get_by_openid(openid) if user: User.update(**info) else: User.add(**info) return jsonify(r=True)
def post(self): args = user_post_parser.parse_args() password = args['password'] user = User(name=args['name'], username=args['username']) user.set_password(password) try: user.add() except IntegrityError: return max_res('', code=401, errmsg='用户已存在') return max_res(marshal(user, user_fields))
def test_get_user_ids(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") lid0 = List.add("To Do", bid0) card_id = Card.add("card0", lid0, uid0) card = Card.get(card_id) assert str(uid0) in [user_id for user_id in card.get_user_ids()]
def test_get_cards_by_list_id(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") lid0 = List.add("To Do", bid0) card_id = Card.add("card0", lid0, uid0) card = Card.get(card_id) assert card_id in [card.id for card in Card.get_cards_by_list_id(lid0)]
def test_add_and_get_cards(self): uid0 = User.add("test_user1", "password", "*****@*****.**") user0 = User.get(uid0) uid1 = User.add("test_user2", "password", "*****@*****.**") user1 = User.get(uid1) bid0 = Board.add("board1", "A") lid0 = List.add("List0", bid0) caid0 = Card.add("card1", lid0, uid0) caid1 = Card.add("card2", lid0, uid1) card0 = Card.get(caid0) print caid0, user0.get_card_ids() assert str(caid0) in user0.get_card_ids() assert str(caid1) not in user0.get_card_ids()
def login666(): user = User.get('666') if user is None: user = User.add('666') login_user(user) session['openid'] = '666' return redirect('/gaga')
def registration(form): username = str(form.username.data) # Захэшируем наши пароли. Обязательно в конфиге должен быть заполнен "SECRET_KEY" password = str(form.password.data) email = str(form.email.data) phone = str(form.phone.data) user = User(username, password, email, phone) try: user.add(g) session['logged_in'] = True except Exception as e: flash("Ошибка при регистрации: %s" % e, 'danger') return render_template('login.html', isReg=True, form=form) return redirect("/")
def test_set_and_get_card(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") lid0 = List.add("To Do", bid0) card_id = Card.add("card0", lid0, uid0) card = Card.get(card_id) assert card.title == 'card0' assert card.list_id == lid0
def test_get_and_test_description(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") lid0 = List.add("To Do", bid0) card_id = Card.add("card0", lid0, uid0) card = Card.get(card_id) card.set_description('desc') assert 'desc' in card.get_description()
def test_add_and_get(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") aid0 = Activity.add(bid0, uid0, "BLABLA") activity0 = Activity.get(aid0) assert bid0 == activity0.board_id assert uid0 == activity0.user_id assert "BLABLA" == activity0.content
def route_register(request): header = 'HTTP/1.1 210 VERY OK\r\nContent-Type: text/html\r\n' if request.method == 'POST': form = request.form() u = User(form) if u.validate_register(): User.add(u) # add 已经自动保存了 result = f'注册成功<br> <pre>{User.all()}</pre>' else: result = '用户名或者密码长度必须大于2' else: result = '' body = template('register.html') body = body.replace('{{result}}', result) r = header + '\r\n' + body return r.encode(encoding='utf-8')
def test_add_and_get(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") lid0 = List.add("To Do", bid0) caid0 = Card.add("card1", lid0, uid0) coid0 = Comment.add(caid0, uid0, "comment1") comment0 = Comment.get(coid0) assert caid0 == comment0.card_id assert uid0 == comment0.user_id assert "comment1" == comment0.content
def incr_decr_get_comment(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") lid0 = List.add("To Do", bid0) card_id = Card.add("card0", lid0, uid0) card = Card.get(card_id) Card.incr_comment(card_id) assert 1 == card.get_comment_count() Card.desc_comment(card_id) assert 0 == card.get_comment_count()
def test_add_and_get_boards(self): cid = User.add("test_user1", "password", "*****@*****.**") user = User.get(cid) bid0 = Board.add("board1", "A") bid1 = Board.add("board2", "A") board0 = Board.get(bid0) board1 = Board.get(bid1) user.add_board(board0) assert str(bid0) in user.get_board_ids() assert str(bid1) not in user.get_board_ids()
def test_get_cards(self): bid0 = Board.add("board1", "A") lid0 = List.add("List0", bid0) list0 = List.get(lid0) lid1 = List.add("List1", bid0) list1 = List.get(lid1) uid0 = User.add("test1", "password", "*****@*****.**") caid0 = Card.add("card1", lid0, uid0) caid1 = Card.add("card2", lid1, uid0) assert caid0 in [card.id for card in list0.get_cards()] assert caid1 not in [card.id for card in list0.get_cards()]
def post(self): user_post_parser.add_argument( 'password', type=str, ) args = user_post_parser.parse_args() password = args['password'] user = User(name=args['name'], email=args['email'], intro=args['intro'], avatar=args['avatar']) if (user.avatar == ''): user.avatar = 'https://avatars.dicebear.com/v2/female/janefaddsdfkk.svg' if (user.intro == ''): user.intro = 'Hi all.' user.set_password(password) try: user.add() except IntegrityError: return max_res('', code=500, errmsg='Record existed.') return max_res(marshal(user, user_fields))
def test_get_comments_by_card_id(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") bid1 = Board.add("board2", "A") aid0 = Activity.add(bid0, uid0, "BLABLA") aid1 = Activity.add(bid0, uid0, "LA") aid2 = Activity.add(bid1, uid0, "HULA") activity0 = Activity.get(aid0) activity1 = Activity.get(aid1) activity2 = Activity.get(aid2) assert aid0 in [activity.id for activity in Activity.get_all(bid0)] assert aid1 in [activity.id for activity in Activity.get_all(bid0)] assert aid2 not in [activity.id for activity in Activity.get_all(bid0)] assert aid2 in [activity.id for activity in Activity.get_all(bid1)]
def test_get_comments_by_card_id(self): uid0 = User.add("test1", "password", "*****@*****.**") bid0 = Board.add("board1", "A") lid0 = List.add("To Do", bid0) caid0 = Card.add("card1", lid0, uid0) caid1 = Card.add("card2", lid0, uid0) coid0 = Comment.add(caid0, uid0, "comment1") coid1 = Comment.add(caid1, uid0, "comment2") comment0 = Comment.get(coid0) comment1 = Comment.get(coid1) assert coid0 in [comment.id for comment in Comment.get_comments_by_card_id(caid0)] assert coid1 not in [comment.id for comment in Comment.get_comments_by_card_id(caid0)]
def post(self): args = self.parser.parse_args() resp = self.jscode2session(args['js_code']) print(resp) if isinstance(resp, dict): # 先登出 logout_user() openid = resp.get('openid') # 新用户的话则存入数据库 user = User.get(openid) if user is None: user = User.add(openid) login_user(user) session.update({'openid': openid}) print(session) return marshal(session, self.login_fields)
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)
def add_users(): members = Bot.guild.members for member in members: if not(member.bot): User.add(member.id, member.name, 0, Level.get_max_xp(1), 1)
from models.card import Card from models.comment import Comment from utils.db import mysql_engine, r_server r_server.flushdb() Board.__table__.drop(mysql_engine, checkfirst=True) Board.__table__.create(mysql_engine, checkfirst=True) User.__table__.drop(mysql_engine, checkfirst=True) User.__table__.create(mysql_engine, checkfirst=True) List.__table__.drop(mysql_engine, checkfirst=True) List.__table__.create(mysql_engine, checkfirst=True) Card.__table__.drop(mysql_engine, checkfirst=True) Card.__table__.create(mysql_engine, checkfirst=True) Comment.__table__.drop(mysql_engine, checkfirst=True) Comment.__table__.create(mysql_engine, checkfirst=True) uid0 = User.add("test1", "password", "*****@*****.**") uid1 = User.add("test2", "password", "*****@*****.**") uid2 = User.add("test3", "password", "*****@*****.**") user0 = User.get(uid0) user1 = User.get(uid1) user2 = User.get(uid2) bid0 = Board.add("board1", "A") bid1 = Board.add("board2", "A") board0 = Board.get(bid0) board1 = Board.get(bid1) board0.add_user(user0) board0.add_user(user1)
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
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="",
def add_user(name, pwd=DEFAULT_PASSWORD): team = add_team('testteam1') user = User.add(name=name, email=(name + '@inad.com'), password=pwd, team=team) return user
# -*- coding: utf-8 -*- from models.user import User User.add("what", "password", "*****@*****.**") User.add("yay", "password", "*****@*****.**") User.add("lsduf fdfe", "password", "*****@*****.**") User.add("toilet", "password", "*****@*****.**") User.add("sorbitol", "password", "*****@*****.**") User.add("washroom", "password", "*****@*****.**") User.add("happiness", "password", "*****@*****.**") User.add("zebra", "password", "*****@*****.**") User.add("pp ll oooookay", "password", "*****@*****.**") User.add("face of what", "password", "*****@*****.**") User.add("reason", "password", "*****@*****.**") User.add("abandon", "password", "*****@*****.**") User.add("moron", "password", "*****@*****.**") User.add("bad people", "password", "*****@*****.**") User.add("vandal", "password", "*****@*****.**")
def first_run(): from models.client import Client from models.category import Category from models.orders import Order from models.product import Product from models.restaurants import Restaurant from models.user import User meta = sqlalchemy.MetaData(engine) meta.reflect() #meta.drop_all() print("First run, please wait while the db is being populated...") # Create tables Base.metadata.create_all(engine) testClient = Client.add("6977988551") testClient2 = Client.add("8891155521") restaurant = Restaurant.add( "Restaurant 1", "The best food you'll find in the city\nWe make sandwiches, salads and burgers" ) sandwichesCategory = Category.add("Sandwiches", restaurant) Product.add("Pulled Pork", "With tangy barbecue sauce on an onion knot", 9.50, restaurant, sandwichesCategory) Product.add( "Turkey Club", "Roasted turkey breast, bacon, lettuce, avocado and tomato on baguette", 8, restaurant, sandwichesCategory) Product.add( "Reuben", "Corned beef, melted swiss, sauerkraut and thousand island on marbled rye", 8, restaurant, sandwichesCategory) Product.add( "Shrimp Cilantro Wrap", "Shrimp, avocado, mixed greens, salsa, cilantro and may on a tomato tortilla", 8.5, restaurant, sandwichesCategory) burgerCategory = Category.add("Burgers", restaurant) Product.add( "Grass-fed Beef Burger", "With sharp cheddar, heirloom tomatoes and caramelized onions", 9.5, restaurant, burgerCategory) Product.add( "Mushroom Swiss Burger", "With sautéed mushrooms and melted swiss on a home-baked roll", 10, restaurant, burgerCategory) Product.add( "Hickory Burger", "Topped with cheddar, hickory smoked bacon and smoked barbecue sauce", 10, restaurant, burgerCategory) Product.add( "Chicken Burger", "Grilled chicken breast with heirloom tomatoes, avocado and sprouts on a home-baked roll", 9, restaurant, burgerCategory) saladCategory = Category.add("Salads", restaurant) Product.add( "Caesar Salad", "Romaine, fresh parmesan, seasoned croutons and black pepper with garlic anchovy dressing", 6.75, restaurant, saladCategory) Product.add("Red Iceberg Salad", "With sweet corn, blackberries, goat cheese and fresh basil", 9.25, restaurant, saladCategory) Product.add( "House Salad", "With green olives, green peppers, onions, cucumbers, and tomato", 6.75, restaurant, saladCategory) Product.add( "Blue Chicken Salad", "Mesclun greens, apple, grilled chicken, gorgonzola, chesse and balsamic vinagrette", 9.25, restaurant, saladCategory) # Add an user for the restaurant we just created User.add("restaurant1", "restaurant1", 0, restaurant) streets = [ "Oak Street", "Madison Avenue", "Bridle Lane", "Jefferson Street", "Lafayette Avenue", "Grove Street", "Chestnut Avenue" ] # Simulate some orders on a different client originalDate = time.time() - 57600000 for i in range(87): productCount = randint(1, 2) used = {} products = [] price = 0 originalDate += randint(376000, 576000) for y in range(productCount): id = randint(0, 11) while (id in used): id = randint(0, 11) used[id] = True amount = randint(1, 2) products.append({"id": id + 1, "count": amount}) product = Product.get_from_id(id + 1) price += amount * product.price order = Order.add( random.choice(streets) + " " + str(randint(1, 5000)), price, "", products, [-34.601874, -58.432611], testClient2, restaurant) order.date = originalDate order.status = 2 get_session().commit() Order.add("Bridle Lane 1775", 9.50, "", [{ 'id': 1, 'count': 1 }], [-34.601874, -58.432611], testClient, restaurant)
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) group = Group.add(u'测试代理集团') agent = Agent.add(u"测试代理", group=group)