Beispiel #1
0
def create_db():
    try:
        User.drop_table()
        Member.drop_table()
        Commodity.drop_table()
        Category.drop_table()
        UserOrder.drop_table()
        OrderItem.drop_table()
        CommodityImage.drop_table()
        CommodityComment.drop_table()
        Address.drop_table()
        OrderStatus.drop_table()
        Announcement.drop_table()
        Feedback.drop_table()
    except:
        pass

    User.create_table()
    Member.create_table()
    Commodity.create_table()
    Category.create_table()
    UserOrder.create_table()
    OrderItem.create_table()
    CommodityImage.create_table()
    CommodityComment.create_table()
    Address.create_table()
    OrderStatus.create_table()
    Announcement.create_table()
    Feedback.create_table()
Beispiel #2
0
def init_db():
    # init status
    global status_list
    global memberships
    global category_list
    global user_list

    s_init = OrderStatus.create(name="init")
    s_confirmed = OrderStatus.create(name="confirmed")
    s_sent = OrderStatus.create(name="sent")
    s_complete = OrderStatus.create(name="complete")
    s_canceled = OrderStatus.create(name="canceled")
    status_list += [s_init, s_confirmed, s_sent, s_complete, s_canceled]

    member0 = Member.create(name="normal", point=1000, discount=100)
    member1 = Member.create(name="vip1", point=2000, discount=90)
    member2 = Member.create(name="vip2", point=3000, discount=80)
    member3 = Member.create(name="vip3", point=4000, discount=70)
    member4 = Member.create(name="vip4", point=5000, discount=60)
    member5 = Member.create(name="vip5", point=-1, discount=50)
    memberships += [member1, member2, member3, member4]

    # init user
    User.create(username="******", password="******", admin=True)
    # user = User.create(username="******", password="******", admin=True)
    # user.set_password("zhang")
    # user.save()

    Announcement.create(title="Hello", content="World")
    Announcement.create(title="Hello", content="World")
    Announcement.create(title="Hello", content="World")

    for i in range(100):
        random_user()

    # init Commodity
    cat = Category.create(name="All")
    category_list.append(cat)
    for i in range(10):
        random_cat()

    for i in range(100):
        random_co()

    for u in user_list:
        random_order(u)

    for i in range(20):
        random_feed()
Beispiel #3
0
def com_filter_list():
    categories = Category.select().filter(**request.args)
    return render_template('core/com_filter_list.html', categories=categories)
Beispiel #4
0
def random_cat():
    global category_list
    name = " ".join(random_name(1))
    cat = Category.create(name=name, parent=random.choice(category_list))
    category_list.append(cat)
    return cat