Example #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()
Example #2
0
def search_commodity():
    from shop import app
    ix = open_dir(app.config.get("INDEX_DIR"))
    searcher = ix.searcher()
    mparser = MultifieldParser(["content", "title"], schema=ix.schema)

    query_raw = request.args.get('q', '')
    if query_raw:
        query = mparser.parse(unicode(query_raw.lower()))
        results = searcher.search(query)

        result_id = []
        for result in results:
            result_id.append(int(result['id']))

        result_id = list(set(result_id))
        wq = None
        for rid in result_id:
            if not wq:
                wq = Q(id=rid)
            else:
                wq |= Q(id=rid)
        if wq:
            coms = Commodity.select().where(wq)
        else:
            coms = []
    else:
        coms = Commodity.select()
    category = int(request.args.get('c', '0'))
    if category and category != 1:
        coms = [c for c in coms if c.is_category(category)]
    return render_template('core/com_list.html', commodities=coms)
Example #3
0
def travel_commodity(writer):
    commodities = Commodity.select()
    for com in commodities:
        writer.add_document(type=u"Commodity",
                            id=unicode(com.id),
                            title=unicode(com.name.lower()),
                            content=unicode(com.des.lower()))
Example #4
0
def get_new():
    coms = list(Commodity.select())
    result = sorted(coms, key=lambda a: a.join_date, reverse=True)
    if len(result) > 5:
        result = result[:5]
    return render_template('core/gallery_view.html', items=result,
                            title="What's New", id="new")
Example #5
0
def get_hot():
    coms = list(Commodity.select())
    result = sorted(coms, key=lambda a: a.order_items.count(), reverse=True)
    if len(result) > 5:
        result = result[:5]
    return render_template('core/gallery_view.html', items=result,
                                    title="What's Host", id="hot")
Example #6
0
def random_co():
    global category_list
    global co_list
    name = " ".join(random_name(1))
    co = Commodity.create(price=random.randint(20, 100), name=name, category=random.choice(category_list))
    CommodityImage.create(name=random_img(), commodity=co)
    co_list.append(co)
    return co
Example #7
0
def item(item_id):
    commodity = Commodity.select().get(id=item_id)
    commodity.img_name = commodity.imgs.execute().first().name
    return render_template('commodity/item.html', user=g.user,
                                                  commodity=commodity)
Example #8
0
def item_comments(item_id):
    commodity = Commodity.select().get(id=item_id)
    return render_template('commodity/item_comments.html',
                            user=g.user, commodity=commodity)
Example #9
0
def additem():
    json = request.json
    order = get_object_or_404(UserOrder, id=json["order"])
    commodity = Commodity.select().get(id=json["commodity"])
    OrderItem.create(commodity=commodity, order=order, num=json["num"], price=commodity.price)
    return jsonify(success=True)
Example #10
0
def com_list():
    commodities = Commodity.select().filter(**request.args)
    return render_template('core/com_list.html', commodities=commodities)
Example #11
0
def recommend():
    recommends = list(Commodity.select())[0:10]
    return render_template('core/gallery_view.html',
                            title="Recommendation",
                            items=recommends, id="rec")