#!/usr/bin/env python
#coding=utf-8
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.core.urlresolvers import resolve
from django.http import Http404
from food.runtime import foodUtil
from icokouCore.runtime import htmlContent
from icokouCore.runtime import coreInfo
from icokouCore.runtime import geo
#添加菜品
def AddFood(request):
if request.method == 'GET':
htmlContentDictRoot = {}
urlPath = resolve(reverse('food:AddFood')).namespace
return render_to_response('%s/%s' % (urlPath,'addFood.html') ,
htmlContentDictRoot, context_instance=RequestContext(request)
)
if request.method == 'POST':
try:
#获取表单信息
foodInfo = {}
#创建htmlContentDictRoot内容
htmlContentDictRoot = {}
htmlContentDictRoot = htmlContent.CreateHtmlContentDict(htmlContentDictRoot,'nextPage', {'url':reverse('food:AddFood')})
foodInfo['foodName'] = request.POST['foodName']
if foodInfo == '':
htmlContentDictRoot = htmlContent.CreateHtmlContentDict(htmlContentDictRoot,'error', {'content':u'菜品名不允许为空'})
raise
foodInfo['foodMemo'] = request.POST['foodMemo']
if foodInfo['foodMemo'] == '':
htmlContentDictRoot = htmlContent.CreateHtmlContentDict(htmlContentDictRoot,'error', {'content':u'菜品介绍不允许为空'})
raise
try:
foodInfo['foodPrice'] = float(request.POST['foodPrice'])
except Exception as e:
foodInfo['foodPrice'] = 0.00
foodInfo['lat'] = ''
foodInfo['lng'] = ''
foodInfo['foodAddress'] = ''
lngInfo = {}
try:
foodInfo['foodAddress'] = request.POST['foodAddress'].strip()
foodInfo['lat'] = request.POST['addFoodLat']
foodInfo['lng'] = request.POST['addFoodLng']
#如果客户端有传回经纬度坐标,优先处理
if (foodInfo['lat'] != '') and (foodInfo['lng'] != '') :
#经纬度纠偏
latLng = geo.transform(float(foodInfo['lat']),float(foodInfo['lng']))
lngInfo['lat'] = latLng[0]
lngInfo['lng'] = latLng[1]
#如果地址为空
if foodInfo['foodAddress'] == '':
foodInfo['foodAddress'] = coreInfo.GetGeoByLng(latLng[0],latLng[1])
#否则按地址反查坐标
else:
#转换经纬度坐标
lngInfo = coreInfo.GetGeoByAddress(foodInfo['foodAddress'])
#经纬度纠偏
latLng = geo.transform(float(lngInfo['lat']),float(lngInfo['lng']))
lngInfo['lat'] = latLng[0]
lngInfo['lng'] = latLng[1]
except Exception as e:
foodInfo['foodAddress'] = u'成都'
lngInfo = coreInfo.GetGeoByAddress(foodInfo['foodAddress'])
foodInfo['foodPic'] = request.FILES.get('foodPic')
if foodInfo['foodPic'] == None:
htmlContentDictRoot = htmlContent.CreateHtmlContentDict(htmlContentDictRoot,'error', {'content':u'未上传菜品图片'})
raise
#获取当前用户名
foodInfo['createUser'] = request.user
#获取IP地址
foodInfo['ipAddress'] = coreInfo.GetClientIp(request.META)
#添加菜品
foodObj = foodUtil.AddFood(foodInfo,lngInfo)
return HttpResponseRedirect(reverse('food:ViewFood', kwargs={'fId':foodObj.id}))
except Exception as e:
htmlContentDictRoot = htmlContent.CreateHtmlContentDict(htmlContentDictRoot,'exception', {'content':e})
return render_to_response('error.html', htmlContentDictRoot, context_instance=RequestContext(request))
#查看菜品
def ViewFood(request,fId):
if request.method == 'GET':
try:
#获取ip地址
ipAddr = coreInfo.GetClientIp(request.META)
#获取菜品对象
foodObj = foodUtil.GetFoodById(fId)
#添加点击次数
foodUtil.AddFoodHitLog(fId,request.user,ipAddr)
htmlContentDictRoot = {}
urlPath = resolve(reverse('food:AddFood')).namespace
htmlContentDictRoot = htmlContent.CreateHtmlContentDict(htmlContentDictRoot,'food', {'obj':foodObj})
return render_to_response('%s/%s' % (urlPath,'viewFood.html') ,
htmlContentDictRoot, context_instance=RequestContext(request)
)
except Exception as e:
print e
#推荐菜品
def CommendFood(request,fId):
if request.method == 'GET':
try:
#获取ip地址
ipAddr = coreInfo.GetClientIp(request.META)
#添加推荐
foodUtil.AddFoodCommendLog(fId,request.user,ipAddr)
return HttpResponseRedirect(reverse('food:ViewFood', kwargs={'fId':fId}))
except Exception as e:
raise Http404
#收藏菜品
def CollectsFood(request,fId):
if request.method == 'GET':
try:
#添加收藏
foodUtil.AddFoodCollectsLog(fId,request.user)
return HttpResponseRedirect(reverse('food:ViewFood', kwargs={'fId':fId}))
except Exception as e:
raise Http404
#编辑菜品
def EditFood(request,fId):
if request.method == 'GET':
pass
if request.method == 'POST':
pass
#搜索菜品表单视图
def SearchForm(request):
if request.method == 'POST':
foodName = request.POST['foodName']
return HttpResponseRedirect(reverse('food:SearchFood', kwargs={'foodName':foodName}))
#搜索菜品
def SearchFood(request,foodName=""):
if request.method == 'GET':
try:
htmlContentDictRoot = {}
urlPath = resolve(reverse('food:AddFood')).namespace
foodObjList = foodUtil.SearchFood(foodName)
htmlContentDictRoot = htmlContent.CreateHtmlContentDict(htmlContentDictRoot,'foodObjList', {'obj':foodObjList})
return render_to_response('%s/%s' % (urlPath,'foodList.html') ,
htmlContentDictRoot, context_instance=RequestContext(request)
)
except Exception as e:
raise e
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
一个基于django的美食分享网站.zip (86个子文件)
icokou-master
icokou
__init__.py 0B
settingsDev.py 61B
icokou.fcgi 430B
settingsBeta.py 720B
templates
503.html 1KB
500.html 1KB
googleAnalytics.html 423B
map
mapPreview.html 939B
qqAnalytics.html 100B
recommendSystem
index.html 1KB
404.html 1KB
base.html 2KB
error.html 565B
passport
reg.html 2KB
login.html 830B
food
foodList.html 1KB
viewFood.html 2KB
addFood.html 3KB
footer.html 667B
navbar.html 2KB
wsgi.py 387B
urls.py 898B
settingsDevLocal.py.sample 191B
settings.py 3KB
static
js
bootstrap.js 57KB
bootstrap.min.js 27KB
geo.js 1KB
img
logo.png 1KB
logo.jpg 5KB
css
bootstrap.min.css 97KB
signin.css 714B
bootstrap-theme.css 14KB
bootstrap.css 120KB
bootstrap-theme.min.css 13KB
expand.css 653B
fonts
glyphicons-halflings-regular.svg 61KB
glyphicons-halflings-regular.ttf 40KB
glyphicons-halflings-regular.woff 23KB
glyphicons-halflings-regular.eot 20KB
.hgignore 91B
watchDog
__init__.py 0B
README.rst 904B
recommendSystem
__init__.py 0B
runtime
__init__.py 0B
recommendUtil.py 366B
urls.py 307B
views
__init__.py 0B
views.py 2KB
docs
idea.mm 7KB
idea.rst 2KB
manage.py 249B
lighttpd
11-simple-vhost-icokou-com.conf 849B
icokouCore
__init__.py 0B
runtime
__init__.py 0B
htmlContent.py 743B
geo.py 2KB
commonTools.py 360B
datetimeTools.py 6KB
qiniuUtil.py 847B
imageUtil.py 4KB
coreInfo.py 2KB
come.md 10B
passport
__init__.py 0B
runtime
__init__.py 0B
passportProfile.py 1KB
urls.py 334B
models
__init__.py 23B
model.py 3KB
views
__init__.py 0B
member.py 408B
account.py 5KB
food
__init__.py 0B
runtime
__init__.py 0B
foodUtil.py 5KB
urls.py 645B
models
__init__.py 21B
model.py 3KB
views
__init__.py 0B
views.py 7KB
geneticMap
__init__.py 0B
shop
__init__.py 0B
scripts
Dev_StartDjangoServer.bat 369B
StartIcokou.sh 401B
Dev_InitDB.py 336B
Dev_Syncdb.py 314B
UpgradeRelease.sh 381B
共 86 条
- 1
资源评论
天天501
- 粉丝: 617
- 资源: 5906
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Android Studio项目天气预报app程序源码+使用说明(高分项目)
- javaWeb会议管理系统源码数据库 MySQL源码类型 WebForm
- html+css+js的我要去旅游之重庆市
- 2023级张博.pptx
- M-QAM正交幅度调制在AWGN信道上的传输性能仿真MATLAB源代码
- 这是考试考试测试测试啊
- 大学生职业规划发展报告(1).pdf
- JAVA的SpringBoot+Shiro+mybatis教务管理系统源码数据库 MySQL源码类型 WebForm
- 【java毕业设计】旅游管理系统的设计与实现源码(springboot+vue+mysql+说明文档+LW).zip
- java订销管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功