├── .idea ├── .name ├── encodings.xml ├── vcs.xml ├── inspectionProfiles │ ├── profiles_settings.xml │ └── Project_Default.xml ├── modules.xml ├── codeStyleSettings.xml ├── misc.xml ├── dataSources.xml ├── AppBackend.iml └── dataSources.ids ├── AppBackend ├── __init__.py ├── wsgi.py ├── urls.py ├── views.py └── settings.py ├── appComment ├── __init__.py ├── migrations │ └── __init__.py ├── admin.py ├── urls.py ├── models.py ├── tests.py └── views.py ├── appScene ├── __init__.py ├── migrations │ ├── __init__.py │ └── 0001_initial.py ├── admin.py ├── urls.py ├── webUrls.py ├── tests.py ├── models.py ├── templates │ ├── sceneDetail.html │ └── addScene.html ├── views.py └── webViews.py ├── appUser ├── __init__.py ├── migrations │ ├── __init__.py │ ├── 0001_initial.py │ └── 0002_useravatar.py ├── admin.py ├── webUrls.py ├── urls.py ├── templates │ ├── applyAdminLists.html │ ├── applyGuideLists.html │ ├── signIn.html │ ├── signUp.html │ └── adminCenter.html ├── tests.py ├── models.py ├── webViews.py └── views.py ├── module ├── rongSDK │ ├── requirements.txt │ ├── __init__.py │ ├── LICENSE │ ├── README.md │ ├── test.py │ └── rong.py ├── __init__.py └── baiduPushSDK │ ├── lib │ ├── __init__.py │ ├── ChannelException.py │ ├── RequestCore.py │ └── valid.py │ ├── __init__.py │ ├── sdk.conf │ ├── sample │ └── sample.py │ └── Channel.py ├── application ├── __init__.py ├── exception.py └── function.py ├── static ├── css │ ├── addScene.css │ ├── sceneDetail.css │ ├── adminCenter.css │ ├── signIn.css │ └── signUp.css ├── media │ ├── avatar │ │ ├── defaultUserImage.png │ │ ├── 0CeW3zUuG8ETfYzA1459839210.jpg │ │ ├── 1z18eT0DAqKwYkN81459834022.jpg │ │ ├── 6zEGffnaEMwvotQj1460733665.jpg │ │ ├── 7LJEFhBxr4Y3lQNn1459835908.jpg │ │ ├── CHU8MiIB2AYCFBu01459861348.jpg │ │ ├── FLB2xhq3SaU0Q15B1459834892.jpg │ │ ├── JNnE81eNjHQhQDWA1459861727.jpg │ │ ├── MCPJlVPmr3dbd9nV1459863190.jpg │ │ ├── NMcDvQAkNZj4smxn1459863254.jpg │ │ ├── P67QzbyzxURtYhkd1459861257.jpg │ │ ├── TiK7ybyBT72pBheP1459861579.jpg │ │ ├── USukoS8BBNp6xoyv1459841178.jpg │ │ ├── XDJ3w2S3EpF0lmev1459833484.jpg │ │ ├── ZobkvqlUBk1maCNV1459839625.jpg │ │ ├── ZztIzvxu0wbgaLvD1459833879.jpg │ │ ├── cPcKBTv2boks1oeB1459861257.jpg │ │ ├── e3JL2Bxg03bVAs9z1459841013.jpg │ │ ├── iCTHCB4LFn0qsT361459862724.jpg │ │ ├── ia5RuyMEwIp3ODtf1459861551.jpg │ │ ├── mzbeaifP9lj6Frgj1459862795.jpg │ │ ├── od5phmPGvubLn6Kn1459833753.jpg │ │ ├── r0KgZxlfrfQpfdNB1459861428.jpg │ │ ├── suSSg70QdJyted5Z1459861624.jpg │ │ ├── uNE32yjlkJ6F2Vzt1459861257.jpg │ │ └── wsjqq5zpBaUUH4zp1459861670.jpg │ └── sceneImage │ │ ├── 1vc13aEopIkHDr6M1461992868.png │ │ ├── 2wvOCDrqo5zsThjp1461993336.png │ │ ├── Mvhagfqr2OUmO5KG1461993695.png │ │ ├── PPoaq5TD9UJx6DSK1462004064.png │ │ ├── VFEuu1JjHzb6F0tz1464069071.jpg │ │ ├── Yhnv6bvU2FnvN9dd1461996166.png │ │ ├── adcL7zF5gEnZe7xn1462003923.png │ │ ├── hyOmrSezSGIpcBc61461993508.png │ │ ├── q6H1HH6piqPkYL0X1462036911.jpg │ │ └── wCy2O8CJGxkWOdnN1462036638.jpg ├── bootstrap │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ └── js │ │ └── npm.js └── js │ ├── scene.js │ ├── applies.js │ ├── adminCenter.js │ └── home.js ├── db └── db.sqlite3 ├── manage.py ├── apache └── django.wsgi ├── Readme.md └── templates └── test.html /.idea/.name: -------------------------------------------------------------------------------- 1 | AppBackend -------------------------------------------------------------------------------- /AppBackend/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /appComment/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /appScene/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /appUser/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /appComment/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /appScene/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /appUser/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /module/rongSDK/requirements.txt: -------------------------------------------------------------------------------- 1 | requests>==2.1.0 -------------------------------------------------------------------------------- /module/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ -------------------------------------------------------------------------------- /application/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ -------------------------------------------------------------------------------- /module/baiduPushSDK/lib/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | lib 3 | """ 4 | -------------------------------------------------------------------------------- /module/rongSDK/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | -------------------------------------------------------------------------------- /static/css/addScene.css: -------------------------------------------------------------------------------- 1 | .addSceneLabel { 2 | color: #57857e; 3 | } -------------------------------------------------------------------------------- /module/baiduPushSDK/__init__.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | -------------------------------------------------------------------------------- /static/css/sceneDetail.css: -------------------------------------------------------------------------------- 1 | .sceneDetailLabel { 2 | color: #57857e; 3 | } -------------------------------------------------------------------------------- /db/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/db/db.sqlite3 -------------------------------------------------------------------------------- /appScene/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /appUser/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /appComment/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /static/media/avatar/defaultUserImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/defaultUserImage.png -------------------------------------------------------------------------------- /static/css/adminCenter.css: -------------------------------------------------------------------------------- 1 | .table-hover > tbody > tr:hover > td, 2 | .table-hover > tbody > tr:hover > th { 3 | background-color: #beb5f5; 4 | } -------------------------------------------------------------------------------- /static/media/avatar/0CeW3zUuG8ETfYzA1459839210.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/0CeW3zUuG8ETfYzA1459839210.jpg -------------------------------------------------------------------------------- /static/media/avatar/1z18eT0DAqKwYkN81459834022.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/1z18eT0DAqKwYkN81459834022.jpg -------------------------------------------------------------------------------- /static/media/avatar/6zEGffnaEMwvotQj1460733665.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/6zEGffnaEMwvotQj1460733665.jpg -------------------------------------------------------------------------------- /static/media/avatar/7LJEFhBxr4Y3lQNn1459835908.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/7LJEFhBxr4Y3lQNn1459835908.jpg -------------------------------------------------------------------------------- /static/media/avatar/CHU8MiIB2AYCFBu01459861348.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/CHU8MiIB2AYCFBu01459861348.jpg -------------------------------------------------------------------------------- /static/media/avatar/FLB2xhq3SaU0Q15B1459834892.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/FLB2xhq3SaU0Q15B1459834892.jpg -------------------------------------------------------------------------------- /static/media/avatar/JNnE81eNjHQhQDWA1459861727.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/JNnE81eNjHQhQDWA1459861727.jpg -------------------------------------------------------------------------------- /static/media/avatar/MCPJlVPmr3dbd9nV1459863190.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/MCPJlVPmr3dbd9nV1459863190.jpg -------------------------------------------------------------------------------- /static/media/avatar/NMcDvQAkNZj4smxn1459863254.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/NMcDvQAkNZj4smxn1459863254.jpg -------------------------------------------------------------------------------- /static/media/avatar/P67QzbyzxURtYhkd1459861257.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/P67QzbyzxURtYhkd1459861257.jpg -------------------------------------------------------------------------------- /static/media/avatar/TiK7ybyBT72pBheP1459861579.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/TiK7ybyBT72pBheP1459861579.jpg -------------------------------------------------------------------------------- /static/media/avatar/USukoS8BBNp6xoyv1459841178.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/USukoS8BBNp6xoyv1459841178.jpg -------------------------------------------------------------------------------- /static/media/avatar/XDJ3w2S3EpF0lmev1459833484.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/XDJ3w2S3EpF0lmev1459833484.jpg -------------------------------------------------------------------------------- /static/media/avatar/ZobkvqlUBk1maCNV1459839625.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/ZobkvqlUBk1maCNV1459839625.jpg -------------------------------------------------------------------------------- /static/media/avatar/ZztIzvxu0wbgaLvD1459833879.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/ZztIzvxu0wbgaLvD1459833879.jpg -------------------------------------------------------------------------------- /static/media/avatar/cPcKBTv2boks1oeB1459861257.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/cPcKBTv2boks1oeB1459861257.jpg -------------------------------------------------------------------------------- /static/media/avatar/e3JL2Bxg03bVAs9z1459841013.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/e3JL2Bxg03bVAs9z1459841013.jpg -------------------------------------------------------------------------------- /static/media/avatar/iCTHCB4LFn0qsT361459862724.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/iCTHCB4LFn0qsT361459862724.jpg -------------------------------------------------------------------------------- /static/media/avatar/ia5RuyMEwIp3ODtf1459861551.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/ia5RuyMEwIp3ODtf1459861551.jpg -------------------------------------------------------------------------------- /static/media/avatar/mzbeaifP9lj6Frgj1459862795.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/mzbeaifP9lj6Frgj1459862795.jpg -------------------------------------------------------------------------------- /static/media/avatar/od5phmPGvubLn6Kn1459833753.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/od5phmPGvubLn6Kn1459833753.jpg -------------------------------------------------------------------------------- /static/media/avatar/r0KgZxlfrfQpfdNB1459861428.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/r0KgZxlfrfQpfdNB1459861428.jpg -------------------------------------------------------------------------------- /static/media/avatar/suSSg70QdJyted5Z1459861624.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/suSSg70QdJyted5Z1459861624.jpg -------------------------------------------------------------------------------- /static/media/avatar/uNE32yjlkJ6F2Vzt1459861257.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/uNE32yjlkJ6F2Vzt1459861257.jpg -------------------------------------------------------------------------------- /static/media/avatar/wsjqq5zpBaUUH4zp1459861670.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/avatar/wsjqq5zpBaUUH4zp1459861670.jpg -------------------------------------------------------------------------------- /static/media/sceneImage/1vc13aEopIkHDr6M1461992868.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/1vc13aEopIkHDr6M1461992868.png -------------------------------------------------------------------------------- /static/media/sceneImage/2wvOCDrqo5zsThjp1461993336.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/2wvOCDrqo5zsThjp1461993336.png -------------------------------------------------------------------------------- /static/media/sceneImage/Mvhagfqr2OUmO5KG1461993695.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/Mvhagfqr2OUmO5KG1461993695.png -------------------------------------------------------------------------------- /static/media/sceneImage/PPoaq5TD9UJx6DSK1462004064.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/PPoaq5TD9UJx6DSK1462004064.png -------------------------------------------------------------------------------- /static/media/sceneImage/VFEuu1JjHzb6F0tz1464069071.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/VFEuu1JjHzb6F0tz1464069071.jpg -------------------------------------------------------------------------------- /static/media/sceneImage/Yhnv6bvU2FnvN9dd1461996166.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/Yhnv6bvU2FnvN9dd1461996166.png -------------------------------------------------------------------------------- /static/media/sceneImage/adcL7zF5gEnZe7xn1462003923.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/adcL7zF5gEnZe7xn1462003923.png -------------------------------------------------------------------------------- /static/media/sceneImage/hyOmrSezSGIpcBc61461993508.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/hyOmrSezSGIpcBc61461993508.png -------------------------------------------------------------------------------- /static/media/sceneImage/q6H1HH6piqPkYL0X1462036911.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/q6H1HH6piqPkYL0X1462036911.jpg -------------------------------------------------------------------------------- /static/media/sceneImage/wCy2O8CJGxkWOdnN1462036638.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/media/sceneImage/wCy2O8CJGxkWOdnN1462036638.jpg -------------------------------------------------------------------------------- /static/bootstrap/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/bootstrap/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /static/bootstrap/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/bootstrap/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /static/bootstrap/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/bootstrap/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /static/bootstrap/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangxuankai/AppBackend/HEAD/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /module/baiduPushSDK/sdk.conf: -------------------------------------------------------------------------------- 1 | [SDK] 2 | host = api.push.baidu.com 3 | apiKey = your_apiKey 4 | secretKey = your_secretKey 5 | deviceType = 3 6 | 7 | [curl] 8 | timeout = 5 9 | connecttimeout = 2 10 | 11 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "AppBackend.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /appScene/urls.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.conf.urls import url, patterns 5 | import views 6 | 7 | urlpatterns = patterns('', 8 | 9 | url(r'^lists/', views.scene_lists), 10 | url(r'^search/', views.scene_search), 11 | 12 | # 测试接口 13 | url(r'^test/', views.test) 14 | ) 15 | -------------------------------------------------------------------------------- /appScene/webUrls.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.conf.urls import url, patterns 5 | import webViews 6 | 7 | urlpatterns = patterns('', 8 | url(r'^add/', webViews.add), 9 | url(r'^update/', webViews.update), 10 | url(r'^updateStatus/', webViews.update_status), 11 | url(r'^query/', webViews.query) 12 | ) 13 | -------------------------------------------------------------------------------- /apache/django.wsgi: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 4 | path = BASE_DIR 5 | if path not in sys.path: 6 | sys.path.insert(0, BASE_DIR) 7 | os.environ['DJANGO_SETTINGS_MODULE'] = 'AppBackend.settings' 8 | 9 | from django.core.wsgi import get_wsgi_application 10 | application = get_wsgi_application() 11 | -------------------------------------------------------------------------------- /module/baiduPushSDK/lib/ChannelException.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | class ChannelException(Exception): 4 | def __init__(self, error_msg, error_code): 5 | self.error_msg = error_msg 6 | self.error_code = error_code 7 | 8 | def getLastErrorCode(self): 9 | return self.error_code 10 | 11 | def getLastErrorMsg(self): 12 | return self.error_msg 13 | -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 13 | -------------------------------------------------------------------------------- /AppBackend/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for AppBackend project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "AppBackend.settings") 12 | 13 | from django.core.wsgi import get_wsgi_application 14 | application = get_wsgi_application() 15 | -------------------------------------------------------------------------------- /appScene/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | import json 3 | # Create your tests here. 4 | 5 | from mongoengine import queryset 6 | 7 | # ll = [ 8 | # { 9 | # "name": 123, 10 | # "age": 654}, 11 | # { 12 | # "name": 789, 13 | # "age": 55 14 | # } 15 | # ] 16 | # l1 = json.dumps(ll) 17 | # 18 | # l2 = json.loads(l1) 19 | # print ll[0] 20 | # print l1 21 | # print l2[0] 22 | 23 | 24 | class A (object): 25 | 26 | def xx(self): 27 | return 'aa' 28 | 29 | a = A() 30 | print a.xx() 31 | 32 | -------------------------------------------------------------------------------- /static/bootstrap/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /appUser/webUrls.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.conf.urls import url, patterns 5 | import webViews 6 | 7 | urlpatterns = patterns('', 8 | url(r'^signIn/', webViews.sign_in), 9 | url(r'^signUp/', webViews.sign_up), 10 | url(r'^signOut/', webViews.sign_out), 11 | url(r'^adminCenter/', webViews.admin_center), 12 | url(r'^applyGuideLists/', webViews.apply_guide_lists), 13 | url(r'^applyAdminLists/', webViews.apply_admin_lists), 14 | url(r'^becomeGuide/', webViews.become_guide), 15 | url(r'^becomeAdmin/', webViews.become_admin), 16 | ) 17 | 18 | 19 | -------------------------------------------------------------------------------- /appComment/urls.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.conf.urls import url, patterns 5 | import views 6 | 7 | urlpatterns = patterns('', 8 | url(r'^commentScene/', views.comment_scene), 9 | url(r'^commentGuide/', views.comment_guide), 10 | 11 | url(r'^getSceneComment/', views.get_scene_comment), 12 | url(r'^getGuideComment/', views.get_guide_comment), 13 | 14 | # url(r'^commentSceneLists/', views.comment_scene_lists), 15 | # url(r'^commentGuideLists/', views.comment_guide_lists), 16 | 17 | # 测试接口 18 | url(r'^test1/', views.test1), 19 | url(r'^test/', views.test) 20 | ) 21 | -------------------------------------------------------------------------------- /AppBackend/urls.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.conf.urls import patterns, include, url 5 | import views 6 | 7 | urlpatterns = patterns('', 8 | # url(r'^home/visitorLists/', views.visitor_lists), 9 | # url(r'^home/guideLists/', views.guide_lists), 10 | 11 | # api接口 12 | url(r'^api/user/', include('appUser.urls')), 13 | url(r'^api/scene/', include('appScene.urls')), 14 | url(r'^api/comment/', include('appComment.urls')), 15 | 16 | # web接口 17 | url(r'^admin/home/', views.home), 18 | url(r'^admin/user/', include('appUser.webUrls')), 19 | url(r'^admin/scene/', include('appScene.webUrls')), 20 | 21 | ) 22 | -------------------------------------------------------------------------------- /appScene/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | from django.db import models, migrations 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='SceneImage', 15 | fields=[ 16 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), 17 | ('image', models.ImageField(upload_to=b'sceneImage')), 18 | ], 19 | options={ 20 | }, 21 | bases=(models.Model,), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /appUser/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | from django.db import models, migrations 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='ImageTest', 15 | fields=[ 16 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), 17 | ('image_avatar', models.ImageField(upload_to=b'photo')), 18 | ], 19 | options={ 20 | }, 21 | bases=(models.Model,), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /appUser/migrations/0002_useravatar.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | from django.db import models, migrations 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('appUser', '0001_initial'), 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='UserAvatar', 16 | fields=[ 17 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), 18 | ('user_avatar', models.ImageField(upload_to=b'avatar')), 19 | ], 20 | options={ 21 | }, 22 | bases=(models.Model,), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # AppBackend 2 | 3 | ==== 基于django的旅游app后台 4 | 5 | 安卓端: https://github.com/540871129/travelApp 6 | *** 7 | #### 说明: 8 | 9 | - 此旅游app项目是本人的毕业设计,包括了后台和安卓端,虽然接触python差不多有一年,但是没怎么系统的去学习,造成了python能力还是很水,-.-!毕业设计也是几个星期赶出来的,不过收获颇丰,现在已经毕业进入一家公司去走python的方向了。 10 | 11 | - 作为python的爱好者,希望这个项目可以对其他初学python的爱好者提供相应项目参考。里面的处理逻辑和数据库操作都是基本的。另外不足的地方是我把数据操作和处理逻辑都是合在views的函数中去处理,没有分层,这样是特别不好的,做的时间赶加上也不是很经常去做分层处理所以比较生疏,就懒的去做。希望其他借鉴的朋友改善。 12 | 13 | - 这个后台没有用django自带的admin,为什么呢?你懂得!然后就自己做了一个简单的admin管理,只是为了数据的录入而已,而不用跑去数据库插阿。 14 | 15 | 16 | -- by Daath 17 | 18 | ------------ 19 | 20 | ##### 用到的第三方sdk: 21 | 22 | - 融云即时通讯:获取聊天token 23 | - 百度云推送:登陆推送一个简易的消息 24 | 25 | 26 | ##### ORM框架: 27 | 28 | - django自带的ORM:为了偷懒,用来快速弄一个图片上传 29 | - MongoEngine 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | sqlite.xerial 6 | true 7 | true 8 | $PROJECT_DIR$/AppBackend/settings.py 9 | org.sqlite.JDBC 10 | jdbc:sqlite:$PROJECT_DIR$/db/db.sqlite3 11 | 12 | com.intellij.database.plan.ExplainPlanProvider.NullExplainPlanProvider 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | -------------------------------------------------------------------------------- /appUser/urls.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.conf.urls import url, patterns 5 | import views 6 | 7 | urlpatterns = patterns('', 8 | url(r'^signCheck/', views.sign_check), 9 | url(r'^signUp/', views.sign_up), 10 | url(r'^signIn/', views.sign_in), 11 | url(r'^signOut/', views.sign_out), 12 | url(r'^update/', views.update), 13 | url(r'^updateLocation/', views.update_location), 14 | url(r'^modifyPassword/', views.modify_password), 15 | url(r'^applyGuide/', views.apply_guide), 16 | url(r'^getGuideLists/', views.get_guide_lists), 17 | url(r'^getVisitorLists/', views.get_visitor_lists), 18 | url(r'^getVisitorInfo/', views.get_visitor_info), # 没用到 19 | url(r'^avatarUpload/', views.avatar_upload), 20 | url(r'^tokenReload/', views.token_reload), 21 | url(r'^saveChannelId/', views.save_channel_id), 22 | 23 | # 测试接口 24 | url(r'^test/', views.test), 25 | url(r'^imageTest/', views.image_test), 26 | 27 | 28 | ) 29 | -------------------------------------------------------------------------------- /appUser/templates/applyAdminLists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 申请管理员列表 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | {% for apply in applyAdmins %} 20 | 21 | 22 | 23 | 24 | 27 | 28 | {% endfor %} 29 | 30 | 31 |
管理员昵称管理员姓名管理员电话操作
{{ apply.nickname }}{{ apply.realName }}{{ apply.phone }} 25 | 26 |
32 |
33 | 34 | -------------------------------------------------------------------------------- /appUser/templates/applyGuideLists.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 申请导游列表 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {% for apply in applyGuides %} 21 | 22 | 23 | 24 | 25 | 28 | 29 | {% endfor %} 30 | 31 | 32 |
导游昵称导游姓名导游电话操作
{{ apply.nickname }}{{ apply.realName }}{{ apply.phone }} 26 | 27 |
33 |
34 | 35 | 36 | -------------------------------------------------------------------------------- /.idea/AppBackend.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | 29 | -------------------------------------------------------------------------------- /module/rongSDK/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 融云 Rong Cloud 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /appComment/models.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.db import models 5 | from mongoengine import * 6 | from mongoengine.base import BaseDocument 7 | import json 8 | import datetime 9 | import time 10 | # Create your models here. 11 | 12 | 13 | class SceneComment(Document): 14 | sceneId = StringField(required=True) 15 | userId = StringField(required=True) 16 | content = StringField(default=None) 17 | commentTime = DateTimeField(default=datetime.datetime.now()) 18 | 19 | def to_json(self): 20 | comment_json = BaseDocument.to_json(self) 21 | comment_dict = json.loads(comment_json) 22 | comment_dict['_id'] = comment_dict['_id']['$oid'] 23 | return json.dumps({"result": comment_dict}) 24 | 25 | 26 | class GuideComment(Document): 27 | guideId = StringField(required=True) 28 | userId = StringField(required=True) 29 | content = StringField(default=None) 30 | commentTime = DateTimeField(default=datetime.datetime.now()) 31 | 32 | def to_json(self): 33 | comment_json = BaseDocument.to_json(self) 34 | comment_dict = json.loads(comment_json) 35 | return json.dumps({"result": comment_dict}) -------------------------------------------------------------------------------- /static/css/signIn.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 40px; 3 | padding-bottom: 40px; 4 | background-color: #eee; 5 | } 6 | 7 | .form-signIn { 8 | max-width: 330px; 9 | padding: 15px; 10 | margin: 0 auto; 11 | } 12 | 13 | .form-signIn .form-signIn-heading { 14 | margin-bottom: 25px; 15 | text-align: center; 16 | color: #747285; 17 | } 18 | 19 | .form-signIn .checkbox { 20 | margin-bottom: 10px; 21 | } 22 | .form-signIn .checkbox { 23 | font-weight: normal; 24 | } 25 | .form-signIn .form-control { 26 | position: relative; 27 | height: auto; 28 | -webkit-box-sizing: border-box; 29 | -moz-box-sizing: border-box; 30 | box-sizing: border-box; 31 | padding: 10px; 32 | font-size: 16px; 33 | } 34 | .form-signIn .form-control:focus { 35 | z-index: 2; 36 | } 37 | .form-signIn input[type="text"] { 38 | margin-bottom: 5px; 39 | border-bottom-right-radius: 0; 40 | border-bottom-left-radius: 0; 41 | } 42 | .form-signIn input[type="password"] { 43 | margin-bottom: 10px; 44 | border-top-left-radius: 0; 45 | border-top-right-radius: 0; 46 | } 47 | 48 | .div-question { 49 | max-width: 330px; 50 | padding: 15px; 51 | margin: 0 auto; 52 | text-align: right; 53 | font-size: 16px; 54 | color: #747285; 55 | } 56 | -------------------------------------------------------------------------------- /static/css/signUp.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 40px; 3 | padding-bottom: 40px; 4 | background-color: #eee; 5 | } 6 | 7 | .form-signUp { 8 | max-width: 330px; 9 | padding: 15px; 10 | margin: 0 auto; 11 | } 12 | 13 | .form-signUp .form-signUp-heading { 14 | margin-bottom: 25px; 15 | text-align: center; 16 | color: #747285; 17 | } 18 | 19 | .form-signUp .checkbox { 20 | margin-bottom: 10px; 21 | } 22 | .form-signUp .checkbox { 23 | font-weight: normal; 24 | } 25 | .form-signUp .form-control { 26 | position: relative; 27 | height: auto; 28 | -webkit-box-sizing: border-box; 29 | -moz-box-sizing: border-box; 30 | box-sizing: border-box; 31 | padding: 10px; 32 | font-size: 16px; 33 | } 34 | .form-signUp .form-control:focus { 35 | z-index: 2; 36 | } 37 | .form-signUp input[type="text"] { 38 | margin-bottom: 10px; 39 | border-bottom-right-radius: 0; 40 | border-bottom-left-radius: 0; 41 | } 42 | .form-signUp input[type="password"] { 43 | margin-bottom: 10px; 44 | border-top-left-radius: 0; 45 | border-top-right-radius: 0; 46 | } 47 | 48 | .div-question { 49 | max-width: 330px; 50 | padding: 15px; 51 | margin: 0 auto; 52 | text-align: right; 53 | font-size: 16px; 54 | color: #747285; 55 | } 56 | -------------------------------------------------------------------------------- /appScene/models.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.db import models 5 | from mongoengine import * 6 | from mongoengine.base import BaseDocument 7 | import json 8 | 9 | # Create your models here. 10 | 11 | 12 | class Scene(Document): 13 | name = StringField(max_length=150) 14 | image = StringField(default="") 15 | description = StringField(default="") 16 | city = StringField(default="") 17 | province = StringField(default="") 18 | status = StringField(default="offline") # [online, offline] 上线 下线 19 | location = PointField(default=[0.0000000000, 0.0000000000]) # [经度Longitude, 纬度Latitude] 20 | 21 | def to_json(self): 22 | scene_json = BaseDocument.to_json(self) 23 | scene_dict = json.loads(scene_json) 24 | return json.dumps({"result": scene_dict}) 25 | 26 | def data_clean(self): 27 | scene_json = BaseDocument.to_json(self) 28 | scene_dict = json.loads(scene_json) 29 | scene_dict['id'] = scene_dict['_id']['$oid'] 30 | scene_dict['longitude'] = scene_dict['location']['coordinates'][0] 31 | scene_dict['latitude'] = scene_dict['location']['coordinates'][1] 32 | scene_dict.pop('_id') 33 | scene_dict.pop('location') 34 | return scene_dict 35 | 36 | 37 | class SceneImage(models.Model): 38 | image = models.ImageField(upload_to="sceneImage") 39 | -------------------------------------------------------------------------------- /AppBackend/views.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from appUser.models import User 5 | from django.http import * 6 | import json 7 | 8 | 9 | def home(request): 10 | return HttpResponseRedirect('/admin/user/adminCenter/') 11 | 12 | 13 | """ 暂时没用 """ 14 | def visitor_lists(request): 15 | if not request.session['user']: 16 | return JsonResponse({"message": "need login"}) 17 | if request.method == "POST": 18 | point = [ 19 | [116.4135540000, 39.9110130000], 20 | [112.4717700000, 23.0529840000], 21 | [112.9453330000, 28.2339710000], 22 | [113.3351650000, 23.1401800000], 23 | ] 24 | lists = User.objects(status="user", location__near=point[3], location__max_distance=10000) 25 | lists = json.loads(lists.to_json()) 26 | return JsonResponse({"result": lists}) 27 | raise Http404 28 | 29 | 30 | """ 暂时没用 """ 31 | def guide_lists(request): 32 | if not request.session['user']: 33 | return JsonResponse({"message": "need login"}) 34 | if request.method == "POST": 35 | point = [ 36 | [116.4135540000, 39.9110130000], 37 | [112.4717700000, 23.0529840000], 38 | [112.9453330000, 28.2339710000], 39 | [113.3351650000, 23.1401800000], 40 | ] 41 | lists = User.objects(status="guide", location__near=point[3], location__max_distance=10000) 42 | lists = json.loads(lists.to_json()) 43 | return JsonResponse({"result": lists}) 44 | raise Http404 45 | 46 | -------------------------------------------------------------------------------- /static/js/scene.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by daath on 16-4-29. 3 | */ 4 | 5 | 6 | function addSceneInfo() { 7 | $("form#add").ajaxSubmit({ 8 | url: '/admin/scene/add/', 9 | type: 'POST', 10 | success: function(data) { 11 | switch (data['msgCode']) { 12 | case 1000: 13 | alert("需要参数"); 14 | break; 15 | case 1008: 16 | alert("请给景区添加一张图片"); 17 | break; 18 | // 以上错误基本不会出现,因为前台已经 19 | case 1005: 20 | alert("更新的坐标有问题"); 21 | break; 22 | case 1007: 23 | alert("此景区名已经存在了"); 24 | break; 25 | case 5: 26 | alert("景区已经添加,请查看"); 27 | window.location.href = '/admin/user/adminCenter/'; 28 | break; 29 | } 30 | 31 | } 32 | }); 33 | return false; 34 | } 35 | 36 | 37 | function updateSceneInfo() { 38 | 39 | $.ajax({ 40 | url: '/admin/scene/update/', 41 | data: $("form#updateScene").serialize(), 42 | async: false, 43 | type: 'POST', 44 | dataType: 'json', 45 | success: function(data) { 46 | switch (data['msgCode']) { 47 | case 1000: 48 | alert("需要参数"); 49 | break; 50 | // 以上错误基本不会出现,因为前台已经 51 | case 1005: 52 | alert("更新的坐标有问题"); 53 | break; 54 | case 1007: 55 | alert("此景区名已经存在了"); 56 | break; 57 | case 6: 58 | alert("此景区信息已经更新"); 59 | break 60 | } 61 | } 62 | }); 63 | return false; 64 | } 65 | -------------------------------------------------------------------------------- /appUser/templates/signIn.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | {% if error %} 26 | 27 | {% endif %} 28 | 29 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 43 |
44 | 45 |
46 | 47 |
48 |

未有账号? 注册

49 |
50 | 51 |
52 | 53 | 54 | -------------------------------------------------------------------------------- /templates/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Login 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 31 | 32 | 33 |
34 | 35 |
36 | 37 |
38 | 39 |
40 | 41 |
42 | 43 | 44 | 45 | 46 | 47 |
48 | 51 |
52 | 53 |
54 | 55 |
56 | 57 |

The strongly emphasized word in this paragraph isred.

58 |

This subhead is also red.

59 |

The strongly emphasized word in this subhead isblue.

60 | -------------------------------------------------------------------------------- /static/js/applies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by daath on 16-4-30. 3 | */ 4 | 5 | 6 | function becomeGuide(id) { 7 | var guideId = id; 8 | $.ajax({ 9 | url: '/admin/user/becomeGuide/', 10 | data: {id: guideId}, 11 | async: false, 12 | type: 'POST', 13 | dataType: 'json', 14 | success: function(data) { 15 | switch (data['msgCode']) { 16 | case 1000: 17 | alert("需要参数"); 18 | break; 19 | // 以上错误一般不会出现 20 | case 9: 21 | alert("操作成功,此人已通过导游申请"); 22 | // 重新刷新 23 | $.ajax({ 24 | url: '/admin/user/applyGuideLists/', 25 | data: {}, 26 | async: false, 27 | type: 'GET', 28 | success: function(data) { 29 | $("#displayContent").html(data); 30 | 31 | } 32 | }); 33 | break; 34 | } 35 | 36 | } 37 | }); 38 | } 39 | 40 | 41 | function becomeAdmin(id) { 42 | var adminId = id; 43 | $.ajax({ 44 | url: '/admin/user/becomeAdmin/', 45 | data: {id: adminId}, 46 | async: false, 47 | type: 'POST', 48 | dataType: 'json', 49 | success: function(data) { 50 | switch (data['msgCode']) { 51 | case 1000: 52 | alert("需要参数"); 53 | break; 54 | // 以上错误一般不会出现 55 | case 10: 56 | alert("操作成功,此人已通过管理员申请"); 57 | // 重新刷新 58 | $.ajax({ 59 | url: '/admin/user/applyAdminLists/', 60 | data: {}, 61 | async: false, 62 | type: 'GET', 63 | success: function(data) { 64 | $("#displayContent").html(data); 65 | 66 | } 67 | }); 68 | break; 69 | } 70 | 71 | } 72 | }); 73 | } 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /appUser/templates/signUp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 注册 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
48 | 49 |
50 |

已有账号? 登录

51 |
52 | 53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /module/baiduPushSDK/sample/sample.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # _*_ coding: UTF-8 _*_ 3 | 4 | import sys 5 | import time 6 | import json 7 | sys.path.append("..") 8 | 9 | from module.baiduPushSDK.Channel import * 10 | 11 | # channel_id = '3812879988317808329' #android 12 | channel_id = '4244463061771694833' #android 13 | # channel_id = '3812879988317808329' #android 14 | 15 | msg = '{"title":"Message from Push","description":"hello world"}' 16 | #msg_ios = '{"aps":{"alert":"iOS Message from Push","sound":"","badge":1},"key1":"value1","key2":"value2"}' 17 | opts = {'msg_type':1, 'expires':300} 18 | 19 | c = Channel() 20 | 21 | 22 | 23 | # travelApp 24 | c.setApiKey('ljYNLqCZdMzY6DsyCyzXEgdss8YmtOFL') 25 | c.setSecretKey('8sGfm4SSDL1KFuLaPyrdHqNs9Qp9nPkG') 26 | 27 | test_msg = { 28 | 'title': '这是一个测试的push', 29 | 'description': '只是个测试', 30 | 'custom_content': { 31 | 'key1': 'value1', 32 | 'key2': 'value2', 33 | 'key3': 'value3' 34 | }, 35 | } 36 | push_msg = { 37 | 'title': '系统通知', 38 | 'description': '距离您5000米最近的景区是:' + 'aa', 39 | 'custom_content': { 40 | 'content': 'value1', 41 | }, 42 | } 43 | try: 44 | ret = c.pushMsgToSingleDevice(channel_id, json.dumps(push_msg), opts) 45 | print 'ret: ', 46 | print ret 47 | print c.getRequestId() 48 | except ChannelException as e: 49 | print '[code]', 50 | print e.getLastErrorCode() 51 | print '[msg]', 52 | print e.getLastErrorMsg() 53 | print '[request id]', 54 | print c.getRequestId() 55 | 56 | # try: 57 | # ret = c.pushMsgToAll(msg, opts) 58 | # print 'ret: ', 59 | # print ret 60 | # print c.getRequestId() 61 | # except ChannelException as e: 62 | # print '[code]', 63 | # print e.getLastErrorCode() 64 | # print '[msg]', 65 | # print e.getLastErrorMsg() 66 | # print '[request id]', 67 | # print c.getRequestId() 68 | 69 | # try: 70 | # ret = c.pushMsgToTag('test_tag', msg, 1, opts) 71 | # print 'ret: ', 72 | # print ret 73 | # print '[request id]', 74 | # print c.getRequestId() 75 | # except ChannelException as e: 76 | # print '[code]', 77 | # print e.getLastErrorCode() 78 | # print '[msg]', 79 | # print e.getLastErrorMsg() 80 | # print '[request id]', 81 | # print c.getRequestId() 82 | 83 | -------------------------------------------------------------------------------- /module/rongSDK/README.md: -------------------------------------------------------------------------------- 1 | server-sdk-python 2 | ================= 3 | 4 | Rong Cloud Server SDK in Python. 5 | 6 | # 更新说明 7 | 8 | * 20150206 9 | * 去掉可能会导致SSL验证失败的代码 10 | * 更改环境变量名称,老的环境变量名称在某些操作系统中无法被识别 11 | 12 | 13 | # 依赖说明 14 | * 本sdk 依赖于requests 15 | 16 | # 使用说明 17 | 18 | ``` 19 | import os 20 | import json 21 | import unittest 22 | import logging 23 | 24 | from rong import ApiClient 25 | 26 | app_key = "" 27 | app_secret = "" 28 | 29 | #您应该将key 和 secret 保存在服务器的环境变量中 30 | os.environ.setdefault('rongcloud_app_key', app_key) 31 | os.environ.setdefault('rongcloud_app_secret', app_secret) 32 | 33 | logging.basicConfig(level=logging.INFO) 34 | 35 | api = ApiClient() 36 | ``` 37 | 38 | ##通用方法 39 | 40 | * 对于单值参数调用 41 | 42 | ``` 43 | token = api.call_api( 44 | action="/user/getToken", 45 | params={ 46 | "userId": "user-id1", 47 | "name":"username1", 48 | "portraitUri":"p1" 49 | } 50 | ) 51 | ``` 52 | 53 | * 对于多值参数调用 54 | 55 | ``` 56 | addblack = api.call_api( 57 | action="/user/blacklist/add", 58 | params={ 59 | "userId": "user-id1", 60 | "blackUserId":["user-id1","user-id2","user-id3"] 61 | } 62 | ) 63 | ``` 64 | 如果一个参数需要传递多个值, 可以直接传递list 类型 65 | 66 | 67 | * 对于json类型参数 68 | 69 | ``` 70 | publish = api.call_api( 71 | action="/message/private/publish", 72 | params={ 73 | "fromUserId": "user-id1", 74 | "toUserId": "user-id8", 75 | "objectName": "RC:ContactNtf", 76 | "content": json.dumps( 77 | { 78 | "content":"this is content", 79 | "targetUserId":"user-id8", 80 | "sourceUserId":"user-id1", 81 | "message": "fydtest", 82 | "operation": "Request", 83 | "extra":json.dumps( 84 | { 85 | "title":"this is title", 86 | "name":"this is name" 87 | } 88 | ) 89 | }), 90 | 91 | "pushContent": "this is push content", 92 | "pushData": "this is push data" 93 | } 94 | ) 95 | ``` 96 | 97 | ## 封装方法 98 | 99 | 如果您觉得通过 call_api 方法调用不够方便,可参阅 test.py 中的单元测试代码。 100 | 101 | 我们对 call_api 进行了更进一步的封装,但是不建议您在生产环境中使用。 -------------------------------------------------------------------------------- /appUser/tests.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | import os 5 | 6 | from django.test import TestCase 7 | 8 | # Create your tests here. 9 | 10 | # from models import User 11 | from mongoengine import connect 12 | import json 13 | import random 14 | import time 15 | # x = '' 16 | # if not x: 17 | # print 12 18 | # else: 19 | # print 32 20 | 21 | # connect('travelDB', username='root', password='root', authentication_source='admin') 22 | # # is_exist = User.objects.get(account="D") 23 | # try: 24 | # is_exist = User.objects(account="Daath").filter() 25 | # except User.DoesNotExist: 26 | # is_exist = None 27 | # 28 | # print is_exist 29 | # if not is_exist: 30 | # print 11 31 | 32 | # 33 | # def random_str(): 34 | # str1 = '' 35 | # chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' 36 | # for i in xrange(22): 37 | # str1 += random.choice(chars) 38 | # 39 | # str1 += str(int(time.time())) 40 | # return str1 41 | # 42 | # xx = random_str() 43 | # print len(xx) 44 | # BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 45 | # STATIC_ROOT = os.path.join(BASE_DIR, 'static') 46 | # MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media') 47 | # STATICFILES_DIRS = ( 48 | # ("media", os.path.join(STATIC_ROOT, 'media')), 49 | # ) 50 | # 51 | # DATABASE_NAME = os.path.join(BASE_DIR, 'db/db.sqlite3') 52 | # print DATABASE_NAME 53 | # # print BASE_DIR 54 | # # print MEDIA_ROOT 55 | # # print STATIC_ROOT 56 | # # print STATICFILES_DIRS 57 | # DATABASES = { 58 | # 'default': { 59 | # 'ENGINE': 'django.db.backends.sqlite3', 60 | # # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 61 | # # 'NAME': '/home/daath/PycharmProjects/AppBackend/db/db.sqlite3', 62 | # 'NAME': os.path.join(BASE_DIR, 'db/db.sqlite3'), 63 | # } 64 | # } 65 | # print DATABASES 66 | 67 | import os 68 | import json 69 | import unittest 70 | import logging 71 | 72 | from module.rongSDK.rong import ApiClient 73 | 74 | app_key = "6tnym1brnoca7" 75 | app_secret = "fHF6HyP2BsswbU" 76 | 77 | # 您应该将key 和 secret 保存在服务器的环境变量中 78 | os.environ.setdefault('rongcloud_app_key', app_key) 79 | os.environ.setdefault('rongcloud_app_secret', app_secret) 80 | 81 | logging.basicConfig(level=logging.INFO) 82 | 83 | api = ApiClient() 84 | user = { 85 | 'user_id': '56dc4a407a74e720e5d3ce24', 86 | 'name': 'Daath', 87 | 'portrait_uri': 'http://192.168.0.106:8003/static/media/avatar/NMcDvQAkNZj4smxn1459863254.jpg' 88 | } 89 | Token = api.user_get_token(**user) 90 | 91 | print Token 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /appUser/models.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.db import models 5 | from mongoengine import * 6 | from mongoengine.base import BaseDocument 7 | from application.exception import prefURL 8 | import json 9 | 10 | # Create your models here. 11 | 12 | defaultAvatar = prefURL['ImageURL'] + 'avatar/defaultUserImage.png' 13 | 14 | # app用户表 15 | class User(Document): 16 | account = StringField(required=True) 17 | password = StringField(required=True) 18 | avatar = StringField(default=defaultAvatar) 19 | nickname = StringField(max_length=50, default="") 20 | realName = StringField(max_length=50, default="") 21 | description = StringField(max_length=150, default="") 22 | phone = StringField(max_length=11, default="") 23 | # ['user', 'applyGuide', 'guide'] 用户, 导游申请, 导游 24 | status = StringField(default="user") 25 | location = PointField(default=[0.0000000000, 0.0000000000]) 26 | token = StringField(default="") 27 | channelId = StringField(default="") 28 | 29 | def to_json(self): 30 | user_json = BaseDocument.to_json(self) 31 | user_dict = json.loads(user_json) 32 | user_dict['_id'] = user_dict['_id']['$oid'] 33 | user_dict['location'] = user_dict['location']['coordinates'] 34 | user_dict.pop('password') 35 | return json.dumps({"result": user_dict}) 36 | 37 | 38 | # 管理后台管理员表 39 | class AdminUser(Document): 40 | account = StringField(required=True) 41 | password = StringField(required=True) 42 | avatar = StringField(default=defaultAvatar) 43 | nickname = StringField(max_length=50, default="") 44 | realName = StringField(max_length=50, required=True) 45 | description = StringField(max_length=150, default="") 46 | phone = StringField(max_length=11, default="") 47 | # ['applyAdmin', 'admin'] 管理员申请, 管理员 48 | status = StringField(default="applyAdmin") 49 | location = PointField(default=[0.0000000000, 0.0000000000]) 50 | token = StringField(default="") 51 | channelId = StringField(default="") 52 | 53 | def to_json(self): 54 | admin_user_json = BaseDocument.to_json(self) 55 | admin_user_dict = json.loads(admin_user_json) 56 | admin_user_dict['_id'] = admin_user_dict['_id']['$oid'] 57 | admin_user_dict['location'] = admin_user_dict['location']['coordinates'] 58 | admin_user_dict.pop('password') 59 | return json.dumps({"result": admin_user_dict}) 60 | 61 | 62 | """ 63 | 通过Django的ORM来存储图片,然后在将图片地址给予用户表的头像字段 64 | """ 65 | class UserAvatar(models.Model): 66 | user_avatar = models.ImageField(upload_to="avatar") 67 | 68 | 69 | class ImageTest(models.Model): 70 | image_avatar = models.ImageField(upload_to="photo") 71 | 72 | 73 | -------------------------------------------------------------------------------- /static/js/adminCenter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by daath on 16-4-29. 3 | */ 4 | 5 | function signOut() { 6 | window.location.href = '/admin/user/signOut/'; 7 | } 8 | 9 | function toAdminCenter() { 10 | window.location.href = '/admin/user/adminCenter/' 11 | } 12 | 13 | function toAddScene() { 14 | $.ajax({ 15 | url: '/admin/scene/add/', 16 | data: {}, 17 | async: false, 18 | type: 'GET', 19 | success: function(data) { 20 | $("#displayContent").html(data) 21 | } 22 | }) 23 | } 24 | 25 | function toQueryScene(id) { 26 | if (!id) { 27 | return; 28 | } 29 | var sceneId = id; 30 | $.ajax({ 31 | url: '/admin/scene/query/', 32 | data: { 33 | id: sceneId 34 | }, 35 | async: false, 36 | type: 'GET', // 获取网页默认GET方法 37 | success: function(data) { 38 | $("#displayContent").html(data); 39 | } 40 | }); 41 | } 42 | 43 | function toApplyGuideLists() { 44 | $("li#titleScene").removeClass("active"); 45 | $("li#titleApply").addClass("active"); 46 | $.ajax({ 47 | url: '/admin/user/applyGuideLists/', 48 | data: {}, 49 | async: false, 50 | type: 'GET', 51 | success: function(data) { 52 | $("#displayContent").html(data); 53 | 54 | } 55 | }); 56 | } 57 | 58 | function toApplyAdminLists() { 59 | $("li#titleScene").removeClass("active"); 60 | $("li#titleApply").addClass("active"); 61 | $.ajax({ 62 | url: '/admin/user/applyAdminLists/', 63 | data: {}, 64 | async: false, 65 | type: 'GET', 66 | success: function(data) { 67 | $("#displayContent").html(data); 68 | 69 | } 70 | }); 71 | } 72 | 73 | function updateStatus(id, status) { 74 | $.ajax({ 75 | url: '/admin/scene/updateStatus/', 76 | data: { 77 | id: id, 78 | status: status 79 | }, 80 | async: false, 81 | type: 'POST', 82 | dataType: 'json', 83 | success: function(data) { 84 | switch (data['msgCode']) { 85 | case 1000: 86 | alert("需要参数"); 87 | break; 88 | // 以上错误一般不会出现 89 | case 1009: 90 | alert("参数status的值有问题"); 91 | break; 92 | case 7: 93 | alert("该景区上线成功"); 94 | toAdminCenter(); 95 | break; 96 | case 8: 97 | alert("该景区下线了"); 98 | toAdminCenter(); 99 | break; 100 | } 101 | 102 | } 103 | }); 104 | } -------------------------------------------------------------------------------- /appScene/templates/sceneDetail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 景区详情 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 |
18 | 19 |
20 | 21 |
22 |
23 |
24 | 25 |
26 | 27 |
28 |
29 |
30 | 31 |
32 | 33 |
34 |
35 |
36 | 37 |
38 | 39 |
40 |
41 |
42 | 43 |
44 | 45 |
46 |
47 |
48 | 49 |
50 | 51 |
52 |
53 |
54 | 55 | 取消 56 |
57 |
58 |
59 | 60 | 61 | -------------------------------------------------------------------------------- /appScene/templates/addScene.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 增加景区 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |
17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 |
28 |
29 | 30 |
31 | 32 |
33 |
34 |
35 | 36 |
37 | 38 |
39 |
40 |
41 | 42 |
43 | 44 |
45 |
46 |
47 | 48 |
49 | 50 |
51 |
52 |
53 | 54 |
55 | 56 |
57 |
58 |
59 | 60 | 取消 61 |
62 |
63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /application/exception.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | prefURL = { 5 | # 以下地址根据你服务器的ip而定 6 | 'ImageURL': 'http://192.168.2.107:8099/static/media/' # django服务器 7 | # 'ImageURL': 'http://192.168.0.106:8003/static/media/' # apache2服务器 8 | } 9 | 10 | """ 自定义的返回结果集 """ 11 | 12 | resultMsg = { 13 | 'NeedParameter': { 14 | 'error': True, 15 | 'msgCode': 1000, 16 | 'msg': "need parameter" 17 | }, 18 | 'ExistUser': { 19 | 'error': True, 20 | 'msgCode': 1001, 21 | 'msg': "exist user" 22 | }, 23 | 'NotExistUser': { 24 | 'error': True, 25 | 'msgCode': 1002, 26 | 'msg': "no exist user" 27 | }, 28 | 'ErrorPassword': { 29 | 'error': True, 30 | 'msgCode': 1003, 31 | 'msg': "error password" 32 | }, 33 | 'NeedLogin': { 34 | 'error': True, 35 | 'msgCode': 1004, 36 | 'msg': "need login" 37 | }, 38 | 'CoordinatesError': { 39 | 'error': True, 40 | 'msgCode': 1005, 41 | 'msg': "coordinates error" 42 | }, 43 | 'AdminAuthorityApplying': { 44 | 'error': True, 45 | 'msgCode': 1006, 46 | 'msg': "admin authority applying" 47 | }, 48 | 'ExistScene': { 49 | 'error': True, 50 | 'msgCode': 1007, 51 | 'msg': "exist scene" 52 | }, 53 | 'NeedSceneImage': { 54 | 'error': True, 55 | 'msgCode': 1008, 56 | 'msg': "need scene image" 57 | }, 58 | 'StatusValueError': { 59 | 'error': True, 60 | 'msgCode': 1009, 61 | 'msg': "status value error" 62 | }, 63 | 'SignUpSuccess': { 64 | 'error': False, 65 | 'msgCode': 0, 66 | 'msg': "sign up success" 67 | }, 68 | 'SignOut': { 69 | 'error': False, 70 | 'msgCode': 1, 71 | 'msg': "sign out" 72 | }, 73 | 'SignCheckSuccessful': { 74 | 'error': False, 75 | 'msgCode': 2, 76 | 'msg': "sign check successful" 77 | }, 78 | 'SaveChannelId': { 79 | 'error': False, 80 | 'msgCode': 3, 81 | 'msg': "save channelId successful" 82 | }, 83 | 'SignInSuccess': { 84 | 'error': False, 85 | 'msgCode': 4, 86 | 'msg': "sign In success" 87 | }, 88 | 'addSceneSuccess': { 89 | 'error': False, 90 | 'msgCode': 5, 91 | 'msg': "add scene success" 92 | }, 93 | 'updateSceneSuccess': { 94 | 'error': False, 95 | 'msgCode': 6, 96 | 'msg': "update scene success" 97 | }, 98 | 'onlineSceneSuccessful': { 99 | 'error': False, 100 | 'msgCode': 7, 101 | 'msg': "online scene success" 102 | }, 103 | 'offlineSceneSuccessful': { 104 | 'error': False, 105 | 'msgCode': 8, 106 | 'msg': "offline scene success" 107 | }, 108 | 'BecomeGuide': { 109 | 'error': False, 110 | 'msgCode': 9, 111 | 'msg': "become guide" 112 | }, 113 | 'BecomeAdmin': { 114 | 'error': False, 115 | 'msgCode': 10, 116 | 'msg': "become admin" 117 | }, 118 | } 119 | -------------------------------------------------------------------------------- /appComment/tests.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | from django.test import TestCase 3 | 4 | # Create your tests here. 5 | 6 | 7 | import datetime 8 | import json 9 | import time 10 | 11 | data = { 12 | "name": datetime.datetime.now().now() 13 | } 14 | 15 | # print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(1457438026727)) 16 | 17 | # dara_json = json.dumps() 18 | # 19 | # print json.loads(dara_json) 20 | # 21 | l1 = [ 22 | u'56de86d77a74e763f3b29186', 23 | u'56de86d77a74e763f3b29186', 24 | u'56de86d77a74e763f3b29186', 25 | u'56de86d77a74e763f3b29186', 26 | u'56de86d77a74e763f3b29186', 27 | u'56de86d77a74e763f3b29186' 28 | ] 29 | 30 | 31 | # print list(set(l1)) 32 | # 33 | # list_string1 = ['123','abc','abc','cde'] 34 | # list_string2 = ['1','ac','bc','ce'] 35 | 36 | 37 | # list_string = set(list_string) 38 | # print zip(list_string1, list_string2) 39 | 40 | 41 | # d1 = [ 42 | # {u'sceneId': u'56de86d77a74e763f3b29186', u'content': u'\u6211\u5f88\u5f00\u5fc3\u6765\u5230\u5f20\u5bb6\u754c', u'_id': {u'$oid': u'56de9cf07a74e708f4bf842f'}, u'userId': u'56dc4a407a74e720e5d3ce24', u'commentTime': {u'$date': 1457458544670}}, 43 | # {u'sceneId': u'56de882ae82017c1a0556b01', u'content': u'\u6211\u5f88\u5f00\u5fc3\u6765\u5230jiuzhaigou', u'_id': {u'$oid': u'56deba757a74e71e7dc54b53'}, u'userId': u'56dc4a407a74e720e5d3ce24', u'commentTime': {u'$date': 1457466101701}}, 44 | # {u'sceneId': u'56de88437a74e76673e2e7b6', u'content': u'\u6211\u5f88\u5f00\u5fc3\u6765\u5230\u51e4\u51f0\u5c71', u'_id': {u'$oid': u'56debb1c7a74e71f34b0b8c0'}, u'userId': u'56dc4a407a74e720e5d3ce24', u'commentTime': {u'$date': 1457437444028}}, 45 | # {u'sceneId': u'56de86d77a74e763f3b29186', u'content': u'\u6211\u5f88\u5f00\u5fc3\u6765\u5230\u5f20\u5bb6\u754c', u'_id': {u'$oid': u'56debb4d7a74e7202b927b5a'}, u'userId': u'56dc4a407a74e720e5d3ce24', u'commentTime': {u'$date': 1457466317555}}, 46 | # {u'sceneId': u'56de86d77a74e763f3b29186', u'content': u'\u6211\u5f88\u5f00\u5fc3\u6765\u5230\u5f20\u5bb6\u754c', u'_id': {u'$oid': u'56debb847a74e720b9d82ed8'}, u'userId': u'56dc4a407a74e720e5d3ce24', u'commentTime': {u'$date': 1457437571990}}, 47 | # {u'sceneId': u'56de86d77a74e763f3b29186', u'content': u'\u6211\u5f88\u5f00\u5fc3\u6765\u5230\u5f20\u5bb6\u754c', u'_id': {u'$oid': u'56debd4a7a74e72208f2eef3'}, u'userId': u'56dc4a407a74e720e5d3ce24', u'commentTime': {u'$date': 1457438026727}} 48 | # ] 49 | # 50 | # d2 = [ 51 | # {"province": "\u6e56\u5357\u7701", "city": "\u5f20\u5bb6\u754c", "name": "\u5f20\u5bb6\u754c", "image": "", "_id": {"$oid": "56de86d77a74e763f3b29186"}, "description": "\u8fd9\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u5730\u65b9"}, 52 | # {"province": "\u56db\u5ddd\u7701", "city": "\u4e5d\u5be8\u6c9f\u53bf", "name": "\u4e5d\u5be8\u6c9f", "image": "", "_id": {"$oid": "56de882ae82017c1a0556b01"}, "description": "\u8fd9\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u5730\u65b9"}, 53 | # {"province": "\u5e7f\u4e1c\u7701", "city": "\u5e7f\u5dde", "name": "\u51e4\u51f0\u5c71", "image": "", "_id": {"$oid": "56de88437a74e76673e2e7b6"}, "description": "\u51e4\u51f0\u51fa\u73b0\u7684\u5730\u65b9"} 54 | # ] 55 | # 56 | # list1 = [1, 2, 3] 57 | # list2 = [1, 3, 3] 58 | # 59 | # 60 | # def x(m, n): 61 | # if m == n: 62 | # return m + n 63 | # 64 | # print map(x, list1, list2) 65 | # print data 66 | # data['aa'] = 1213 67 | # print data 68 | # x = { 69 | # "name": 123, 70 | # "age": 456 71 | # } 72 | # print x 73 | # x.pop("name") 74 | # print x 75 | 76 | L = ['Adam', 'Lisa', 'Bart', 'Paul'] 77 | print L[-2: 0] 78 | 79 | str1 = '鱼C资源打包' 80 | 81 | print str1[-55: -42] 82 | def xx(): 83 | pass -------------------------------------------------------------------------------- /application/function.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.http import * 5 | from django.shortcuts import * 6 | from .exception import resultMsg 7 | from module.rongSDK.rong import ApiClient 8 | from appUser.models import User 9 | from appScene.models import Scene 10 | from module.baiduPushSDK.Channel import * 11 | import random 12 | import time 13 | import json 14 | """ 自定义的功能函数 """ 15 | 16 | 17 | def id_replace(l): 18 | l['_id'] = l['_id']['$oid'] 19 | 20 | 21 | def more_replace(l): 22 | l['_id'] = l['_id']['$oid'] 23 | l['location'] = l['location']['coordinates'] 24 | 25 | 26 | def web_id_replace(l): 27 | l['id'] = l['_id']['$oid'] 28 | l.pop('_id') 29 | 30 | 31 | def login_auth(function): 32 | def wrapper(request): 33 | if request.session.get('currentUser', None): 34 | return function(request) 35 | return JsonResponse(resultMsg['NeedLogin']) 36 | return wrapper 37 | 38 | 39 | def admin_login_auth(function): 40 | def wrapper(request): 41 | if request.session.get('currentAdmin', None): 42 | return function(request) 43 | return render(request, 'signIn.html', {'error': '登录已失效,请重新登录'}) 44 | return wrapper 45 | 46 | 47 | def produce_image_name(length=16): 48 | name = '' 49 | chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' 50 | for i in xrange(length): 51 | name += random.choice(chars) 52 | # 加上时间戳  53 | name += str(int(time.time())) 54 | return name 55 | 56 | 57 | def process_token(**kw): 58 | api = ApiClient() 59 | print kw 60 | if kw['token']: 61 | params = { 62 | 'user_id': kw['_id'], 63 | 'name': kw['nickname'], 64 | 'portrait_uri': kw['avatar'] 65 | } 66 | response = api.user_refresh(**params) 67 | if response['code'] == 200: 68 | return 69 | else: 70 | params = { 71 | 'user_id': kw['_id'], 72 | 'name': kw['nickname'], 73 | 'portrait_uri': kw['avatar'] 74 | } 75 | response = api.user_get_token(**params) 76 | if response['code'] == 200: 77 | user = User.objects(id=kw['_id']).get() 78 | user.update(token=response['token']) 79 | return 80 | print response 81 | return 82 | 83 | 84 | def push_nearly_scene(**kw): 85 | channel_id = kw['channelId'].encode('utf-8') 86 | coordinates = kw['coordinates'] 87 | lists = Scene.objects(status='online', location__near=coordinates, location__max_distance=5000).all()[:1] 88 | lists = json.loads(lists.to_json()) 89 | print channel_id, coordinates 90 | push_msg = { 91 | 'title': '系统通知', 92 | 'custom_content': { 93 | 'content': 'value1', 94 | }, 95 | } 96 | if lists: 97 | push_msg['description'] = '距离您5000米最近的景区是:' + lists[0]['name'].encode('utf-8') 98 | else: 99 | push_msg['description'] = '距离您5000米暂无景区' 100 | opts = {'msg_type':1, 'expires':300} 101 | c = Channel() 102 | # 这里设置云推送的key,务必跟app端的所用云推送key一致 103 | c.setApiKey('ljYNLqCZdMzY6DsyCyzXEgdss8YmtOFL') 104 | c.setSecretKey('8sGfm4SSDL1KFuLaPyrdHqNs9Qp9nPkG') 105 | try: 106 | ret = c.pushMsgToSingleDevice(channel_id, json.dumps(push_msg), opts) 107 | print 'ret: ', 108 | print ret 109 | print c.getRequestId() 110 | except ChannelException as e: 111 | print '[code]', 112 | print e.getLastErrorCode() 113 | print '[msg]', 114 | print e.getLastErrorMsg() 115 | print '[request id]', 116 | print c.getRequestId() 117 | -------------------------------------------------------------------------------- /appScene/views.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.http import * 5 | from mongoengine import Q 6 | 7 | from .models import Scene 8 | import json 9 | from application.function import id_replace, more_replace 10 | from application.exception import resultMsg 11 | 12 | # Create your views here. 13 | 14 | 15 | """ 16 | /scene/lists/ 获得景区列表 17 | Method: POST 18 | Parameter: | skip limit latitude longitude 19 | JSON: { 20 | "result": [ 21 | { 22 | "province": "湖南省", 23 | "city": "张家界", 24 | "name": "张家界", 25 | "image": "http://photocdn.sohu.com/20150720/mp23435940_1437361439743_3.jpeg", 26 | "_id": "56de86d77a74e763f3b29186", 27 | "description": "这是一个很好的地方" 28 | }, 29 | ... 30 | ] 31 | } 32 | """ 33 | def scene_lists(request): 34 | if request.method == "POST": 35 | try: 36 | skip = int(request.POST.get('skip', 0)) 37 | except (TypeError, ValueError) as e: 38 | skip = 0 39 | try: 40 | limit = int(request.POST.get('limit', 5)) 41 | except (TypeError, ValueError) as e: 42 | limit = 5 43 | # 查看是否有坐标参数 44 | try: 45 | latitude = float(request.POST.get('latitude', None)) 46 | longitude = float(request.POST.get('longitude', None)) 47 | except: 48 | return JsonResponse(resultMsg['CoordinatesError']) 49 | coordinates = [longitude, latitude] # 做成坐标组 50 | lists = Scene.objects(status='online', location__near=coordinates, location__max_distance=50000).all()[skip: limit] 51 | lists = json.loads(lists.to_json()) 52 | map(more_replace, lists) 53 | return JsonResponse({"result": lists}) 54 | raise Http404 55 | 56 | 57 | """ 58 | /scene/search/ 搜索景区 59 | Method: POST 60 | Parameter: | skip limit latitude longitude 61 | JSON: { 62 | "result": [ 63 | { 64 | "province": "湖南省", 65 | "city": "张家界", 66 | "name": "张家界", 67 | "image": "http://photocdn.sohu.com/20150720/mp23435940_1437361439743_3.jpeg", 68 | "_id": "56de86d77a74e763f3b29186", 69 | "description": "这是一个很好的地方" 70 | }, 71 | ... 72 | ] 73 | } 74 | """ 75 | def scene_search(request): 76 | if request.method == "POST": 77 | try: 78 | skip = int(request.POST.get('skip', 0)) 79 | except TypeError: 80 | skip = 0 81 | except ValueError: 82 | skip = 0 83 | try: 84 | limit = int(request.POST.get('limit', 5)) 85 | except TypeError: 86 | limit = 5 87 | except ValueError: 88 | limit = 5 89 | # # 查看是否有坐标参数 90 | # try: 91 | # latitude = float(request.POST.get('latitude', None)) 92 | # longitude = float(request.POST.get('longitude', None)) 93 | # except: 94 | # return JsonResponse(resultMsg['CoordinatesError']) 95 | # coordinates = [longitude, latitude] # 做成坐标组 96 | 97 | # 判断搜索内容 98 | content = request.POST.get('searchContent', None) 99 | if not content: 100 | return JsonResponse(resultMsg['NeedParameter']) 101 | lists = Scene.objects( 102 | (Q(name={"$regex": content}) | 103 | Q(city={"$regex": content}) | 104 | Q(province={"$regex": content})), 105 | status='online' 106 | # location__near=coordinates, location__max_distance=50000 107 | ).all()[skip: limit] 108 | lists = json.loads(lists.to_json()) 109 | map(more_replace, lists) 110 | return JsonResponse({"result": lists}) 111 | raise Http404 112 | 113 | 114 | def test(request): 115 | raise Http404 116 | -------------------------------------------------------------------------------- /AppBackend/settings.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ 3 | Django settings for AppBackend project. 4 | 5 | For more information on this file, see 6 | https://docs.djangoproject.com/en/1.7/topics/settings/ 7 | 8 | For the full list of settings and their values, see 9 | https://docs.djangoproject.com/en/1.7/ref/settings/ 10 | """ 11 | 12 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 13 | import os 14 | import logging 15 | from mongoengine import connect 16 | 17 | BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 18 | 19 | 20 | # Quick-start development settings - unsuitable for production 21 | # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ 22 | 23 | # SECURITY WARNING: keep the secret key used in production secret! 24 | SECRET_KEY = '2a)rhd0f1aqg&dwf@)ar4z_e70o5hbvzja&rpsmkz&p@%3ez)f' 25 | 26 | # SECURITY WARNING: don't run with debug turned on in production! 27 | DEBUG = True 28 | # DEBUG = False 29 | 30 | TEMPLATE_DEBUG = True 31 | 32 | ALLOWED_HOSTS = [] 33 | 34 | 35 | # Application definition 36 | 37 | INSTALLED_APPS = ( 38 | 'django.contrib.admin', 39 | 'django.contrib.auth', 40 | 'django.contrib.contenttypes', 41 | 'django.contrib.sessions', 42 | 'django.contrib.messages', 43 | 'django.contrib.staticfiles', 44 | 'appUser', 45 | 'appScene', 46 | 'appComment', 47 | 'application', 48 | 'module' 49 | ) 50 | 51 | MIDDLEWARE_CLASSES = ( 52 | 'django.contrib.sessions.middleware.SessionMiddleware', 53 | 'django.middleware.common.CommonMiddleware', 54 | # 'django.middleware.csrf.CsrfViewMiddleware', 55 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 56 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 57 | 'django.contrib.messages.middleware.MessageMiddleware', 58 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 59 | ) 60 | 61 | TEMPLATE_CONTEXT_PROCESSORS = ( 62 | 'django.core.context_processors.request', 63 | ) 64 | 65 | # APPEND_SLASH = False 66 | ROOT_URLCONF = 'AppBackend.urls' 67 | 68 | WSGI_APPLICATION = 'AppBackend.wsgi.application' 69 | 70 | # Database 71 | # https://docs.djangoproject.com/en/1.7/ref/settings/#databases 72 | 73 | DATABASES = { 74 | 'default': { 75 | 'ENGINE': 'django.db.backends.sqlite3', 76 | 'NAME': os.path.join(BASE_DIR, 'db/db.sqlite3'), 77 | } 78 | } 79 | 80 | # NoSql Database Mongodb connect 81 | connect('travelDB', username='root', password='root', authentication_source='admin') 82 | 83 | # Internationalization 84 | # https://docs.djangoproject.com/en/1.7/topics/i18n/ 85 | 86 | LANGUAGE_CODE = 'en-us' 87 | 88 | TIME_ZONE = 'UTC' 89 | 90 | USE_I18N = True 91 | 92 | USE_L10N = True 93 | 94 | USE_TZ = True 95 | 96 | 97 | # Static files (CSS, JavaScript, Images) 98 | # https://docs.djangoproject.com/en/1.7/howto/static-files/ 99 | 100 | # STATIC_ROOT = '/home/daath/PycharmProjects/AppBackend/static/' 101 | STATIC_ROOT = os.path.join(BASE_DIR, 'static') 102 | 103 | STATIC_URL = '/static/' 104 | 105 | TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),) 106 | 107 | # MEDIA_ROOT = '/home/daath/PycharmProjects/AppBackend/static/media' 108 | MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media') 109 | 110 | STATICFILES_DIRS = ( 111 | os.path.join(BASE_DIR, 'templates'), # static路径下的html模板会从template目录获取 112 | ("media", os.path.join(STATIC_ROOT, 'media')), 113 | ("bootstrap", os.path.join(STATIC_ROOT, 'bootstrap')), 114 | ("jquery", os.path.join(STATIC_ROOT, 'jquery')), 115 | ("css", os.path.join(STATIC_ROOT, 'css')), 116 | ("js", os.path.join(STATIC_ROOT, 'js')), 117 | ) 118 | 119 | # 融云IM 测试环境 120 | app_key = "6tnym1brnoca7" 121 | app_secret = "fHF6HyP2BsswbU" 122 | os.environ.setdefault('rongcloud_app_key', app_key) 123 | os.environ.setdefault('rongcloud_app_secret', app_secret) 124 | 125 | # 融云IM 正式环境 126 | # app_key = "" 127 | # app_secret = "" 128 | # os.environ.setdefault('rongcloud_app_key', app_key) 129 | # os.environ.setdefault('rongcloud_app_secret', app_secret) 130 | 131 | logging.basicConfig(level=logging.INFO) 132 | -------------------------------------------------------------------------------- /appUser/templates/adminCenter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 管理中心 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 64 | 65 | 66 |
67 | 68 |
69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | {% for scene in scenes %} 78 | 79 | 80 | 81 | 92 | 93 | {% endfor %} 94 | 95 | 96 |
景区名所在城市操作
{{ scene.name }}{{ scene.city }}/{{ scene.province }} 82 | 83 | {% if scene.status == "online" %} 84 | 85 | 86 | {% else %} 87 | 88 | 89 | {% endif %} 90 | 91 |
97 |
98 |
99 |
100 | 101 | 102 | -------------------------------------------------------------------------------- /appScene/webViews.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | from django.core.files.base import ContentFile 4 | from django.shortcuts import render 5 | from django.http import * 6 | from .models import Scene, SceneImage 7 | from application.exception import resultMsg, prefURL 8 | from application.function import produce_image_name, admin_login_auth 9 | 10 | # Create your views here. 11 | 12 | 13 | @admin_login_auth 14 | def add(request): 15 | if request.method == "GET": 16 | return render(request, 'addScene.html') 17 | if request.method == "POST": 18 | name = request.POST.get('sceneName', None) 19 | description = request.POST.get('sceneDescription', None) 20 | city = request.POST.get('sceneCity', None) 21 | province = request.POST.get('sceneProvince', None) 22 | if not name or not description or not city or not province: 23 | return JsonResponse(resultMsg['NeedParameter']) 24 | 25 | try: 26 | latitude = float(request.POST.get('sceneLatitude', None)) 27 | longitude = float(request.POST.get('sceneLongitude', None)) 28 | coordinates = [longitude, latitude] # 做成坐标组 29 | except: 30 | return JsonResponse(resultMsg['CoordinatesError']) 31 | 32 | try: 33 | image = request.FILES['sceneImage'] 34 | except: 35 | return JsonResponse(resultMsg['NeedSceneImage']) 36 | 37 | is_exist = Scene.objects(name=name).filter().count() 38 | if is_exist: 39 | return JsonResponse(resultMsg['ExistScene']) 40 | print image.content_type 41 | # 图片缓存 42 | scene_image = SceneImage() 43 | if image.content_type == 'image/png': 44 | print image.content_type 45 | scene_image.image.save(produce_image_name() + '.png', image) 46 | if image.content_type == 'image/jpg' or image.content_type == 'image/jpeg': 47 | print image.content_type 48 | scene_image.image.save(produce_image_name() + '.jpg', image) 49 | print scene_image.image 50 | 51 | scene = Scene() 52 | scene.name = name 53 | scene.description = description 54 | scene.city = city 55 | scene.province = province 56 | scene.location = coordinates 57 | scene.image = prefURL['ImageURL'] + scene_image.image.__str__() 58 | scene.save() 59 | 60 | return JsonResponse(resultMsg['addSceneSuccess']) 61 | 62 | 63 | @admin_login_auth 64 | def update(request): 65 | if request.method == "POST": 66 | scene_id = request.POST.get('id', None) 67 | name = request.POST.get('name', None) 68 | description = request.POST.get('description', None) 69 | city = request.POST.get('city', None) 70 | province = request.POST.get('province', None) 71 | if not scene_id or not name or not name or not description or not city or not province: 72 | return JsonResponse(resultMsg['NeedParameter']) 73 | try: 74 | latitude = float(request.POST.get('latitude', None)) 75 | longitude = float(request.POST.get('longitude', None)) 76 | coordinates = [longitude, latitude] # 做成坐标组 77 | except: 78 | return JsonResponse(resultMsg['CoordinatesError']) 79 | 80 | is_exist = Scene.objects(name=name).filter() 81 | if is_exist and str(is_exist[0].id) != scene_id: 82 | return JsonResponse(resultMsg['ExistScene']) 83 | 84 | update_dict = dict() 85 | update_dict['name'] = name 86 | update_dict['description'] = description 87 | update_dict['city'] = city 88 | update_dict['province'] = province 89 | update_dict['location'] = coordinates 90 | scene = Scene.objects(id=scene_id).get() 91 | scene.update(**update_dict) 92 | return JsonResponse(resultMsg['updateSceneSuccess']) 93 | raise Http404 94 | 95 | 96 | @admin_login_auth 97 | def update_status(request): 98 | if request.method == "POST": 99 | scene_id = request.POST.get('id', None) 100 | status = request.POST.get('status', None) 101 | if not scene_id or not status: 102 | return JsonResponse(resultMsg['NeedParameter']) 103 | if not (status in ['online', 'offline']): 104 | return JsonResponse(resultMsg['StatusValueError']) 105 | Scene.objects(id=scene_id).get().update(status=status) 106 | response = { 107 | 'online': resultMsg['onlineSceneSuccessful'], 108 | 'offline': resultMsg['offlineSceneSuccessful'] 109 | } 110 | return JsonResponse(response[status]) 111 | raise Http404 112 | 113 | 114 | @admin_login_auth 115 | def query(request): 116 | scene_id = request.GET.get('id', None) 117 | if not scene_id: 118 | return JsonResponse(resultMsg['NeedParameter']) 119 | scene = Scene.objects.get(id=scene_id) 120 | return render(request, 'sceneDetail.html', {'scene': scene.data_clean()}) 121 | -------------------------------------------------------------------------------- /module/baiduPushSDK/lib/RequestCore.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # _*_ coding: UTF-8 _*_ 3 | 4 | ### 5 | # 本文件提供百度云服务PYTHON版本SDK的公共网络交互功能 6 | # 7 | # @author 百度移动.云事业部 8 | # @copyright Copyright (c) 2012-2020 百度在线网络技术(北京)有限公司 9 | # @version 1.0.0 10 | # @package 11 | ## 12 | 13 | 14 | import urlparse 15 | 16 | import pycurl 17 | 18 | import StringIO 19 | 20 | from module.baiduPushSDK.lib.ChannelException import ChannelException 21 | 22 | 23 | class RequestCore(object): 24 | """封装curl,提供网络交互功能,组网络请求包,并保存返回结果""" 25 | #类常量 26 | HTTP_GET = 'GET' 27 | 28 | HTTP_POST = 'POST' 29 | 30 | HTTP_PUT = 'PUT' 31 | 32 | HTTP_DELETE = 'DELETE' 33 | 34 | HTTP_HEAD = 'HEAD' 35 | 36 | 37 | def __init__(self, url=None, proxy=None): 38 | self.request_url = url 39 | self.method = RequestCore.HTTP_POST 40 | self.request_headers = dict() 41 | self.request_body = None 42 | self.response = None 43 | self.response_headers = None 44 | self.response_body = None 45 | self.response_code = None 46 | self.response_info = None 47 | self.curl_handle = None 48 | self.proxy = None 49 | self.username = None 50 | self.password = None 51 | self.curlopts = None 52 | self.debug_mode = False 53 | self.request_class = 'RequestCore' 54 | self.response_class = 'ResponseCore' 55 | self.useragent = 'RequestCore/1.4.2' 56 | if(proxy is not None): 57 | self.set_proxy(proxy) 58 | 59 | def set_credentials(self, username, password): 60 | self.username = username 61 | self.password = password 62 | 63 | def add_header(self, key, value): 64 | self.request_headers[key] = value 65 | 66 | def remove_header(self, key): 67 | if(self.request_headers.has_key(key)): 68 | del self.request_headers[key] 69 | 70 | def set_method(self, method): 71 | self.method = method.upper() 72 | 73 | def set_useragent(self, ua): 74 | self.useragent = ua 75 | 76 | def set_body(self, body): 77 | self.request_body = body 78 | 79 | def set_request_url(self, url): 80 | self.request_url = url 81 | 82 | def set_curlopts(self, curlopts): 83 | self.curlopts = curlopts 84 | 85 | def set_proxy(self, proxy): 86 | self.proxy = urlparse.urlparse(proxy) 87 | 88 | def handle_request(self): 89 | curl_handle = pycurl.Curl() 90 | # set default options. 91 | curl_handle.setopt(pycurl.URL, self.request_url) 92 | curl_handle.setopt(pycurl.REFERER, self.request_url) 93 | curl_handle.setopt(pycurl.USERAGENT, self.useragent) 94 | curl_handle.setopt(pycurl.TIMEOUT, self.curlopts['TIMEOUT']) 95 | curl_handle.setopt(pycurl.CONNECTTIMEOUT, self.curlopts['CONNECTTIMEOUT']) 96 | curl_handle.setopt(pycurl.HEADER, True) 97 | #curl_handle.setopt(pycurl.VERBOSE, 1) 98 | curl_handle.setopt(pycurl.FOLLOWLOCATION, 1) 99 | curl_handle.setopt(pycurl.MAXREDIRS, 5) 100 | if(self.request_headers and len(self.request_headers) > 0): 101 | tmplist = list() 102 | for(key, value) in self.request_headers.items(): 103 | tmplist.append(key + ':' + value) 104 | curl_handle.setopt(pycurl.HTTPHEADER, tmplist) 105 | #目前只需支持POST 106 | curl_handle.setopt(pycurl.HTTPPROXYTUNNEL, 1) 107 | curl_handle.setopt(pycurl.POSTFIELDS, self.request_body) 108 | 109 | response = StringIO.StringIO() 110 | curl_handle.setopt(pycurl.WRITEFUNCTION, response.write) 111 | 112 | try: 113 | curl_handle.perform() 114 | except pycurl.error as error: 115 | raise ChannelException(error, 5) 116 | 117 | self.response_code = curl_handle.getinfo(curl_handle.HTTP_CODE) 118 | header_size = curl_handle.getinfo(curl_handle.HEADER_SIZE) 119 | resp_str = response.getvalue() 120 | self.response_headers = resp_str[0 : header_size] 121 | self.response_body = resp_str[header_size : ] 122 | 123 | response.close() 124 | curl_handle.close() 125 | 126 | 127 | def get_response_header(self, header = None): 128 | if(header is not None): 129 | return self.response_headers[header] 130 | return self.response_headers 131 | 132 | def get_response_body(self): 133 | return self.response_body 134 | 135 | def get_response_code(self): 136 | return self.response_code 137 | 138 | 139 | # 140 | # Container for all response-related methods 141 | # 142 | 143 | class ResponseCore(object): 144 | 145 | def __init__(self, header, body, status = None): 146 | self.header = header 147 | self.body = body 148 | self.status = status 149 | 150 | def isOK(self, codes = None): 151 | if(codes == None): 152 | codes = [200, 201, 204, 206] 153 | return self.status in codes 154 | else: 155 | return self == codes 156 | -------------------------------------------------------------------------------- /appUser/webViews.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.http import * 5 | from django.shortcuts import render 6 | 7 | from models import User, AdminUser 8 | from appScene.models import Scene 9 | from application.exception import resultMsg 10 | from application.function import web_id_replace, admin_login_auth 11 | import json 12 | 13 | 14 | # Create your views here. 15 | 16 | """ 17 | /admin/user/signUp/ 管理页面用户注册 18 | Method: POST 19 | Parameter: | account password realName nickname phone 20 | JSON: { 21 | 'error': False, 22 | 'msgCode': 0, 23 | 'msg': "sign up success" 24 | } 25 | """ 26 | def sign_up(request): 27 | if request.method == "GET": 28 | return render(request, 'signUp.html') 29 | if request.method == "POST": 30 | account = request.POST.get('account', None) 31 | password = request.POST.get('password', None) 32 | real_name = request.POST.get('realName', None) 33 | nickname = request.POST.get('nickname', None) 34 | phone = request.POST.get('phone', None) 35 | if not account or not password or not real_name or not nickname or not phone: 36 | return JsonResponse(resultMsg['NeedParameter']) 37 | is_exist = AdminUser.objects(account=account).filter().count() 38 | if is_exist: 39 | return JsonResponse(resultMsg['ExistUser']) 40 | admin_user = AdminUser() 41 | admin_user.account = account 42 | admin_user.password = password 43 | admin_user.realName = real_name 44 | admin_user.nickname = nickname 45 | admin_user.phone = phone 46 | admin_user.save() 47 | print account + "||" + password + "||" + real_name 48 | return JsonResponse(resultMsg['SignUpSuccess']) 49 | 50 | 51 | """ 52 | /admin/user/signIn/ 管理页面用户登陆 53 | Method: POST 54 | Parameter: | account password 55 | JSON: { 56 | 'error': False, 57 | 'msgCode': 4, 58 | 'msg': "sign In success" 59 | } 60 | """ 61 | def sign_in(request): 62 | if request.method == "GET": 63 | return render(request, 'signIn.html') 64 | if request.method == "POST": 65 | account = request.POST.get('account', None) 66 | password = request.POST.get('password', None) 67 | if not account or not password: 68 | return JsonResponse(resultMsg['NeedParameter']) 69 | try: 70 | admin_user = AdminUser.objects(account=account).get() 71 | except AdminUser.DoesNotExist: 72 | return JsonResponse(resultMsg['NotExistUser']) 73 | if admin_user.status != "admin": 74 | return JsonResponse(resultMsg['AdminAuthorityApplying']) 75 | if admin_user.password == password: 76 | request.session['currentAdmin'] = { 77 | 'id': str(admin_user.id), 78 | 'nickname': admin_user.nickname, 79 | 'realName': admin_user.realName, 80 | 'avatar': admin_user.avatar, 81 | 'status': admin_user.status 82 | } 83 | return JsonResponse(resultMsg['SignInSuccess']) 84 | else: 85 | return JsonResponse(resultMsg['ErrorPassword']) 86 | 87 | 88 | """ 89 | /admin/user/signOut/ 管理页面用户退出 90 | Method: POST 91 | """ 92 | def sign_out(request): 93 | try: 94 | del request.session['currentAdmin'] 95 | except KeyError: 96 | pass 97 | return HttpResponseRedirect('/admin/user/signIn/') 98 | 99 | 100 | @admin_login_auth 101 | def admin_center(request): 102 | scene_lists = Scene.objects().only('id', 'name', 'province', 'city', 'status').all() 103 | scene_lists = json.loads(scene_lists.to_json()) 104 | map(web_id_replace, scene_lists) 105 | print scene_lists 106 | return render(request, 'adminCenter.html', {'scenes': scene_lists}) 107 | 108 | 109 | @admin_login_auth 110 | def apply_guide_lists(request): 111 | apply_guides = User.objects(status="applyGuide").only('id', 'nickname', 'realName', 'status', 'phone').all() 112 | apply_guides = json.loads(apply_guides.to_json()) 113 | map(web_id_replace, apply_guides) 114 | return render(request, 'applyGuideLists.html', {'applyGuides': apply_guides}) 115 | 116 | 117 | @admin_login_auth 118 | def apply_admin_lists(request): 119 | apply_admins = AdminUser.objects(status="applyAdmin").only('id', 'nickname', 'realName', 'status', 'phone').all() 120 | apply_admins = json.loads(apply_admins.to_json()) 121 | map(web_id_replace, apply_admins) 122 | return render(request, 'applyAdminLists.html', {'applyAdmins': apply_admins}) 123 | 124 | 125 | @admin_login_auth 126 | def become_guide(request): 127 | if request.method == "POST": 128 | user_id = request.POST.get('id', None) 129 | if not user_id: 130 | return JsonResponse(resultMsg['NeedParameter']) 131 | User.objects.get(id=user_id).update(status="guide") 132 | return JsonResponse(resultMsg['BecomeGuide']) 133 | raise Http404 134 | 135 | 136 | @admin_login_auth 137 | def become_admin(request): 138 | if request.method == "POST": 139 | admin_id = request.POST.get('id', None) 140 | if not admin_id: 141 | return JsonResponse(resultMsg['NeedParameter']) 142 | AdminUser.objects.get(id=admin_id).update(status="admin") 143 | print resultMsg['BecomeAdmin'] 144 | return JsonResponse(resultMsg['BecomeAdmin']) 145 | raise Http404 146 | -------------------------------------------------------------------------------- /static/js/home.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by daath on 16-4-28. 3 | */ 4 | 5 | 6 | //$(document).ready(function(){ 7 | // $("form#signIn").submit(function(){ 8 | // var account = $("#inputAccount").val(); 9 | // var password = $("#inputPassword").val(); 10 | // $.ajax({ 11 | // url: "/admin/user/signIn/", 12 | // data: { 13 | // account: account, 14 | // password: password 15 | // }, 16 | // async: false, 17 | // type: "POST", 18 | // dataType: "json", 19 | // success: function(data) { 20 | // switch (data['msgCode']) { 21 | // case 1002: 22 | // alert(data['msg']); 23 | // break; 24 | // case 1003: 25 | // alert(data['msg']); 26 | // break; 27 | // case 1006: 28 | // alert(data['msg']); 29 | // break; 30 | // case 4: 31 | // alert(data['msg']); 32 | // break; 33 | // } 34 | // } 35 | // }); 36 | // }); 37 | //}); 38 | 39 | function signInCheck() { 40 | var account = $("#inputAccount").val(); 41 | var password = $("#inputPassword").val(); 42 | $.ajax({ 43 | url: "/admin/user/signIn/", 44 | data: { 45 | account: account, 46 | password: password 47 | }, 48 | async: false, 49 | type: "POST", 50 | dataType: "json", 51 | success: function(data) { 52 | switch (data['msgCode']) { 53 | case 1000: 54 | alert("需要参数"); 55 | break; 56 | // 以上错误一般不会出现 57 | case 1002: 58 | if ($("div#errorDisplay").length) { // 登录失效时候重定向 59 | $("div#errorDisplay").text("此账号还没有注册"); 60 | } else { 61 | $("div#errorDisplay1").show(); 62 | $("div#errorDisplay1").text("此账号还没有注册"); 63 | } 64 | break; 65 | case 1003: 66 | if ($("div#errorDisplay").length) { 67 | $("div#errorDisplay").text("密码错误"); 68 | } else { 69 | $("div#errorDisplay1").show(); 70 | $("div#errorDisplay1").text("密码错误"); 71 | } 72 | break; 73 | case 1006: 74 | if ($("div#errorDisplay").length) { 75 | $("div#errorDisplay").text("此账号还正在申请权限中,请耐心等候"); 76 | } else { 77 | $("div#errorDisplay1").show(); 78 | $("div#errorDisplay1").text("此账号还正在申请权限中,请耐心等候"); 79 | } 80 | break; 81 | case 4: 82 | if ($("div#errorDisplay").length) { 83 | $("div#errorDisplay").removeClass("alert-danger"); 84 | $("div#errorDisplay").addClass("alert-success"); 85 | $("div#errorDisplay").text("登录成功,为您跳转控制台!"); 86 | } else { 87 | $("div#errorDisplay1").show(); 88 | $("div#errorDisplay1").removeClass("alert-danger"); 89 | $("div#errorDisplay1").addClass("alert-success"); 90 | $("div#errorDisplay1").text("登录成功,为您跳转控制台!"); 91 | } 92 | setTimeout(function() { 93 | window.location.href = '/admin/user/adminCenter/'; 94 | }, 3000); 95 | return true; 96 | break; 97 | } 98 | } 99 | }); 100 | return false; 101 | } 102 | 103 | function signUpCheck() { 104 | var account = $("#account").val(); 105 | var password = $("#password").val(); 106 | var confirmPassword = $("#confirmPassword").val(); 107 | var realName = $("#realName").val(); 108 | var nickname = $("#nickname").val(); 109 | var phone = $("#phone").val(); 110 | if (password != confirmPassword) { 111 | alert("确认密码不一致"); 112 | //$("#confirmPassword").parent("div").addClass("has-error"); 113 | } else { 114 | $.ajax({ 115 | url: '/admin/user/signUp/', 116 | data: { 117 | account: account, 118 | password: password, 119 | realName: realName, 120 | nickname: nickname, 121 | phone: phone 122 | }, 123 | async: false, 124 | type: 'POST', 125 | dataType: 'json', 126 | success: function (data) { 127 | switch (data['msgCode']) { 128 | case 1000: 129 | alert("需要参数"); 130 | break; 131 | // 以上错误一般不会出现 132 | case 1001: 133 | $("div#errorDisplay").show(); 134 | $("div#errorDisplay").text("此账号已经被注册"); 135 | $("#account").focus().end(); 136 | break; 137 | case 0: 138 | $("div#errorDisplay").removeClass("alert-danger"); 139 | $("div#errorDisplay").addClass("alert-success"); 140 | $("div#errorDisplay").show(); 141 | 142 | $("div#errorDisplay").text("注册成功!为您跳转登录页面"); 143 | setTimeout(function() { 144 | window.location.href = '/admin/user/signIn/'; 145 | }, 1000); 146 | break; 147 | } 148 | } 149 | }) 150 | } 151 | return false; 152 | } 153 | 154 | 155 | -------------------------------------------------------------------------------- /module/rongSDK/test.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # coding=utf-8 3 | 4 | import os 5 | import json 6 | import unittest 7 | import logging 8 | 9 | from rong import ApiClient 10 | 11 | #app_key = "" 12 | #app_secret = "" 13 | 14 | #os.environ.setdefault('rongcloud_app_key', app_key) 15 | #os.environ.setdefault('rongcloud_app_secret', app_secret) 16 | 17 | logging.basicConfig(level=logging.INFO) 18 | 19 | client = ApiClient() 20 | 21 | 22 | class ApiTest(unittest.TestCase): 23 | def test_token_get(self): 24 | result = client.user_get_token( 25 | 'test-userid1', 26 | 'test-name1', 27 | 'http://www.rongcloud.cn/images/logo.png') 28 | 29 | result2 = client.user_get_token( 30 | 'test-userid2', 31 | 'test-name2', 32 | 'http://www.rongcloud.cn/images/logo.png') 33 | 34 | self.assertEqual(result[u'code'], 200) 35 | self.assertEqual(result2[u'code'], 200) 36 | self.assertEqual(result[u'userId'], 'test-userid1') 37 | self.assertEqual(result2[u'userId'], 'test-userid2') 38 | 39 | self.assertTrue(u"token" in result) 40 | 41 | def test_user_refresh(self): 42 | result = client.user_refresh( 43 | 'test-userid2', 44 | 'test-name2', 45 | 'http://www.rongcloud.cn/images/logo_new.png' 46 | ) 47 | 48 | self.assertEqual(result[u'code'], 200) 49 | 50 | def test_user_check_online(self): 51 | result = client.user_check_online( 52 | 'test-userid2' 53 | ) 54 | 55 | self.assertEqual(result[u'code'], 200) 56 | self.assertTrue(u"status" in result) 57 | 58 | def test_user_block(self): 59 | result = client.user_block('test-userid1', 10) 60 | self.assertEqual(result[u'code'], 200) 61 | 62 | block_user_list = client.user_block_query() 63 | self.assertEqual(block_user_list[u'code'], 200) 64 | self.assertTrue('test-userid1' in [r.get("userId") for r in block_user_list.get("users")]) 65 | 66 | def test_user_unblock(self): 67 | result = client.user_unblock('test-userid2') 68 | self.assertEqual(result[u'code'], 200) 69 | 70 | block_user_list = client.user_block_query() 71 | self.assertEqual(block_user_list[u'code'], 200) 72 | self.assertTrue('test-userid2' not in [r.get("userId") for r in block_user_list.get("users")], "检查解封是否成功") 73 | 74 | def test_user_blocklist_add(self): 75 | result = client.user_blocklist_add('test-userid1', ['test-userid2', 'test-userid3']) 76 | self.assertEqual(result[u'code'], 200) 77 | 78 | def test_user_blocklist_query(self): 79 | result = client.user_blocklist_query('test-userid1') 80 | self.assertTrue('test-userid2' in result.get('users')) 81 | self.assertTrue('test-userid3' in result.get('users')) 82 | 83 | def test_user_blocklist_remove(self): 84 | client.user_blocklist_remove('test-userid1', ['test-userid2', 'test-userid3']) 85 | result = client.user_blocklist_query('test-userid1') 86 | self.assertTrue('test-userid2' not in result.get('users')) 87 | self.assertTrue('test-userid3' not in result.get('users')) 88 | 89 | def test_message_publish(self): 90 | result = client.message_publish( 91 | from_user_id='test-userid1', 92 | to_user_id='test-userid2', 93 | object_name='RC:TxtMsg', 94 | content=json.dumps({"content":"hello"}), 95 | push_content='thisisapush', 96 | push_data='aa') 97 | 98 | self.assertEqual(result[u'code'], 200) 99 | 100 | def test_message_system_publish(self): 101 | result = client.message_system_publish( 102 | from_user_id='test-userid1', 103 | to_user_id='test-userid2', 104 | object_name='RC:TxtMsg', 105 | content=json.dumps({"content":"hello"}), 106 | push_content='thisisapush', 107 | push_data='aa') 108 | 109 | self.assertEqual(result[u'code'], 200) 110 | 111 | def test_group_create(self): 112 | result = client.group_create( 113 | user_id_list=["test-userid1", "test-userid2"], 114 | group_id="groupid1", 115 | group_name="groupname1" 116 | ) 117 | 118 | self.assertEqual(result[u'code'], 200) 119 | 120 | def test_message_group_publish(self): 121 | result = client.message_group_publish( 122 | from_user_id='test-userid1', 123 | to_group_id="groupid1", 124 | object_name='RC:TxtMsg', 125 | content=json.dumps({"content":"hello"}), 126 | push_content='this is push content', 127 | push_data='this is pushdata' 128 | ) 129 | self.assertEqual(result[u'code'], 200) 130 | 131 | def test_chatroom_create(self): 132 | result = client.chatroom_create( 133 | chatrooms={ 134 | 'tr001':'room1', 135 | 'tr002':'room2' 136 | } 137 | ) 138 | self.assertEqual(result[u'code'], 200) 139 | 140 | def test_message_chatroom_publish(self): 141 | result = client.message_chatroom_publish( 142 | from_user_id="test-userid1", 143 | to_chatroom_id="tr001", 144 | object_name="RC:TxtMsg", 145 | content=json.dumps({"content":"hello"}) 146 | ) 147 | self.assertEqual(result[u'code'], 200) 148 | 149 | def test_message_history(self): 150 | result = client.message_history( 151 | date=2014010101 152 | ) 153 | self.assertEqual(result[u'code'], 200) 154 | self.assertTrue(u'url' in result) 155 | 156 | def test_group_sync(self): 157 | result = client.group_sync( 158 | user_id='test-userid1', 159 | groups={ 160 | "groupid1":"groupname1" 161 | } 162 | ) 163 | self.assertEqual(result[u'code'], 200) 164 | 165 | def test_group_join(self): 166 | result = client.group_join( 167 | user_id_list=['test-userid1', 'test-userid2'], 168 | group_id="groupid1", 169 | group_name="groupname1" 170 | ) 171 | self.assertEqual(result[u'code'], 200) 172 | 173 | def test_group_quit(self): 174 | result = client.group_quit( 175 | user_id_list=['test-userid1', 'test-userid2'], 176 | group_id="groupid1" 177 | ) 178 | self.assertEqual(result[u'code'], 200) 179 | 180 | def test_group_refresh(self): 181 | result = client.group_refresh( 182 | group_id="groupid1", 183 | group_name="groupname1" 184 | ) 185 | self.assertEqual(result[u'code'], 200) 186 | 187 | def test_group_dismiss(self): 188 | result = client.group_dismiss( 189 | user_id='test-userid1', 190 | group_id="groupid1") 191 | self.assertEqual(result[u'code'], 200) 192 | 193 | def test_chatroom_query(self): 194 | result = client.chatroom_query(["tr001","tr002"]) 195 | self.assertEqual(result[u'code'], 200) 196 | 197 | def test_chatroom_destroy(self): 198 | result = client.chatroom_destroy( 199 | chatroom_id_list=["tr001", "tr002"] 200 | ) 201 | self.assertEqual(result[u'code'], 200) 202 | 203 | if __name__ == "__main__": 204 | unittest.main() -------------------------------------------------------------------------------- /module/baiduPushSDK/lib/valid.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | 4 | import inspect 5 | 6 | import re 7 | 8 | import socket 9 | 10 | from module.baiduPushSDK.lib.ChannelException import ChannelException 11 | 12 | opt_keys ={ 13 | 'pushMsgToSingleDevice' : ('expires', 'device_type', 'msg_expires', 'msg_type', 'deploy_status'), 14 | 'pushMsgToAll' : ('expires', 'device_type', 'msg_expires', 'msg_type', 'deploy_status', 'send_time'), 15 | 'pushMsgToTag' : ('expires', 'device_type', 'msg_expires', 'msg_type', 'deploy_status', 'send_time'), 16 | 'pushBatchUniMsg' : ('expires', 'device_type', 'msg_expires', 'msg_type', 'topic_id'), 17 | 'queryTimerRecords' : ('expires', 'device_type', 'start', 'limit', 'range_start', 'range_end'), 18 | 'queryTopicRecords':('expires', 'device_type', 'start', 'limit', 'range_start', 'range_end'), 19 | 'queryTimerList' : ('expires', 'device_type', 'timer_id', 'start', 'limit'), 20 | 'queryTopicList' : ('expires', 'device_type', 'start', 'limit'), 21 | 'queryTags' : ('expires', 'device_type', 'tag', 'start', 'limit')} 22 | 23 | def validParam(*varargs, **keywords): 24 | """��֤�����װ������""" 25 | 26 | varargs = map(_toStardardCondition, varargs) 27 | keywords = dict((k, _toStardardCondition(keywords[k])) 28 | for k in keywords) 29 | 30 | def generator(func): 31 | args, varargname, kwname = inspect.getargspec(func)[:3] 32 | dctValidator = _getcallargs(args, varargname, kwname, 33 | varargs, keywords) 34 | 35 | def wrapper(*callvarargs, **callkeywords): 36 | dctCallArgs = _getcallargs(args, varargname, kwname, 37 | callvarargs, callkeywords) 38 | 39 | k, item = None, None 40 | try: 41 | for k in dctValidator: 42 | if k == varargname: 43 | for item in dctCallArgs[k]: 44 | assert dctValidator[k](item) 45 | elif k == kwname: 46 | for item in dctCallArgs[k].values(): 47 | assert dctValidator[k](item) 48 | else: 49 | item = dctCallArgs[k] 50 | assert dctValidator[k](item) 51 | except: 52 | raise ChannelException( 53 | ('parameter validation fails, param: %s, value: %s(%s)' 54 | % (k, item, item.__class__.__name__)), 3) 55 | 56 | return func(*callvarargs, **callkeywords) 57 | 58 | wrapper = _wrapps(wrapper, func) 59 | return wrapper 60 | 61 | return generator 62 | 63 | 64 | def _toStardardCondition(condition): 65 | """�����ָ�ʽ�ļ������ת��Ϊ��麯��""" 66 | 67 | if inspect.isclass(condition): 68 | return lambda x: isinstance(x, condition) 69 | 70 | if isinstance(condition, (tuple, list)): 71 | cls, condition = condition[:2] 72 | if condition is None: 73 | return _toStardardCondition(cls) 74 | 75 | if cls in (str, unicode) and condition[0] == condition[-1] == '/': 76 | return lambda x: (isinstance(x, cls) 77 | and re.match(condition[1:-1], x) is not None) 78 | 79 | return lambda x: isinstance(x, cls) and eval(condition) 80 | 81 | return condition 82 | 83 | 84 | def nullOk(cls, condition=None): 85 | """�������ָ���ļ���������Խ���Noneֵ""" 86 | 87 | return lambda x: x is None or _toStardardCondition((cls, condition))(x) 88 | 89 | 90 | def multiType(*conditions): 91 | """�������ָ���ļ������ֻ��Ҫ��һ��ͨ��""" 92 | 93 | lstValidator = map(_toStardardCondition, conditions) 94 | def validate(x): 95 | for v in lstValidator: 96 | if v(x): 97 | return True 98 | return validate 99 | 100 | 101 | def _getcallargs(args, varargname, kwname, varargs, keywords): 102 | """��ȡ����ʱ�ĸ�������-ֵ���ֵ�""" 103 | 104 | dctArgs = {} 105 | varargs = tuple(varargs) 106 | keywords = dict(keywords) 107 | 108 | argcount = len(args) 109 | varcount = len(varargs) 110 | callvarargs = None 111 | 112 | if argcount <= varcount: 113 | for n, argname in enumerate(args): 114 | dctArgs[argname] = varargs[n] 115 | 116 | callvarargs = varargs[-(varcount-argcount):] 117 | 118 | else: 119 | for n, var in enumerate(varargs): 120 | dctArgs[args[n]] = var 121 | 122 | for argname in args[-(argcount-varcount):]: 123 | if argname in keywords: 124 | dctArgs[argname] = keywords.pop(argname) 125 | 126 | callvarargs = () 127 | 128 | if varargname is not None: 129 | dctArgs[varargname] = callvarargs 130 | 131 | if kwname is not None: 132 | dctArgs[kwname] = keywords 133 | 134 | dctArgs.update(keywords) 135 | return dctArgs 136 | 137 | 138 | def _wrapps(wrapper, wrapped): 139 | """����Ԫ���""" 140 | 141 | for attr in ('__module__', '__name__', '__doc__'): 142 | setattr(wrapper, attr, getattr(wrapped, attr)) 143 | for attr in ('__dict__',): 144 | getattr(wrapper, attr).update(getattr(wrapped, attr, {})) 145 | 146 | return wrapper 147 | 148 | 149 | def _checkValue(key, value): 150 | if key == 'msg_type': 151 | @validParam(msg_type=(int, '-1 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
95 | 96 | 97 | 98 | 99 | 100 | 101 |
102 | 103 | 104 | 105 | 106 | 107 | 108 |
109 | 110 | 111 | 112 | 113 | 114 | 115 |
116 | 117 | 118 | 119 |
120 |
121 |
-------------------------------------------------------------------------------- /appComment/views.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | import datetime 4 | from django.http import * 5 | from .models import SceneComment, GuideComment 6 | from appScene.models import Scene 7 | from appUser.models import User 8 | import json 9 | from application.exception import resultMsg 10 | from application.function import login_auth 11 | 12 | 13 | # Create your views here. 14 | 15 | 16 | """ 17 | /comment/commentScene/ 评论景区 18 | Method: POST 19 | Parameter: | id content 20 | JSON = { 21 | "result": { 22 | "sceneId": "56de885c7a74e76673e2e7b7", 23 | "content": "这是个好景区", 24 | "_id": "56ff70d27a74e760897c8183", 25 | "userId": "56dc4a407a74e720e5d3ce24", 26 | "commentTime": { 27 | "$date": 1459581122315 28 | } 29 | } 30 | } 31 | """ 32 | @login_auth 33 | def comment_scene(request): 34 | if request.method == "POST": 35 | scene_id = request.POST.get('id', None) 36 | content = request.POST.get('content', None) 37 | if not scene_id or not content: 38 | return JsonResponse(resultMsg['NeedParameter']) 39 | comment = SceneComment() 40 | comment.sceneId = scene_id 41 | comment.userId = request.session['currentUser']['_id'] 42 | comment.content = content 43 | comment.save() 44 | comment.reload() 45 | return HttpResponse(comment.to_json()) 46 | raise Http404 47 | 48 | 49 | """ 50 | /comment/commentGuide/ 评论导游 51 | Method: POST 52 | Parameter: | id content 53 | JSON = { 54 | "result": { 55 | "guideId": "56de77c3e82017c1a0556aff", 56 | "content": "这是个好导游", 57 | "_id": { 58 | "$oid": "56ff71627a74e765eb541f81" 59 | }, 60 | "userId": "56dc4a407a74e720e5d3ce24", 61 | "commentTime": { 62 | "$date": 1459581282233 63 | } 64 | } 65 | } 66 | """ 67 | @login_auth 68 | def comment_guide(request): 69 | if request.method == "POST": 70 | guide_id = request.POST.get('id', None) 71 | content = request.POST.get('content', None) 72 | if not guide_id or not content: 73 | return JsonResponse(resultMsg['NeedParameter']) 74 | comment = GuideComment() 75 | comment.guideId = guide_id 76 | comment.userId = request.session['currentUser']['_id'] 77 | comment.content = content 78 | comment.save() 79 | comment.reload() 80 | return HttpResponse(comment.to_json()) 81 | raise Http404 82 | 83 | 84 | """ 85 | /comment/getSceneComment/ 获得景区评论 86 | Method: POST 87 | Parameter: | id 88 | JSON = { 89 | "haveComment": true, 90 | "result": [ 91 | { 92 | "content": "黄埔古港是个好地方", 93 | "userId": "56dc4a407a74e720e5d3ce24", 94 | "sceneId": "56de885c7a74e76673e2e7b7", 95 | "userInfo": { 96 | "_id": "56dc4a407a74e720e5d3ce24", 97 | "nickname": "好", 98 | "avatar": "http://img4q.duitang.com/uploads/item/201406/30/20140630190350_HLd4L.jpeg" 99 | }, 100 | "commentTime": { 101 | "$date": 1459580864691 102 | }, 103 | "_id": "56ff6fe27a74e75d7f2b0a4d" 104 | } 105 | ] 106 | } 107 | """ 108 | def get_scene_comment(request): 109 | if request.method == "POST": 110 | scene_id = request.POST.get("id", None) 111 | if not scene_id: 112 | return JsonResponse(resultMsg['NeedParameter']) 113 | comments = SceneComment.objects(sceneId=scene_id).all() 114 | comments = json.loads(comments.to_json()) 115 | user_ids = list(set(map(lambda l: l['userId'], comments))) 116 | users = User.objects(id__in=user_ids).only("id", "nickname", "avatar").all() 117 | users = json.loads(users.to_json()) 118 | for comment in comments: 119 | comment['_id'] = comment['_id']['$oid'] 120 | for user in users: 121 | if user['_id']['$oid'] == comment['userId']: 122 | comment['userInfo'] = { 123 | '_id': user['_id']['$oid'], 124 | 'nickname': user['nickname'], 125 | 'avatar': user['avatar'], 126 | } 127 | print request.COOKIES 128 | response = { 129 | 'result': comments, 130 | 'haveComment': False 131 | } 132 | if request.session['currentUser']['_id'] in user_ids: 133 | response['haveComment'] = True 134 | return JsonResponse(response) 135 | raise Http404 136 | 137 | 138 | """ 139 | /comment/getGuideComment/ 获得导游评论表 140 | Method: POST 141 | Parameter: | id 142 | JSON: { 143 | "haveComment": true, 144 | "result": [ 145 | { 146 | "guideId": "56dc4a407a74e720e5d3ce24", 147 | "userId": "56dd1f6e80980daee16a8dc5", 148 | "content": "Tiger是个不错的导游", 149 | "userInfo": { 150 | "_id": "56dd1f6e80980daee16a8dc5", 151 | "nickname": "hani", 152 | "avatar": "http://b.picphotos.baidu.com/album/s%3D1100%3Bq%3D90/sign=63fc9698e7fe9925cf0c6d51049865ae/060828381f30e924e14c126c4b086e061c95f787.jpg" 153 | }, 154 | "commentTime": { 155 | "$date": 1459427991298 156 | }, 157 | "_id": "56fd18132f3f565529a0e1cd" 158 | }, 159 | { 160 | "guideId": "56dc4a407a74e720e5d3ce24", 161 | "userId": "56dc4a407a74e720e5d3ce24", 162 | "content": "来一波评论自己的", 163 | "userInfo": { 164 | "_id": "56dc4a407a74e720e5d3ce24", 165 | "nickname": "好", 166 | "avatar": "http://img4q.duitang.com/uploads/item/201406/30/20140630190350_HLd4L.jpeg" 167 | }, 168 | "commentTime": { 169 | "$date": 1459580148277 170 | }, 171 | "_id": "56ff6cf47a74e74e9bb3b069" 172 | } 173 | ] 174 | } 175 | 176 | """ 177 | def get_guide_comment(request): 178 | if request.method == "POST": 179 | guide_id = request.POST.get("id", None) 180 | if not guide_id: 181 | return JsonResponse(resultMsg['NeedParameter']) 182 | comments = GuideComment.objects(guideId=guide_id).all() 183 | comments = json.loads(comments.to_json()) 184 | user_ids = list(set(map(lambda l: l['userId'], comments))) 185 | users = User.objects(id__in=user_ids).only("id", "nickname", "avatar").all() 186 | users = json.loads(users.to_json()) 187 | for comment in comments: 188 | comment['_id'] = comment['_id']['$oid'] 189 | for user in users: 190 | if user['_id']['$oid'] == comment['userId']: 191 | comment['userInfo'] = { 192 | "_id": user['_id']['$oid'], 193 | "nickname": user['nickname'], 194 | "avatar": user['avatar'], 195 | } 196 | response = { 197 | 'result': comments, 198 | 'haveComment': False 199 | } 200 | if request.session['currentUser']['_id'] in user_ids: 201 | response['haveComment'] = True 202 | return JsonResponse(response) 203 | raise Http404 204 | 205 | 206 | """ 207 | /comment/commentSceneLists/ 获得所有景区和与其相关的评论(暂时不用) 208 | Method: POST 209 | JSON: {} 210 | """ 211 | def comment_scene_lists(request): 212 | # TODO 会到时候修改的,会有一个景区的id参数,不需要遍历两层 213 | if request.method == "POST": 214 | comments = json.loads(SceneComment.objects().all().to_json()) 215 | # 取出要查询的景区id和评论人id然后得到一个去重的列表 216 | scene_ids = list(set(map(lambda l: l['sceneId'], comments))) 217 | user_ids = list(set(map(lambda l: l['userId'], comments))) 218 | scenes = json.loads(Scene.objects(id__in=scene_ids).all().to_json()) 219 | users = json.loads(User.objects(id__in=user_ids).all().to_json()) 220 | # 遍历comments这个列表然后把相关的景区信息和评论人的信息插进去 221 | for comment in comments: 222 | for scene in scenes: 223 | if scene['_id']['$oid'] == comment['sceneId']: 224 | comment['sceneInfo'] = scene 225 | for user in users: 226 | if user['_id']['$oid'] == comment['userId']: 227 | comment['userInfo'] = { 228 | "_id": user['_id'], 229 | "nickname": user['nickname'], 230 | "avatar": user['avatar'], 231 | } 232 | return JsonResponse({"result": comments}) 233 | raise Http404 234 | 235 | 236 | """ 237 | /comment/commentGuideLists/ 获得所有导游与其相关的评论(暂时不用) 238 | Method: POST 239 | JSON: {} 240 | """ 241 | def comment_guide_lists(request): 242 | if request.method == "POST": 243 | comments = json.loads(GuideComment.objects().all().to_json()) 244 | user_ids = list(set(map(lambda l: l['guideId'] or l['userId'], comments))) 245 | users = json.loads(User.objects(id__in=user_ids).all().to_json()) 246 | # TODO 其实可能会有一个导游id参数,遍历会少一层,那么就不会这么麻烦了 247 | # for comment in comments: 248 | # for user in users: 249 | # if user['_id']['$oid'] == comment['guideId']: 250 | # comment['guideInfo'] = { 251 | # "_id": user['_id'], 252 | # "nickname": user['nickname'], 253 | # "avatar": user['avatar'], 254 | # } 255 | return JsonResponse({"result": comments}) 256 | raise Http404 257 | 258 | 259 | def test1(request): 260 | # del request.COOKIES 261 | # request.session['user'] = 21 262 | print request.COOKIES 263 | print request.session.__dict__ 264 | print request.session.get('currentUser') 265 | http = JsonResponse({'result': 321}) 266 | # http.delete_cookie('sessionid') 267 | # http.set_cookie('session', ) 268 | return http 269 | 270 | 271 | def test(request): 272 | # from django.contrib.sessions.backends.db import SessionStore 273 | # s = SessionStore(session_key=request.COOKIES['sessionid']) 274 | # print "123", s.session_key 275 | # time = datetime.datetime.now() 276 | # lists = SceneComment.objects(commentTime__gte=time) 277 | # for i in lists: 278 | # print i.commentTime 279 | # return HttpResponse(lists.to_json()) 280 | print request.COOKIES 281 | print request.session.__dict__ 282 | print request.session.get('currentUser') 283 | # try: 284 | # request.session['currentUser'] 285 | # except KeyError: 286 | # print 1236465465465 287 | http = JsonResponse({"results": 123}) 288 | # http.delete_cookie('sessionid') 289 | # http.set_cookie("sessionid", {'user': 123}) 290 | return http 291 | # return 292 | -------------------------------------------------------------------------------- /appUser/views.py: -------------------------------------------------------------------------------- 1 | # encoding:utf8 2 | """ By Daath """ 3 | 4 | from django.contrib import auth 5 | from django.core.files.base import ContentFile 6 | from mongoengine import document 7 | from django.http import * 8 | from models import User, ImageTest, UserAvatar 9 | import json 10 | from application.exception import resultMsg, prefURL 11 | from application.function import id_replace, login_auth, produce_image_name, process_token, push_nearly_scene 12 | from base64 import b64decode 13 | 14 | # Create your views here. 15 | 16 | """ 17 | api/user/signCheck/ app用户登录检查 18 | Method: POST 19 | JSON: { 20 | 'error': False, 21 | 'msgCode': 2, 22 | 'msg': "sign check successful" 23 | } 24 | """ 25 | def sign_check(request): 26 | if request.method == "POST": 27 | is_exist = request.session.get('currentUser', None) 28 | if is_exist: 29 | return JsonResponse(resultMsg['SignCheckSuccessful']) 30 | return JsonResponse(resultMsg['NeedLogin']) 31 | raise Http404 32 | 33 | 34 | """ 35 | api/user/signUp/ 用户注册 36 | Method: POST 37 | Parameter: | account password 38 | JSON: { 39 | "msg": "exist user", 40 | "msgCode": 1001, 41 | "error": true 42 | } 43 | """ 44 | def sign_up(request): 45 | if request.method == "POST": 46 | account = request.POST.get('account', '') 47 | password = request.POST.get('password', '') 48 | if not account or not password: 49 | return JsonResponse(resultMsg['NeedParameter']) 50 | is_exist = User.objects(account=account).filter().count() 51 | if is_exist: 52 | return JsonResponse(resultMsg['ExistUser']) 53 | user = User() 54 | user.account = account 55 | user.password = password 56 | user.save() 57 | kw = { 58 | '_id': str(user.id), 59 | 'nickname': user.nickname, 60 | 'avatar': user.avatar, 61 | 'token': user.token 62 | } 63 | process_token(**kw) 64 | return JsonResponse(resultMsg['SignUpSuccess']) 65 | raise Http404 66 | 67 | 68 | """ 69 | api/user/signIn/ 用户登录 70 | Method: POST 71 | Parameter: | account password 72 | JSON: { 73 | "result": { 74 | "status": "guide", 75 | "account": "Daath", 76 | "_id": "56dc4a407a74e720e5d3ce24", 77 | "realName": "李四", 78 | "location": { 79 | "type": "Point", 80 | "coordinates": [ 81 | 113.363911, 82 | 23.140113 83 | ] 84 | }, 85 | "phone": "1364", 86 | "avatar": "http://img4q.duitang.com/uploads/item/201406/30/20140630190350_HLd4L.jpeg", 87 | "nickname": "好", 88 | "description": "真诚待人,希望做更好" 89 | } 90 | } 91 | """ 92 | def sign_in(request): 93 | if request.method == "POST": 94 | account = request.POST.get('account', None) 95 | password = request.POST.get('password', None) 96 | if not account or not password: 97 | return JsonResponse(resultMsg['NeedParameter']) 98 | try: 99 | user = User.objects(account=account).get() 100 | except User.DoesNotExist: 101 | return JsonResponse(resultMsg['NotExistUser']) 102 | if user.password == password: 103 | request.session['currentUser'] = {"_id": str(user.id)} 104 | kw = { 105 | '_id': str(user.id), 106 | 'nickname': user.nickname, 107 | 'avatar': user.avatar, 108 | 'token': user.token 109 | } 110 | process_token(**kw) 111 | user.reload() 112 | return HttpResponse(user.to_json()) 113 | return JsonResponse(resultMsg['ErrorPassword']) 114 | raise Http404 115 | 116 | 117 | """ 118 | api/user/signOut/ 用户退出 119 | Method: POST 120 | JSON: { 121 | "msg": "sign out", 122 | "msgCode": 1, 123 | "error": False 124 | } 125 | """ 126 | def sign_out(request): 127 | try: 128 | del request.session['currentUser'] 129 | except KeyError: 130 | pass 131 | return JsonResponse(resultMsg['SignOut']) 132 | 133 | 134 | """ 135 | api/user/update/ 更新用户资料 136 | Method: POST 137 | Parameter: | nickname realName description phone 138 | JSON: { 139 | "result": { 140 | "status": "guide", 141 | "account": "Daath", 142 | "_id": "56dc4a407a74e720e5d3ce24", 143 | "realName": "李四", 144 | "location": { 145 | "type": "Point", 146 | "coordinates": [ 147 | 113.363911, 148 | 23.140113 149 | ] 150 | }, 151 | "phone": "1364", 152 | "avatar": "http://img4q.duitang.com/uploads/item/201406/30/20140630190350_HLd4L.jpeg", 153 | "nickname": "赵日天", 154 | "description": "真诚待人,希望做更好" 155 | } 156 | } 157 | """ 158 | @login_auth 159 | def update(request): 160 | if request.method == "POST": 161 | nickname = request.POST.get('nickname', None) 162 | real_name = request.POST.get('realName', None) 163 | description = request.POST.get('description', None) 164 | phone = request.POST.get('phone', None) 165 | update_dict = dict() 166 | if nickname: 167 | update_dict['nickname'] = nickname 168 | if real_name: 169 | update_dict['realName'] = real_name 170 | if description: 171 | update_dict['description'] = description 172 | if phone: 173 | update_dict['phone'] = phone 174 | user = User.objects(id=request.session['currentUser']['_id']).get() 175 | if update_dict: 176 | user.update(**update_dict) 177 | user.reload() 178 | if nickname: 179 | kw = { 180 | '_id': str(user.id), 181 | 'nickname': user.nickname, 182 | 'avatar': user.avatar, 183 | 'token': user.token 184 | } 185 | process_token(**kw) 186 | return HttpResponse(user.to_json()) 187 | raise Http404 188 | 189 | 190 | """ 191 | api/user/updateLocation/ 用户定位坐标更新 192 | Method: POST 193 | Parameter: | latitude longitude 194 | JSON: { 当前用户的信息 } 195 | """ 196 | @login_auth 197 | def update_location(request): 198 | if request.method == "POST": 199 | try: 200 | latitude = float(request.POST.get('latitude', None)) 201 | longitude = float(request.POST.get('longitude', None)) 202 | except: 203 | return JsonResponse({"message": "坐标有错"}) 204 | coordinates = [longitude, latitude] 205 | user = User.objects(id=request.session['currentUser']['_id']).get() 206 | user.update(location=coordinates) 207 | user.reload() 208 | print coordinates 209 | kw = { 210 | 'channelId': user.channelId, 211 | 'coordinates': [longitude, latitude] 212 | } 213 | push_nearly_scene(**kw) 214 | return HttpResponse(user.to_json()) 215 | raise Http404 216 | 217 | 218 | """ 219 | api/user/modifyPassword/ 修改用户密码 220 | Method: POST 221 | Parameter: | oldPassword newPassword 222 | JSON: { 223 | "result": { 224 | "status": "guide", 225 | "account": "Daath", 226 | "_id": "56dc4a407a74e720e5d3ce24", 227 | "realName": "李四", 228 | "location": { 229 | "type": "Point", 230 | "coordinates": [ 231 | 113.363911, 232 | 23.140113 233 | ] 234 | }, 235 | "phone": "1364", 236 | "avatar": "http://img4q.duitang.com/uploads/item/201406/30/20140630190350_HLd4L.jpeg", 237 | "nickname": "赵日天", 238 | "description": "真诚待人,希望做更好" 239 | } 240 | } 241 | """ 242 | @login_auth 243 | def modify_password(request): 244 | if request.method == "POST": 245 | old_password = request.POST.get('oldPassword', None) 246 | new_password = request.POST.get('newPassword', None) 247 | if not old_password or not new_password: 248 | return JsonResponse(resultMsg['NeedParameter']) 249 | try: 250 | update_user = User.objects(id=request.session['currentUser']['_id'], password=old_password).get() 251 | except User.DoesNotExist: 252 | return JsonResponse(resultMsg['ErrorPassword']) 253 | update_user.update(password=new_password) 254 | update_user.reload() 255 | return HttpResponse(update_user.to_json()) 256 | raise Http404 257 | 258 | 259 | """ 260 | api/user/applyGuide/ 申请导游 261 | Method: POST 262 | JSON: { 当前用户的信息 } 263 | """ 264 | @login_auth 265 | def apply_guide(request): 266 | if request.method == "POST": 267 | user = User.objects(id=request.session['currentUser']['_id']).get() 268 | user.update(status="applyGuide") 269 | user.reload() 270 | return HttpResponse(user.to_json()) 271 | raise Http404 272 | 273 | 274 | """ 275 | api/user/getGuideLists/ 获得导游列表 276 | Method: POST 277 | Parameter: | skip limit latitude longitude 278 | Json: { 279 | "result": [ 280 | { 281 | "_id": "56de77c3e82017c1a0556aff", 282 | "realName": "banana", 283 | "avatar": "http://b.picphotos.baidu.com/album/s%3D1100%3Bq%3D90/sign=63fc9698e7fe9925cf0c6d51049865ae/060828381f30e924e14c126c4b086e061c95f787.jpg", 284 | "description": "带好您的行李,走遍中国,尽力为每一个游客细心周到的解说景区" 285 | } 286 | ] 287 | } 288 | """ 289 | def get_guide_lists(request): 290 | if request.method == "POST": 291 | try: 292 | skip = int(request.POST.get('skip', 0)) 293 | except (TypeError, ValueError) as e: 294 | skip = 0 295 | try: 296 | limit = int(request.POST.get('limit', 5)) 297 | except (TypeError, ValueError) as e: 298 | limit = 5 299 | # 查看是否有坐标参数 300 | try: 301 | latitude = float(request.POST.get('latitude', None)) 302 | longitude = float(request.POST.get('longitude', None)) 303 | except: 304 | return JsonResponse(resultMsg['CoordinatesError']) 305 | coordinates = [longitude, latitude] # 做成坐标组 306 | print coordinates 307 | guides = User.objects( 308 | status='guide', 309 | location__near=coordinates, 310 | location__max_distance=10000 311 | ).only('id', 'realName', 'avatar', 'description').all()[skip: limit] 312 | guides = json.loads(guides.to_json()) 313 | print guides 314 | map(id_replace, guides) 315 | return JsonResponse({"result": guides}) 316 | raise Http404 317 | 318 | 319 | """ 320 | api/user/getVisitorLists/ 获得附近游客列表 321 | Method: POST 322 | Parameter: | skip limit latitude longitude 323 | Json: { 324 | "result": [ 325 | { 326 | "_id": "56de77c3e82017c1a0556aff", 327 | "realName": "banana", 328 | "avatar": "http://b.picphotos.baidu.com/album/s%3D1100%3Bq%3D90/sign=63fc9698e7fe9925cf0c6d51049865ae/060828381f30e924e14c126c4b086e061c95f787.jpg", 329 | "description": "带好您的行李,走遍中国,尽力为每一个游客细心周到的解说景区" 330 | } 331 | ] 332 | } 333 | """ 334 | def get_visitor_lists(request): 335 | if request.method == "POST": 336 | try: 337 | skip = int(request.POST.get('skip', 0)) 338 | except (TypeError, ValueError) as e: 339 | skip = 0 340 | try: 341 | limit = int(request.POST.get('limit', 5)) 342 | except (TypeError, ValueError) as e: 343 | limit = 5 344 | # 查看是否有坐标参数 345 | try: 346 | latitude = float(request.POST.get('latitude', None)) 347 | longitude = float(request.POST.get('longitude', None)) 348 | except: 349 | return JsonResponse(resultMsg['CoordinatesError']) 350 | coordinates = [longitude, latitude] # 做成坐标组 351 | print coordinates 352 | visitors = User.objects( 353 | id__ne=request.session['currentUser']['_id'], 354 | status__in=['user', 'applyGuide'], 355 | location__near=coordinates, 356 | location__max_distance=10000 357 | ).only('id', 'realName', 'avatar', 'description').all()[skip: limit] 358 | visitors = json.loads(visitors.to_json()) 359 | map(id_replace, visitors) 360 | return JsonResponse({"result": visitors}) 361 | raise Http404 362 | 363 | 364 | """ 365 | api/user/avatarUpload/ 头像上传 366 | Method: POST 367 | Parameter: | file 是base64字节流 368 | JSON: { 当前用户的信息} 369 | """ 370 | @login_auth 371 | def avatar_upload(request): 372 | if request.method == "POST": 373 | image_stream = request.POST.get('file', None) 374 | image = ContentFile(b64decode(image_stream)) 375 | avatar = UserAvatar() 376 | avatar.user_avatar.save(produce_image_name() + '.jpg', image) 377 | current_user = User.objects(id=request.session['currentUser']['_id']).get() 378 | image_url = prefURL['ImageURL'] + avatar.user_avatar.__str__() 379 | current_user.update(avatar=image_url) 380 | current_user.reload() 381 | kw = { 382 | '_id': str(current_user.id), 383 | 'nickname': current_user.nickname, 384 | 'avatar': current_user.avatar, 385 | 'token': current_user.token 386 | } 387 | process_token(**kw) 388 | return HttpResponse(current_user.to_json()) 389 | raise Http404 390 | 391 | 392 | """ 393 | api/user/tokenReload/ token过期,重新获取token 394 | Method: POST 395 | JSON: { 当前游客的部分信息} 396 | """ 397 | @login_auth 398 | def token_reload(request): 399 | if request.method == "POST": 400 | current_user = User.objects(id=request.session['currentUser']['_id']).get() 401 | kw = { 402 | '_id': str(current_user.id), 403 | 'nickname': current_user.nickname, 404 | 'avatar': current_user.avatar, 405 | 'token': '' 406 | } 407 | process_token(**kw) 408 | current_user.reload() 409 | print current_user.token 410 | return HttpResponse(current_user.to_json()) 411 | raise Http404 412 | 413 | 414 | """ 415 | api/user/saveChannelId/ 保存百度云推送的channelId 416 | Method: POST 417 | Parameter: | channelId 418 | JSON: { 419 | 'error': False, 420 | 'msgCode': 3, 421 | 'msg': "save channelId successful" 422 | } 423 | """ 424 | @login_auth 425 | def save_channel_id(request): 426 | if request.method == "POST": 427 | channel_id = request.POST.get('channelId', None) 428 | if not channel_id: 429 | return JsonResponse(resultMsg['NeedParameter']) 430 | current_user = User.objects(id=request.session['currentUser']['_id']).get() 431 | current_user.update(channelId=channel_id) 432 | return JsonResponse(resultMsg['SaveChannelId']) 433 | raise Http404 434 | 435 | 436 | """ 437 | api/user/getVisitorInfo/ 获取游客用户信息(这个暂时没用到) 438 | Method: POST 439 | Parameter: | id 440 | JSON: { 当前游客的部分信息} 441 | """ 442 | @login_auth 443 | def get_visitor_info(request): 444 | if request.method == "POST": 445 | visitor_id = request.POST.get('id', None) 446 | if not visitor_id: 447 | return JsonResponse(resultMsg['NeedParameter']) 448 | visitor = User.objects(id=visitor_id).only('id', 'realName', 'nickname', 'avatar').get() 449 | result = { 450 | '_id': str(visitor.id), 451 | 'realName': visitor.realName, 452 | 'nickname': visitor.nickname, 453 | 'avatar': visitor.avatar 454 | } 455 | return JsonResponse({'result': result}) 456 | raise Http404 457 | 458 | 459 | def test(request): 460 | # if request.session['user']: 461 | # print request.session['user'] 462 | # return JsonResponse({"aaa": 123}) 463 | # userTest = User.objects().all() 464 | # xx = json.loads(userTest.to_json()) 465 | # return JsonResponse({"result": xx}) 466 | # return HttpResponse(userTest.to_json()) 467 | # xx = request.session['xx'] 468 | # x = json.dumps(xx) 469 | # del request.session['xx'] 470 | return JsonResponse({"ss": 11}, status=201) 471 | # list1 = [ 472 | # [116.4135540000, 39.9110130000], 473 | # [112.4717700000, 23.0529840000], 474 | # [112.9453330000, 28.2339710000], 475 | # [113.3351650000, 23.1401800000], 476 | # 477 | # ] 478 | # user = User.objects(location__near=list1[3], location__max_distance=10000) 479 | # if not user: 480 | # print 'xx' 481 | # return HttpResponse(user.to_json()) 482 | 483 | 484 | """ 485 | 上传图片测试 486 | """ 487 | def image_test(request): 488 | if request.method == "GET": 489 | print request.method 490 | return JsonResponse({"result": 555}) 491 | if request.method == "POST": 492 | print 123 493 | xxs = request.POST.get('file', None) 494 | # print xxs 495 | # print type(xxs) 496 | image_data = ContentFile(b64decode(xxs)) 497 | # file = ContentFile(xxs) 498 | # print request.FILES 499 | # print request.FILES['file'].__dict__ 500 | # print bytes(request.FILES['file']) 501 | # print type(request.FILES['file']) 502 | x = ImageTest() 503 | # file = ContentFile(request.FILES['file'].read()) 504 | # # x.save() 505 | x.image_avatar.save("test.jpg", image_data) 506 | return JsonResponse({"result": 555}) 507 | 508 | 509 | 510 | -------------------------------------------------------------------------------- /module/baiduPushSDK/Channel.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # _*_ coding: UTF-8 _*_ 3 | 4 | import time 5 | 6 | import urllib 7 | 8 | import hashlib 9 | 10 | import json 11 | 12 | import ConfigParser 13 | 14 | import os,sys 15 | 16 | import platform 17 | 18 | from lib.ChannelException import ChannelException 19 | 20 | from lib.RequestCore import RequestCore,ResponseCore 21 | 22 | from lib.valid import validOptDict,validParam,nullOk 23 | 24 | class Channel(object): 25 | 26 | #baidu push 域名 27 | HOST = 'host' 28 | 29 | #应用key,从百度开发者中心获得,是创建Channel的必须参数 30 | API_KEY = 'apikey' 31 | 32 | #从百度开发者中心获得,是创建Channel的必须参数 33 | SECRET_KEY = 'secret_key' 34 | 35 | #设备类型,3:android, 4:ios 36 | DEVICE_TYPE = 'device_type' 37 | 38 | #Channel常量,用于计算sign,用户不必关注 39 | SIGN = 'sign' 40 | METHOD = 'method' 41 | REQUEST_ID = None 42 | 43 | #curl 连接参数 44 | CURL_TIMEOUT = 30 45 | CURL_CONNECTTIMEOUT = 5 46 | 47 | #Channel 错误常量 48 | CHANNEL_SDK_INIT_ERROR = 1 49 | CHANNEL_SDK_RUNNING_ERROR = 2 50 | CHANNEL_SDK_PARAM = 3 51 | CHANNEL_SDK_HTTP_STATUS_OK_BUT_RESULT_ERROR = 4 52 | CHANNEL_SDK_HTTP_STATUS_ERROR_AND_RESULT_ERROR = 5 53 | 54 | #操作系统版本信息,用于User-Agent设置 55 | SYSTEM_INFO = 'system_info' 56 | 57 | #配置文件加载情况 58 | CONF_ERR = False; 59 | 60 | def __init__(self): 61 | """init 获得运行linux平台版本信息, 加载conf""" 62 | 63 | Channel.SYSTEM_INFO = str(platform.uname()) 64 | self._loadConf() 65 | 66 | def _loadConf(self): 67 | """加载配置文件 68 | 69 | 加载失败会在调用api时抛出异常ChannelException,errCode=1 70 | 配置文件分为两个section: 71 | 1、SDK,包括推送域名host、apiKey、secretKey 72 | 2、curl,包括建立连接超时和交互超时""" 73 | 74 | try: 75 | ABSPATH=os.path.abspath(__file__) 76 | pos = ABSPATH.rfind('/') 77 | ABSPATH = ABSPATH[:pos + 1] 78 | cp = ConfigParser.SafeConfigParser() 79 | cp.read(ABSPATH + 'sdk.conf') 80 | Channel.API_KEY= cp.get('SDK', 'apiKey') 81 | Channel.SECRET_KEY = cp.get('SDK', 'secretKey') 82 | Channel.DEVICE_TYPE = cp.get('SDK', 'deviceType') 83 | Channel.HOST = cp.get('SDK', 'host') 84 | Channel.CURL_TIMEOUT = cp.getint('curl', 'timeout') 85 | Channel.CURL_CONNECTTIMEOUT= cp.getint('curl', 'connecttimeout') 86 | self._curlOpts = dict(TIMEOUT = Channel.CURL_TIMEOUT, 87 | CONNECTTIMEOUT = Channel.CURL_CONNECTTIMEOUT) 88 | except Exception as e: 89 | Channel.CONF_ERR = True 90 | 91 | def setApiKey(self, apiKey): 92 | """运行期间可以另指定apiKey 93 | 94 | args: 95 | apiKey--想要指定的apiKey""" 96 | 97 | Channel.API_KEY = apiKey 98 | 99 | def setSecretKey(self, secretKey): 100 | """运行期间可以另指定secretKey 101 | 102 | args: 103 | secretKey--想要指定的secretKey""" 104 | 105 | Channel.SECRET_KEY = secretKey 106 | 107 | def setDeviceType(self, deviceType): 108 | """运行期间可以修改设备类型 109 | 110 | args: 111 | deviceType--想要指定的deviceType""" 112 | 113 | Channel.DEVICE_TYPE = deviceType 114 | 115 | def getRequestId(self): 116 | """获得服务器返回的requestId 117 | 118 | return: 119 | requestId""" 120 | 121 | return Channel.REQUEST_ID 122 | 123 | @validParam(channel_id=str, msg=str, opts=nullOk(dict)) 124 | def pushMsgToSingleDevice(self, channel_id, msg, opts=None): 125 | """向单个设备推送消息 126 | 127 | args: 128 | channel_id--客户端初始化成功之后返回的channelId 129 | msg--json格式的通知数据,详见说明文档 130 | opts--可选字段合集,详见说明文档 131 | return: 132 | msg_id--消息id 133 | send_time--消息的实际推送时间 134 | Exception: 135 | 参数错误或者http错误,会抛出此异常,异常信息详见说明文档""" 136 | 137 | self._checkConf() 138 | 139 | validOptDict(opts, 'pushMsgToSingleDevice') 140 | args = self._commonSet() 141 | args['channel_id'] = channel_id 142 | args['msg'] = msg 143 | args.update(opts) 144 | self._product_name = 'push' 145 | self._resource_name = 'single_device' 146 | 147 | return self._commonProcess(args) 148 | 149 | 150 | @validParam(msg=str, opts=nullOk(dict)) 151 | def pushMsgToAll(self, msg, opts=None): 152 | """向当前app下所有设备推送一条消息 153 | 154 | args: 155 | msg--json格式的通知数据,详见说明文档 156 | opts--可选字段合集,详见说明文档 157 | return: 158 | msg_id--消息id 159 | send_time--消息的实际推送时间 160 | timer_id(可选)--定时服务ID 161 | Exception: 162 | 参数错误或者http错误,会抛出此异常,异常信息详见说明文档""" 163 | 164 | self._checkConf() 165 | 166 | validOptDict(opts, 'pushMsgToAll') 167 | args = self._commonSet() 168 | args['msg'] = msg 169 | args.update(opts) 170 | self._product_name = 'push' 171 | self._resource_name = 'all' 172 | 173 | return self._commonProcess(args) 174 | 175 | 176 | @validParam(type=(int, '0