-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
453 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import home, work, collection, author, dynasty, user, review, love | ||
import home, work, collection, author, dynasty, user, review, love, product |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#-*- coding: UTF-8 -*- | ||
|
||
from flask import render_template, request, redirect, url_for, json, session | ||
|
||
from xichuangzhu import app | ||
|
||
from xichuangzhu.models.product_model import Product | ||
|
||
# page - shop | ||
#-------------------------------------------------- | ||
|
||
# view | ||
@app.route('/shop') | ||
def shop(): | ||
products = Product.get_products(12) | ||
return render_template('shop.html', products=products) | ||
|
||
# page - single product | ||
#-------------------------------------------------- | ||
|
||
# view | ||
@app.route('/product/<int:product_id>') | ||
def single_product(product_id): | ||
product = Product.get_product(product_id) | ||
return render_template('single_product.html', product=product) | ||
|
||
# page - add product | ||
#-------------------------------------------------- | ||
|
||
# view | ||
@app.route('/product/add', methods=['GET', 'POST']) | ||
def add_product(): | ||
if request.method == 'GET': | ||
return render_template('add_product.html') | ||
elif request.method == 'POST': | ||
product = request.form['product'] | ||
url = request.form['url'] | ||
image_url = request.form['image-url'] | ||
introduction = request.form['introduction'] | ||
|
||
new_product_id = Product.add_product(product, url, image_url, introduction) | ||
return redirect(url_for('single_product', product_id=new_product_id)) | ||
|
||
# page - edit product | ||
#-------------------------------------------------- | ||
|
||
# view | ||
@app.route('/product/edit/<int:product_id>', methods=['GET', 'POST']) | ||
def edit_product(product_id): | ||
if request.method == 'GET': | ||
product = Product.get_product(product_id) | ||
return render_template('edit_product.html', product=product) | ||
elif request.method == 'POST': | ||
product = request.form['product'] | ||
url = request.form['url'] | ||
image_url = request.form['image-url'] | ||
introduction = request.form['introduction'] | ||
|
||
Product.edit_product(product_id, product, url, image_url, introduction) | ||
return redirect(url_for('single_product', product_id=product_id)) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from xichuangzhu import conn, cursor | ||
|
||
class Product: | ||
|
||
# GET | ||
|
||
# get single product | ||
@staticmethod | ||
def get_product(product_id): | ||
query = "SELECT * FROM product WHERE ProductID = %d" % product_id | ||
cursor.execute(query) | ||
return cursor.fetchone() | ||
|
||
# get products by num | ||
@staticmethod | ||
def get_products(num): | ||
query = "SELECT * FROM product LIMIT %d" % num | ||
cursor.execute(query) | ||
return cursor.fetchall() | ||
|
||
# NEW | ||
|
||
# add product | ||
@staticmethod | ||
def add_product(product, url, image_url, introduction): | ||
query = '''INSERT INTO product (Product, Url, ImageUrl, Introduction)\n | ||
VALUES ('%s', '%s', '%s', '%s')''' % (product, url, image_url, introduction) | ||
cursor.execute(query) | ||
conn.commit() | ||
return cursor.lastrowid | ||
|
||
# EDIT | ||
|
||
# edit product | ||
@staticmethod | ||
def edit_product(product_id, product, url, image_url, introduction): | ||
query = '''UPDATE product SET Product = '%s', Url = '%s', ImageUrl = '%s', Introduction = '%s' WHERE ProductID = %d''' % (product, url, image_url, introduction, product_id) | ||
cursor.execute(query) | ||
return conn.commit() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %}添加商品{% endblock %} | ||
|
||
{% block page_id%}page-add-product{% endblock %} | ||
|
||
{% block body %} | ||
|
||
<form id="form-add-product" class="form-horizontal" method="post" action="{{ url_for('add_product') }}"> | ||
<fieldset> | ||
<legend>添加商品</legend> | ||
|
||
<div class="control-group"> | ||
<label class="control-label">商品</label> | ||
<div class="controls"> | ||
<input type="text" name="product" /> | ||
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<label class="control-label">主页</label> | ||
<div class="controls"> | ||
<input type="text" class="input-xxlarge" name="url" /> | ||
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<label class="control-label">图片</label> | ||
<div class="controls"> | ||
<input type="text" class="input-xxlarge" name="image-url" /> | ||
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<label class="control-label">简介</label> | ||
<div class="controls"> | ||
<textarea class="input-xxlarge" rows="10" name="introduction"></textarea> | ||
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<div class="controls"> | ||
<input type="submit" value="提交" class="btn btn-primary" /> | ||
</div> | ||
</div> | ||
|
||
</fieldset> | ||
</form> | ||
|
||
{% endblock %} |
Oops, something went wrong.