diff --git a/manage.py b/manage.py index afbc784a..5dfdf0ca 100644 --- a/manage.py +++ b/manage.py @@ -3,7 +3,7 @@ import os import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings_dev") try: from django.core.management import execute_from_command_line except ImportError: diff --git a/mysite/settings_dev.py b/mysite/settings_dev.py new file mode 100644 index 00000000..65f36ff1 --- /dev/null +++ b/mysite/settings_dev.py @@ -0,0 +1,24 @@ +from .settings import * + +DEBUG=True + +DATABASES = { + # 'default': { + # 'ENGINE': 'django.db.backends.sqlite3', + # 'NAME': os.path.join(BASE_DIR, 'safe.db'), + # }, + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'safedb', + 'USER':'postgres', + 'PASSWORD':'cbma1234', + 'HOST':'47.94.4.206', + 'PORT':'5432', + # 'CONN_MAX_AGE': 60, + }, + 'OPTIONS': { + 'isolation_level': psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE, + }, +} +APPID_MP = 'wx8cc62edbfed029b9' +APPSECRET_MP= 'eb15364f89139b9ba9453e4b7c8c12e0' \ No newline at end of file diff --git a/mysite/settings_pro.py b/mysite/settings_pro.py new file mode 100644 index 00000000..c4593b92 --- /dev/null +++ b/mysite/settings_pro.py @@ -0,0 +1,24 @@ +from .settings import * + +DEBUG=False + +DATABASES = { + # 'default': { + # 'ENGINE': 'django.db.backends.sqlite3', + # 'NAME': os.path.join(BASE_DIR, 'safe.db'), + # }, + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'safedb', + 'USER':'postgres', + 'PASSWORD':'cbma1234', + 'HOST':'localhost', + 'PORT':'5432', + # 'CONN_MAX_AGE': 60, + }, + 'OPTIONS': { + 'isolation_level': psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE, + }, +} +APPID_MP = 'wx8cc62edbfed029b9' +APPSECRET_MP= 'eb15364f89139b9ba9453e4b7c8c12e0' \ No newline at end of file diff --git a/mysite/wsgi.py b/mysite/wsgi.py index 74e7daee..dd1df1ef 100644 --- a/mysite/wsgi.py +++ b/mysite/wsgi.py @@ -11,6 +11,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings_pro") application = get_wsgi_application() diff --git a/safesite/daoru.py b/safesite/daoru.py index 22078d6e..b27b092d 100644 --- a/safesite/daoru.py +++ b/safesite/daoru.py @@ -6,6 +6,7 @@ from .models import SafeItem, SafeList, User,Trouble,Dickey,Partment,Dicclass,Tr from datetime import datetime,date import base64 from django.conf import settings +from mysite.settings_dev import APPID_MP, APPSECRET_MP import qrcode import os from django.contrib.auth.hashers import make_password @@ -300,7 +301,7 @@ def drtodotroubles(companyid,path,userid): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db"}, + "miniprogram": {"appid": APPID_MP}, 'data': { 'first': { diff --git a/safesite/views.py b/safesite/views.py index 9c2619f1..a34b309b 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -31,7 +31,7 @@ from django.views.decorators.csrf import csrf_exempt from django.views.generic import TemplateView from duibiao import calsim from groups import models as g_models - +from mysite.settings_dev import APPID_MP, APPSECRET_MP from . import forms from .daoru import (cal_area_risk_level, cal_riskact_level, drequipments, drquestions, drrisks, drtodotroubles, drusers, makeqr, drsafelist, @@ -1058,7 +1058,7 @@ def addyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': { 'value': a.yhdj.dickeyname + '待复查:' @@ -1104,7 +1104,7 @@ def addyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': { @@ -1155,7 +1155,7 @@ def addyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': { @@ -1199,7 +1199,7 @@ def addyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': { @@ -1236,7 +1236,7 @@ def addyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': { @@ -1308,7 +1308,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '待整改:'}, 'keyword1': {'value': a.yhms}, @@ -1393,7 +1393,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '待整改:'}, 'keyword1': {'value': a.yhms}, @@ -1431,7 +1431,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '未被采纳:'}, 'keyword1': {'value': a.yhms}, @@ -1456,7 +1456,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '被退回需重新上报:'}, 'keyword1': {'value': a.yhms}, @@ -1482,7 +1482,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '待评估:'}, 'keyword1': {'value': a.yhms}, @@ -1526,7 +1526,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '待整改:'}, 'keyword1': {'value': a.yhms}, @@ -1568,7 +1568,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '待整改:'}, 'keyword1': {'value': a.yhms}, @@ -1593,7 +1593,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '待整改:'}, 'keyword1': {'value': a.yhms}, @@ -1616,7 +1616,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': { @@ -1652,7 +1652,7 @@ def accessyh(req): postdict = { 'touser': 'oPGqkweX75QtLmgehUN-ipR4hcyc', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + "miniprogram": {"appid": APPID_MP, "path": "pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, 'data': { 'first': {'value': a.yhdj.dickeyname + '待整改:'}, 'keyword1': {'value': a.yhms}, @@ -3816,7 +3816,7 @@ def mplogin(req): code = req.POST.get('code') except: code = json.loads(res)['code'] - info = requests.get('https://api.weixin.qq.com/sns/jscode2session?appid=wx5c39b569f01c27db&secret=68762892f8df2b4a0b1940c5250a8dc0&js_code=' + + info = requests.get('https://api.weixin.qq.com/sns/jscode2session?appid='+APPID_MP+'&secret='+APPSECRET_MP+'&js_code=' + code+'&grant_type=authorization_code').content.decode('utf-8') info = json.loads(info) mpopenid = info['openid'] @@ -5183,7 +5183,7 @@ def apinotice(req): postdict = { 'touser': '', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db"}, + "miniprogram": {"appid": APPID_MP}, 'data': { 'first': { 'value': '公司通知:' @@ -5478,7 +5478,7 @@ def apioperation(req): postdict = { 'touser': '', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db"}, + "miniprogram": {"appid": APPID_MP}, 'data': { 'first': { 'value': obj.zylx.dickeyname + '作业通知:' @@ -6356,7 +6356,7 @@ def apiexamtest(req): postdict = { 'touser': '', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/examtest/index"}, + "miniprogram": {"appid": APPID_MP, "path": "pages/examtest/index"}, 'data': { 'first': { 'value': '小程序考试通知:' @@ -6454,7 +6454,7 @@ def apiexamtest(req): postdict = { 'touser': '', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db", "path": "pages/examtest/index"}, + "miniprogram": {"appid": APPID_MP, "path": "pages/examtest/index"}, 'data': { 'first': { 'value': '小程序考试通知:' @@ -8615,7 +8615,7 @@ def checkprojects(req): postdict = { 'touser': '', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db"}, + "miniprogram": {"appid": APPID_MP}, 'data': { 'first': { 'value': '处罚通知:' @@ -8702,7 +8702,7 @@ def checkprojects(req): postdict = { 'touser': '', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db"}, + "miniprogram": {"appid": APPID_MP}, 'data': { 'first': { 'value': '检查任务通知:' @@ -8763,7 +8763,7 @@ def checkprojects(req): postdict = { 'touser': '', 'template_id': 'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram": {"appid": "wx5c39b569f01c27db"}, + "miniprogram": {"appid": APPID_MP}, 'data': { 'first': { 'value': '检查任务通知:'