diff --git a/.gitignore b/.gitignore index fb725e1..e5b4827 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ lib64/ parts/ sdist/ @@ -104,6 +103,7 @@ celerybeat.pid *.sage.py # Environments +.DS_Store .env .venv env/ diff --git a/Lib/searchDrug.py b/Lib/searchDrug.py new file mode 100644 index 0000000..801bb60 --- /dev/null +++ b/Lib/searchDrug.py @@ -0,0 +1,43 @@ +import json +import time +import os + + +class GetDrugTypeData: + + # 初始化只打开一次 + data = None + + @classmethod + def init(cls): + cls.data = cls.open_text() + + # 打开json文件 + @classmethod + def open_text(cls): + + with open(os.path.abspath('.')+'/Lib/ReagentDB.json', 'r', encoding='utf-8') as f: + content = json.loads(f.read()) + return content + + # 模糊搜索 + @classmethod + def search_data(cls, search_word): + data_list = [] + for drug_dict in cls.data: + if drug_dict['ChineseName'].find(search_word) != -1 or drug_dict['EnglishName'].find(search_word) != -1: + new_dict = {} + new_dict['id'] = drug_dict['CASNumber'] + new_dict['value'] = drug_dict['ChineseName'] + new_dict['subvalue'] = drug_dict['AliasName'] + new_dict['EnglishName'] = drug_dict['EnglishName'] + data_list.append(new_dict) + # 根据列表的字典的key的长度进行排序 + data_list.sort(key=lambda i: len(i['value'])) + return data_list[:5] + + +if __name__ == '__main__': + GetDrugTypeData.init() + print(GetDrugTypeData().search_data('甲醛')) + diff --git a/YY_RMS_Multiple_Manage/__init__.py b/YY_RMS_Multiple_Manage/__init__.py index e69de29..c45523b 100644 --- a/YY_RMS_Multiple_Manage/__init__.py +++ b/YY_RMS_Multiple_Manage/__init__.py @@ -0,0 +1,2 @@ +import pymysql +pymysql.install_as_MySQLdb() \ No newline at end of file diff --git a/YY_RMS_Multiple_Manage/settings.py b/YY_RMS_Multiple_Manage/settings.py index 97c6b6c..40fb8f6 100644 --- a/YY_RMS_Multiple_Manage/settings.py +++ b/YY_RMS_Multiple_Manage/settings.py @@ -11,6 +11,10 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ """ import os +import time +import logging + +from Lib.searchDrug import GetDrugTypeData # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -49,6 +53,34 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] + +# 跨域增加忽略 +CORS_ALLOW_CREDENTIALS = True +CORS_ORIGIN_ALLOW_ALL = True + +CORS_ALLOW_METHODS = ( + 'DELETE', + 'GET', + 'OPTIONS', + 'PATCH', + 'POST', + 'PUT', + 'VIEW', +) +CORS_ALLOW_HEADERS = ( + 'XMLHttpRequest', + 'X_FILENAME', + 'accept-encoding', + 'authorization', + 'content-type', + 'dnt', + 'origin', + 'user-agent', + 'x-csrftoken', + 'x-requested-with', +) + + ROOT_URLCONF = 'YY_RMS_Multiple_Manage.urls' TEMPLATES = [ @@ -105,7 +137,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' +TIME_ZONE = 'Asia/Shanghai' USE_I18N = True @@ -118,3 +150,74 @@ USE_TZ = True # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' + + +# 程序运行时加载 只加载一次 +GetDrugTypeData.init() +flag_ = True + +# 日志管理器 +# 给过滤器使用的判断 + + +class RequireDebugTrue(logging.Filter): + # 实现filter方法 + def filter(self, record): + return DEBUG + + +LOGGING = { + # 基本设置 + 'version': 1, # 日志级别 + 'disable_existing_loggers': False, # 是否禁用现有的记录器 + + # 日志格式集合 + 'formatters': { + # 标准输出格式 + 'standard': { + # [具体时间][日志名字:日志级别名称(日志级别ID)] [输出的模块:输出的函数]:调用日志输出函数的语句所在的代码行-日志内容 + 'format': '具体时间:[%(asctime)s][%(name)s:%(levelname)s(%(lineno)d)]\n当前文件位置:[%(pathname)s]' + '模块名:[%(module)s:]函数名:[%(funcName)s]:\n[第%(lineno)d行]-%(message)s\n' + } + }, + + # 过滤器 + 'filters': { + 'require_debug_true': { + '()': RequireDebugTrue, + } + }, + + # 处理器集合 + 'handlers': { + # 输出到控制台 + 'console': { + 'level': 'DEBUG', # 输出信息的最低级别 + 'class': 'logging.StreamHandler', + 'formatter': 'standard', # 使用standard格式 + 'filters': ['require_debug_true', ], # 仅当 DEBUG = True 该处理器才生效 + }, + # 输出到文件 + 'log': { + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', + 'formatter': 'standard', + # 输出位置 + 'filename': os.path.join(BASE_DIR, 'runserver_log/%s.log' % time.strftime('%Y_%m_%d')), + 'maxBytes': 1024*1024*5, # 文件大小 5M + 'backupCount': 5, # 备份份数 + 'encoding': 'utf8', # 文件编码 + + }, + }, + + # 日志管理器集合 + 'loggers': { + # 管理器 + 'default': { + 'handlers': ['console', 'log'], + 'level': 'DEBUG', + 'propagate': True, # 是否传递给父记录器 + }, + } +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b19b49e Binary files /dev/null and b/requirements.txt differ