添加启动脚本

添加报告查看,编辑功能
This commit is contained in:
pzc-x99 2025-03-01 10:44:40 +08:00
parent 0fe45a7093
commit a80e18dc83
9 changed files with 216 additions and 4 deletions

View File

@ -3,10 +3,20 @@ from django.contrib import admin
# Register your models here.
from . models import Papers, OpenAIDiagnose
from django.urls import reverse
from django.utils.html import format_html
@admin.register(Papers)
class PaperAdmin(admin.ModelAdmin):
list_display = ('id', 'uuid', 'status', 'created_at', 'updated_at')
list_display = ('user', 'uuid', 'status', 'created_at', 'updated_at')
@admin.register(OpenAIDiagnose)
class OpenAIDiagnoseAdmin(admin.ModelAdmin):
list_display = ('id', 'uuid', 'status', 'diagnose_type', 'created_at', 'updated_at')
list_display = ('user', 'uuid', 'status', 'diagnose_type', 'created_at', 'updated_at', 'custom_link')
def custom_link(self, obj):
# 为每个用户添加自定义链接
url = reverse('dia_report', args=[obj.pk]) # 生成链接
return format_html('<a href="{}">查看</a>', url) # 创建 HTML 链接
custom_link.short_description = '详细信息' # 设置列标题

View File

@ -62,7 +62,7 @@ def openai_diagnoser_asyna_wraper(uuid_str: str, username: str, diagnose_type: s
"content": [
{
"type": "text",
"text": "图中是几个题目,帮我分析一下,我是否做对了",
"text": "图中是几个题目,我已经用笔作答了。通过我的作答情况给出本学科的学情分析。",
},
{
"type": "image_url",

View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>诊断报告</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/simplemde@1.11.2/dist/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/npm/simplemde@1.11.2/dist/simplemde.min.js"></script>
</head>
<body>
{% extends 'admin/base_site.html' %}
<!-- {% block title %}
{{ admin_site.site_title }} - {{ user.username }}'s Profile
{% endblock %} -->
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">诊断应用后台</a></h1>
{% endblock %}
{% block content %}
<p>{{ obj.user.name }} 的诊断报告,该报告的类型为 {{ obj.diagnose_type }}, 报告生成时间:{{ obj.updated_at }}
uuid: {{ obj.uuid }}
</p>
<button id="save-button" style="margin: 10px 5px;">保存修改</button>
<div id="editor-container">
<textarea id="markdown-editor"></textarea>
</div>
<script>
const simplemde = new SimpleMDE({ element: document.getElementById("markdown-editor") });
simplemde.value(`{{ md_content }}`); // 将文件内容加载到编辑器中
document.getElementById("save-button").addEventListener("click", () => {
const updatedContent = simplemde.value();
fetch('/diagnose/report_update/{{ report_id }}/', { // 这里是你的后台 API 路径
method: 'POST',
body: new URLSearchParams({ 'md_new_content': updatedContent }),
})
.then(response => response.json())
.then(data => {
if (data.message) {
alert("File saved successfully!");
} else {
alert("Failed to save content");
}
});
});
</script>
{% endblock %}
</body>
</html>

View File

@ -2,11 +2,17 @@
from django.urls import path
from .dp_views import MyProtectedGeneratePaper, MyProtectedGenerateCheck, MyProtectedDownloadPaper
from .db_views import MyProtectedUploadDiagnose, MyProtectedDiagnoseCheck
from .views import dia_report, dia_report_update
urlpatterns = [
path('', MyProtectedGeneratePaper.as_view(), name='api_generate_paper'),
path('check/', MyProtectedGenerateCheck.as_view(), name='api_generate_check'),
path('download/', MyProtectedDownloadPaper.as_view(), name='api_download_paper'),
path('upload/', MyProtectedUploadDiagnose.as_view(), name='api_upload_file'),
path('upload_diagnose_check/', MyProtectedDiagnoseCheck.as_view(), name='api_diagnose_file')
path('upload_diagnose_check/', MyProtectedDiagnoseCheck.as_view(), name='api_diagnose_file'),
path('report/<int:report_id>/', dia_report, name='dia_report'),
path('report_update/<int:report_id>/', dia_report_update, name='dia_report_update'),
]

34
diagnose/views.py Normal file
View File

@ -0,0 +1,34 @@
import os
from django.conf import settings
from django.shortcuts import render
from .models import OpenAIDiagnose
from django.http import JsonResponse
def dia_report(request, report_id):
obj = OpenAIDiagnose.objects.get(id=report_id)
file_path = os.path.join(settings.BASE_DIR, 'upload_file', obj.user.username, obj.uuid + '.md')
print(file_path)
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8' ) as f:
content = f.read()
f.close()
else:
content = 'None'
if obj:
return render(request, 'dia_report.html', {'obj': obj, 'md_content': content, 'report_id': report_id})
else:
return render(request, 'dia_report.html', {'error': 'Report not found'})
def dia_report_update(request, report_id):
if request.method == 'POST':
obj = OpenAIDiagnose.objects.get(id=report_id)
file_path = os.path.join(settings.BASE_DIR, 'upload_file', obj.user.username, obj.uuid + '.md')
print(file_path)
if os.path.exists(file_path):
f = open(file_path, 'w', encoding='utf-8' )
f.write(request.POST['md_new_content'])
f.close()
return JsonResponse({'message':"ok"}, status=200)

4
ec_static/font-awesome.min.css vendored Normal file

File diff suppressed because one or more lines are too long

15
ec_static/simplemde.min.js vendored Normal file

File diff suppressed because one or more lines are too long

73
requirements.txt Normal file
View File

@ -0,0 +1,73 @@
amqp==5.3.1
annotated-types==0.7.0
anyio==4.8.0
asgiref==3.8.1
async-timeout==5.0.1
beautifulsoup4==4.13.3
billiard==4.2.1
Brotli @ file:///C:/b/abs_c415aux9ra/croot/brotli-split_1736182803933/work
celery==5.4.0
certifi==2025.1.31
cffi @ file:///C:/b/abs_29_b57if3f/croot/cffi_1736184144340/work
charset-normalizer==3.4.1
click==8.1.8
click-didyoumean==0.3.1
click-plugins==1.1.1
click-repl==0.3.0
colorama==0.4.6
cryptography==43.0.3
cssselect2==0.2.1
distro==1.9.0
Django==4.2.19
djangorestframework==3.15.2
dnspython==2.7.0
eventlet==0.39.0
exceptiongroup==1.2.2
fonttools @ file:///C:/b/abs_4crkswws2h/croot/fonttools_1737040078745/work
gevent==24.11.1
greenlet==3.1.1
h11==0.14.0
html5lib @ file:///Users/ktietz/demo/mc3/conda-bld/html5lib_1629144453894/work
httpcore==1.0.7
httpx==0.28.1
idna==3.10
jiter==0.8.2
kombu==5.4.2
lxml==5.3.1
markdown2==2.5.3
openai==1.64.0
pdfkit==1.0.0
pillow @ file:///C:/b/abs_b50vowcrzo/croot/pillow_1738010273782/work
prompt_toolkit==3.0.50
pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work
pydantic==2.10.6
pydantic_core==2.27.2
pydyf @ file:///home/conda/feedstock_root/build_artifacts/pydyf_1734953323721/work
PyMySQL==1.1.1
pypandoc==1.15
pyphen @ file:///C:/b/abs_f53b85wvhi/croot/pyphen_1696417767496/work
python-dateutil==2.9.0.post0
python-docx==1.1.2
redis==5.2.1
requests==2.32.3
six @ file:///tmp/build/80754af9/six_1644875935023/work
sniffio==1.3.1
soupsieve==2.6
sqlparse==0.5.3
tinycss2 @ file:///C:/b/abs_df38owi5ma/croot/tinycss2_1738337725183/work
tinyhtml5==2.0.0
tqdm==4.67.1
typing_extensions==4.12.2
tzdata==2025.1
unicodedata2 @ file:///C:/b/abs_dfnftvxi4k/croot/unicodedata2_1736543771112/work
urllib3==2.3.0
vine==5.1.0
volcengine-python-sdk==1.0.126
wcwidth==0.2.13
weasyprint @ file:///home/conda/feedstock_root/build_artifacts/weasyprint_1736155132945/work/weasyprint-62.3-py3-none-any.whl#sha256=d31048646ce15084e135b33e334a61f526aa68d2f679fcc109ed0e0f5edaed21
webencodings==0.5.1
websocket==0.2.1
websocket-client==1.8.0
zope.event==5.0
zope.interface==7.2
zopfli==0.2.3.post1

15
start.bat Normal file
View File

@ -0,0 +1,15 @@
@echo off
echo Activating conda environment...
call conda activate educheck
echo Starting Django server...
start /B python manage.py runserver 127.0.0.1:8000
echo Starting Celery worker...
start /B celery -A educheck worker -l info -P eventlet
echo Starting Celery beat...
start /B celery -A educheck beat -l info
echo All services are running.
pause