Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
54017 committed Apr 4, 2015
2 parents 6a27a07 + 9766e67 commit 61bcdff
Show file tree
Hide file tree
Showing 46 changed files with 452 additions and 78,110 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
instance/
.svn/
migrations/
app/node_modules/
app/static/img/
app/static/tmp/
40 changes: 18 additions & 22 deletions app/Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ module.exports = (grunt) ->
coffee: "src/pc/src/coffee/*.coffee"
less: "src/pc/src/less/*.less"

dest =
dest =
js: "static/pc/js"
css: "static/pc/css"

grunt.initConfig
clean:
bin:
src: ["static/pc/css/*.css", "static/pc/js/*.js"]
dist: ["static/pc/css/*.min.css", "static/pc/js/*.min.js"]

watch:
compile:
Expand Down Expand Up @@ -52,26 +51,26 @@ module.exports = (grunt) ->
build:
files: [{
expand: true
cwd: "static/pc/js"
cwd: dest.js
src: ["*.js"]
dest: dest.js
ext: ".min.js"
ext: ".js"
}]

cssmin:
build:
files: [{
expand: true
cwd: "static/pc/css"
cwd: dest.css
src: ["*.css"]
dest: dest.css
ext: ".min.css"
ext: ".css"
}]

copy:
assets:
src: "static/images"
dest: "dist/images"
# copy:
# assets:
# src: "static/images"
# dest: "dist/images"
# css:
# options:
# process: (content, srcpath)->
Expand All @@ -86,14 +85,14 @@ module.exports = (grunt) ->
# files:
# "dist/index.html": ["src/index.html"]

imagemin:
dev:
files: [
expand: true
cwd: 'notminimgs'
src: ['*.{png, jpg, gif}']
dest: 'static/images/'
]
# imagemin:
# dev:
# files: [
# expand: true
# cwd: 'notminimgs'
# src: ['*.{png, jpg, gif}']
# dest: 'static/images/'
# ]

grunt.loadNpmTasks "grunt-contrib-copy"
grunt.loadNpmTasks "grunt-contrib-clean"
Expand All @@ -102,7 +101,7 @@ module.exports = (grunt) ->
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-contrib-uglify"
grunt.loadNpmTasks "grunt-contrib-cssmin"
grunt.loadNpmTasks "grunt-contrib-imagemin"
# grunt.loadNpmTasks "grunt-contrib-imagemin"

grunt.registerTask "default", ->
grunt.task.run [
Expand All @@ -115,12 +114,9 @@ module.exports = (grunt) ->
grunt.registerTask "build", ->
grunt.task.run [
"clean:bin"
"clean:dist"
"browserify"
"less"
"uglify"
"cssmin"
"copy"
]

grunt.registerTask "min", ["imagemin"]
2 changes: 1 addition & 1 deletion app/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ModifyCat2Form(CreateCat1Form):
name = StringField(validators=[Required(), Length(1, 32), ])

class DeleteCat2Form(Form):
cat1_id = IntegerField(validators=[Required(), ])
cat2_id = IntegerField(validators=[Required(), ])

class CreateProductForm(Form):
name = StringField(validators=[Required(), Length(1, 50), ])
Expand Down
4 changes: 2 additions & 2 deletions app/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def logout():
def index():
ad = g.admin
if ad.privilege == 4:
if not viaMobile():
return render_template('admin/index_3.html')
return render_template('admin/index_3.html')
elif ad.privilege == 2:
return render_template('admin/index_2.html')
elif ad.privilege == 1:
Expand Down Expand Up @@ -1203,6 +1202,7 @@ def delete_product():
if p and p.pic:
removepic(p.pic.filename)
p.product_buildings.delete()
p.carts.delete()
db.session.delete(p)
db.session.commit()
return jsonResponse(None)
Expand Down
2 changes: 2 additions & 0 deletions app/cart/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
from ..util.errno import CartErrno
from ..user.utils import buyer_login_required
from ..product.models import Product, Product_building
from ..util.common import PC_MB_distribute

@cartbp.route('/', methods=['GET', ])
@PC_MB_distribute('/m/cart')
@buyer_login_required(False, 'main.index')
def shopping_cart():
u = g.buyer
Expand Down
6 changes: 5 additions & 1 deletion app/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def index():
uid = session.get('buyerid')
user = User.query.filter_by(id=uid).first() if uid else None
if user:
user.name = u'匿名用户'
buyer_contact_info = session.get('buyer_contact_info')
if buyer_contact_info:
user.name = buyer_contact_info[0]
else:
user.name = u'匿名用户'
buyer_location_info = session.get('buyer_location_info')
user.location_info = {
'school_id': buyer_location_info[0][0],
Expand Down
6 changes: 5 additions & 1 deletion app/mbend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def index():
uid = session.get('buyerid')
user = User.query.filter_by(id=uid).first() if uid else None
if user:
user.name = u'匿名用户'
buyer_contact_info = session.get('buyer_contact_info')
if buyer_contact_info:
user.name = buyer_contact_info[0]
else:
user.name = u'匿名用户'
buyer_location_info = session.get('buyer_location_info')
user.location_info = {
'school_id': buyer_location_info[0][0],
Expand Down
4 changes: 2 additions & 2 deletions app/order/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def validate_product_ids(form ,field):
else:
raise ValidationError('Product ids format error.')
def validate_phone(form, field):
if not (re.match(mobile_p, field.data).group() or\
re.match(telephone_p, field.data).group()):
if not (re.match(mobile_p, field.data) or\
re.match(telephone_p, field.data)):
raise ValidationError('Not a telephone or mobile phone number.')


Expand Down
5 changes: 4 additions & 1 deletion app/order/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..cart.models import Cart
from ..product.models import Product_building, Product, Snapshot
from ..location.models import Building, School
from ..util.common import PC_MB_distribute

# ajax
@orderbp.route('/create', methods=['POST', ])
Expand All @@ -35,7 +36,8 @@ def create_order():
return jsonError(CartErrno.CART_INVALID)
for i in range(len(pbs)): # check whether some products have been updated
pd = pbs[i].product
if pd.snapshots.filter(Snapshot.released_time>carts[i].last_viewed_time).count():
if pd.snapshots.filter(Snapshot.released_time>carts[i].last_viewed_time).count() or\
pbs[i].quantity < carts[i].quantity:
return jsonError(OrderErrno.PRODUCT_REFRESH)
timedelta = max([i.timedelta for i in pbs]) # get max delivery time
bd = Building.query.get(u.location_info['building_id'])
Expand Down Expand Up @@ -77,6 +79,7 @@ def create_order():
return jsonError(OrderErrno.INVALID_ARGUMENT)

@orderbp.route('/', methods=['GET', ])
@PC_MB_distribute('/m/order')
@buyer_login_required(False, 'main.index')
def order_page():
u = g.buyer
Expand Down
8 changes: 4 additions & 4 deletions app/pic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def savepic(file_):
file_.save('%s/%s' % (SAVE_PATH, filename))
f = File(filename=filename)
db.session.add(f)
db.session.commit()
# db.session.commit()
return f

def changepic(product_obj, file_):
Expand All @@ -33,7 +33,7 @@ def changepic(product_obj, file_):
file_.save('%s/%s' % (SAVE_PATH, filename))
product_obj.pic.filename = filename
db.session.add(product_obj)
db.session.commit()
# db.session.commit()

def removepic(filename):
'''
Expand All @@ -44,7 +44,7 @@ def removepic(filename):
except:
pass
File.query.filter_by(filename=filename).delete()
db.session.commit()
# db.session.commit()

def copypic(product_obj):
'''
Expand All @@ -59,6 +59,6 @@ def copypic(product_obj):
nf.close()
nf = File(filename=filename)
db.session.add(nf)
db.session.commit()
# db.session.commit()
return nf

8 changes: 5 additions & 3 deletions app/product/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from ..category.models import Cat1, Cat2
from ..category.utils import _get_catx
from ..product.models import Product_building, Product
from ..util.common import PC_MB_distribute

@productbp.route('/list', methods=['GET', ])
@PC_MB_distribute('/m/product/list')
@buyer_login_required(False, 'main.index')
def get_product_list_by_catx_render():
u = g.buyer
Expand Down Expand Up @@ -55,8 +57,8 @@ def get_product_list_by_catx_ajax():
return jsonResponse({
'products': products,
'current_cat1': {
'id': current_cat1.id,
'name': current_cat1.name,
'id': current_cat1.id if current_cat1 else None,
'name': current_cat1.name if current_cat1 else None,
},
})
return jsonError(ProductErrno.INVALID_ARGUMENT)
Expand Down Expand Up @@ -124,7 +126,7 @@ def get_hot_product_list():
res = []
for i in hot_products:
data = dict()
pd, sold_cnt, qty = i[0], i[1], i[2]
pd, sold_cnt, qty = i[0], int(i[1]), int(i[2])
data['id'] = pd.id
data['name'] = pd.name
data['description'] = pd.description
Expand Down
51 changes: 43 additions & 8 deletions app/src/pc/src/coffee/cart.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ getCartObjs = ->
success: (res)->
if res.code is 0
bindCartObjs res.data
else
common.tokenNotify()

getContactInfo = ->
jquery.ajax
Expand All @@ -44,6 +46,8 @@ getContactInfo = ->
success: (res)->
originalContactInfo = res.data
bindContactInfo res.data if res.code is 0
if res.code != 0 and res.code != -3
common.tokenNotify()

initBtns = ->
$mask.click (e)->
Expand Down Expand Up @@ -83,8 +87,11 @@ initBtns = ->

settleStrategy =
"0": "成功下单"
"1": "error: 无效的参数"
"-2": "error: 存在无效商品,请刷新页面后再试"
"1": "信息输入不正确,请重新输入"
"-1": " 存在无效商品,请刷新页面后再试"
"-2": " 存在无效商品,请刷新页面后再试"
"2": "请重新选择位置后再试"
"3": "请重新选择位置后再试"

$confirmBtn.click ->
if vm.checkedProductsLength() < 1
Expand Down Expand Up @@ -117,6 +124,13 @@ bindCartObjs = (objs)->

injectProperties = (obj)->
obj.setQuantity = ->
strategy =
"1": "无效的输入,请重新输入"
"-3": "该商品不存在,请刷新页面后再试"
"-2": " 该商品已失效,请刷新页面后再试"
"2": "请重新选择位置后再试"
"3": "请重新选择位置后再试"

quantity = parseInt(@quantity())
if quantity and quantity > 0
@quantity(quantity)
Expand All @@ -131,6 +145,9 @@ injectProperties = (obj)->
csrf_token: localStorage.csrf_token
product_id: @product_id
quantity: @quantity()
success: (res) ->
if res.code isnt 0
common.notify(strategy[res.code])

obj.validStatus = -> @is_valid ? '' : 'unvalid'
obj.removeSelf = -> @deleteHandler('/cart/delete')
Expand All @@ -144,26 +161,45 @@ injectProperties = (obj)->
obj.formattedPrice = ko.pureComputed ->
"" + @totalPrice()
, obj
obj.checkProduct = ->
vm.is_all_checked(false)

deleteHandler = (suffix) ->
strategy =
"2": "请重新选择位置后再试"
"3": "请重新选择位置后再试"
jquery.ajax
url: common.url + suffix
type: "POST"
data:
_crsf_token: localStorage.csrf_token
csrf_token: localStorage.csrf_token
product_id: @product_id
success: (res) =>
vm.cartObjs.remove @
if res.code is 0
vm.cartObjs.remove @
common.initHeader()
else
common.notify(strategy[res.code])


quantityHandler = (suffix)->
strategy =
"-3": "该商品不存在,请刷新页面后再试"
"-2": " 该商品已失效,请刷新页面后再试"
"2": "请重新选择位置后再试"
"3": "请重新选择位置后再试"
jquery.ajax
url: common.url + suffix
type: "POST"
data:
csrf_token: localStorage.csrf_token
product_id: @product_id
success: (res)=>
@quantity(res.data) if res.code is 0 and res.data > 0
success: (res) =>
if res.code is 0
@quantity(res.data) if res.data > 0
else
common.notify(strategy[res.code])


bindContactInfo = (info)->
props = ['name', 'phone', 'addr']
Expand All @@ -182,13 +218,12 @@ getCheckedProductIds = ->
vm.deleteCheckedProducts = ->
checked_cart_obj.removeSelf() for checked_cart_obj in getCheckedProducts()


vm.checkAllProducts = ->
vm.is_all_checked(!vm.is_all_checked())
cart_obj.is_checked(vm.is_all_checked()) for cart_obj in vm.cartObjs()

vm.deleteInvalidProducts = ->
cart_obj.removeSelf() for cart_obj in vm.cartObjs() when cart_obj.is_valid
cart_obj.removeSelf() for cart_obj in vm.cartObjs() when not cart_obj.is_valid

vm.checkedProductsLength = ko.pureComputed ->
getCheckedProducts().length
Expand Down
Loading

0 comments on commit 61bcdff

Please sign in to comment.