修改了一些模型

配置了django托管静态文件 Debug=False
This commit is contained in:
pzc-x99 2025-03-01 15:12:55 +08:00
parent a80e18dc83
commit bb3d03b26d
14 changed files with 234 additions and 28 deletions

View File

@ -1,7 +1,7 @@
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from . models import Papers, OpenAIDiagnose from . models import Papers, OpenAIDiagnose, Questions
from django.urls import reverse from django.urls import reverse
from django.utils.html import format_html from django.utils.html import format_html
@ -20,3 +20,7 @@ class OpenAIDiagnoseAdmin(admin.ModelAdmin):
return format_html('<a href="{}">查看</a>', url) # 创建 HTML 链接 return format_html('<a href="{}">查看</a>', url) # 创建 HTML 链接
custom_link.short_description = '详细信息' # 设置列标题 custom_link.short_description = '详细信息' # 设置列标题
@admin.register(Questions)
class QuestionAdmin(admin.ModelAdmin):
list_display = ('name', 'content')

View File

@ -52,8 +52,6 @@ class DpArguments():
# 用字典中的数据恢复对象状态 # 用字典中的数据恢复对象状态
self.__dict__.update(state) self.__dict__.update(state)
class MyProtectedGeneratePaper(APIView): class MyProtectedGeneratePaper(APIView):
authentication_classes = [CustomTokenAuthentication] # 使用自定义的 Token 认证 authentication_classes = [CustomTokenAuthentication] # 使用自定义的 Token 认证
permission_classes = [IsAuthenticated] # 需要用户认证才能访问 permission_classes = [IsAuthenticated] # 需要用户认证才能访问
@ -95,7 +93,8 @@ class MyProtectedGeneratePaper(APIView):
print(dp_args.student, dp_args.subject, dp_args.textbook_version, dp_args.start_grade, dp_args.start_semester,\ print(dp_args.student, dp_args.subject, dp_args.textbook_version, dp_args.start_grade, dp_args.start_semester,\
dp_args.start_chapter, dp_args.end_grade, dp_args.end_semester, dp_args.end_chapter) dp_args.start_chapter, dp_args.end_grade, dp_args.end_semester, dp_args.end_chapter)
# 调用异步任务 # 调用异步任务
obj = Papers.objects.create(uuid=uuid_str, user=user, status='P') obj = Papers.objects.create(uuid=uuid_str, user=user, status='P',
text_version=textbook_version, subject=subject)
obj.save() obj.save()
user.subject_usage_count = user.subject_usage_count - 1 user.subject_usage_count = user.subject_usage_count - 1
user.save() user.save()
@ -117,14 +116,34 @@ class MyProtectedGenerateCheck(APIView):
except json.JSONDecodeError: except json.JSONDecodeError:
return JsonResponse({"error": "Invalid JSON format"}, status=400) return JsonResponse({"error": "Invalid JSON format"}, status=400)
try: try:
# print(uuid_str) # print("uuid: ", uuid_str)
obj = Papers.objects.get(uuid=uuid_str, user=user) # 只获取一个对象 obj = Papers.objects.get(uuid=uuid_str, user=user) # 只获取一个对象
if obj.status == 'D': if obj.status == 'D':
return JsonResponse({"status": "done", "download_url": f'/diagnose/download/?uuid_str={uuid_str}'}) return JsonResponse({"status": "done", "download_url": f'/diagnose/download/?uuid_str={uuid_str}'})
else: else:
return JsonResponse({"status": "processing", "download_url": None}) return JsonResponse({"status": "processing", "download_url": None})
except ObjectDoesNotExist: except ObjectDoesNotExist:
return JsonResponse({"error_code": "2004"}, status=404) return JsonResponse({"error_code": "2004"}, status=403)
class MyProtectedUserPapersInfo(APIView):
authentication_classes = [CustomTokenAuthentication] # 使用自定义的 Token 认证
permission_classes = [IsAuthenticated] # 需要用户认证才能访问
def get(self, request):
user = request.user
papers = Papers.objects.filter(user=user)
paper_list = []
for paper in papers:
paper_list.append({
'uuid': paper.uuid,
'status': paper.status,
'text_version': paper.text_version,
'subject': paper.subject,
'msg': f'试卷信息:{paper.text_version}, {paper.subject}',
'created_at': paper.created_at,
'download_url': f'/diagnose/download/?uuid_str={paper.uuid}'
})
return JsonResponse({"papers": paper_list})
class MyProtectedDownloadPaper(APIView): class MyProtectedDownloadPaper(APIView):
authentication_classes = [CustomTokenAuthentication] # 使用自定义的 Token 认证 authentication_classes = [CustomTokenAuthentication] # 使用自定义的 Token 认证

View File

@ -0,0 +1,21 @@
# Generated by Django 4.2.19 on 2025-03-01 03:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('diagnose', '0003_openaidiagnose'),
]
operations = [
migrations.CreateModel(
name='Questions',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('content', models.TextField()),
],
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 4.2.19 on 2025-03-01 06:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('diagnose', '0004_questions'),
]
operations = [
migrations.AddField(
model_name='papers',
name='subject',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='papers',
name='text_version',
field=models.CharField(blank=True, max_length=100, null=True),
),
]

View File

@ -2,6 +2,10 @@ from django.db import models
from ec_user.models import EcUser from ec_user.models import EcUser
# Create your models here. # Create your models here.
class Questions(models.Model):
name = models.CharField(max_length=100) # 问题名称
content = models.TextField() # 问题内容
class Papers(models.Model): class Papers(models.Model):
STATUS_CHOICES = ( STATUS_CHOICES = (
('C', '任务创建'), ('C', '任务创建'),
@ -12,6 +16,8 @@ class Papers(models.Model):
# 定义一个与EcUser一对多关联的外键 # 定义一个与EcUser一对多关联的外键
user = models.ForeignKey(EcUser, on_delete=models.CASCADE) # 当EcUser被删除时关联的Papers也会被删除 user = models.ForeignKey(EcUser, on_delete=models.CASCADE) # 当EcUser被删除时关联的Papers也会被删除
status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='C') # 默认值设置为'C' status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='C') # 默认值设置为'C'
subject = models.CharField(max_length=100, null=True, blank=True) # 学科
text_version = models.CharField(max_length=100, null=True, blank=True) # 教材版本
created_at = models.DateTimeField(auto_now_add=True,null=True, blank=True) # 创建时间 created_at = models.DateTimeField(auto_now_add=True,null=True, blank=True) # 创建时间
updated_at = models.DateTimeField(auto_now=True,null=True, blank=True) # 更新时间 updated_at = models.DateTimeField(auto_now=True,null=True, blank=True) # 更新时间

View File

@ -62,7 +62,8 @@ def openai_diagnoser_asyna_wraper(uuid_str: str, username: str, diagnose_type: s
"content": [ "content": [
{ {
"type": "text", "type": "text",
"text": "图中是几个题目,我已经用笔作答了。通过我的作答情况给出本学科的学情分析。", "text": """图中是几个题目,我已经用笔作答了,先帮我判题,然后通过我的作答情况给出本学科的学情分析。
从基础知识学科素养综合能力等方面给出学员指导意见""",
}, },
{ {
"type": "image_url", "type": "image_url",

View File

@ -1,6 +1,6 @@
from django.urls import path from django.urls import path
from .dp_views import MyProtectedGeneratePaper, MyProtectedGenerateCheck, MyProtectedDownloadPaper from .dp_views import MyProtectedGeneratePaper, MyProtectedGenerateCheck, MyProtectedDownloadPaper, MyProtectedUserPapersInfo
from .db_views import MyProtectedUploadDiagnose, MyProtectedDiagnoseCheck from .db_views import MyProtectedUploadDiagnose, MyProtectedDiagnoseCheck
from .views import dia_report, dia_report_update from .views import dia_report, dia_report_update
@ -9,6 +9,7 @@ urlpatterns = [
path('', MyProtectedGeneratePaper.as_view(), name='api_generate_paper'), path('', MyProtectedGeneratePaper.as_view(), name='api_generate_paper'),
path('check/', MyProtectedGenerateCheck.as_view(), name='api_generate_check'), path('check/', MyProtectedGenerateCheck.as_view(), name='api_generate_check'),
path('download/', MyProtectedDownloadPaper.as_view(), name='api_download_paper'), path('download/', MyProtectedDownloadPaper.as_view(), name='api_download_paper'),
path('user_papers_info/', MyProtectedUserPapersInfo.as_view(), name='api_user_papers_info'),
path('upload/', MyProtectedUploadDiagnose.as_view(), name='api_upload_file'), 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'),

View File

@ -12,55 +12,112 @@ class ContactInfoForm(forms.ModelForm):
class Meta: class Meta:
model = ContactInfo model = ContactInfo
fields = ['home_address', 'parent_contact', 'student_contact', 'email'] fields = ['home_address', 'parent_contact', 'student_contact', 'email']
labels = {
'home_address': '家庭住址',
'parent_contact': '家长联系方式',
'student_contact': '学生联系方式',
'email': '电子邮箱',
}
# SchoolInfo 表单 # SchoolInfo 表单
class SchoolInfoForm(forms.ModelForm): class SchoolInfoForm(forms.ModelForm):
class Meta: class Meta:
model = SchoolInfo model = SchoolInfo
fields = ['school_name', 'grade', 'class_name', 'admission_date', 'expected_graduation_date'] fields = ['school_name', 'grade', 'class_name', 'admission_date', 'expected_graduation_date']
labels = {
'school_name': '学校名称',
'grade': '年级',
'class_name': '班级名称',
'admission_date': '入学日期',
'expected_graduation_date': '预计毕业日期',
}
# AcademicInfo 表单 # AcademicInfo 表单
class AcademicInfoForm(forms.ModelForm): class AcademicInfoForm(forms.ModelForm):
class Meta: class Meta:
model = AcademicInfo model = AcademicInfo
fields = ['last_semester_score', 'this_semester_score', 'class_ranking', 'strong_subject', 'weak_subject'] fields = ['last_semester_score', 'this_semester_score', 'class_ranking', 'strong_subject', 'weak_subject']
labels = {
'last_semester_score': '上学期成绩',
'this_semester_score': '本学期成绩',
'class_ranking': '班级排名',
'strong_subject': '优势科目',
'weak_subject': '弱势科目',
}
# HealthInfo 表单 # HealthInfo 表单
class HealthInfoForm(forms.ModelForm): class HealthInfoForm(forms.ModelForm):
class Meta: class Meta:
model = HealthInfo model = HealthInfo
fields = ['height', 'weight', 'blood_type', 'medical_history', 'disability_status', 'disability_category', 'disability_grade'] fields = ['height', 'weight', 'blood_type', 'medical_history', 'disability_status', 'disability_category', 'disability_grade']
labels = {
'height': '身高',
'weight': '体重',
'blood_type': '血型',
'medical_history': '病史',
'disability_status': '残疾情况',
'disability_category': '残疾类别',
'disability_grade': '残疾等级',
}
# SelfEvaluation 表单 # SelfEvaluation 表单
class SelfEvaluationForm(forms.ModelForm): class SelfEvaluationForm(forms.ModelForm):
class Meta: class Meta:
model = SelfEvaluation model = SelfEvaluation
fields = ['strengths', 'weaknesses', 'study_attitude', 'future_plans'] fields = ['strengths', 'weaknesses', 'study_attitude', 'future_plans']
labels = {
'strengths': '优点',
'weaknesses': '缺点',
'study_attitude': '学习态度',
'future_plans': '未来计划',
}
# HobbiesInterests 表单 # HobbiesInterests 表单
class HobbiesInterestsForm(forms.ModelForm): class HobbiesInterestsForm(forms.ModelForm):
class Meta: class Meta:
model = HobbiesInterests model = HobbiesInterests
fields = ['interests', 'extracurricular_activities'] fields = ['interests', 'extracurricular_activities']
labels = {
'interests': '兴趣爱好',
'extracurricular_activities': '课外活动',
}
# SocialPractice 表单 # SocialPractice 表单
class SocialPracticeForm(forms.ModelForm): class SocialPracticeForm(forms.ModelForm):
class Meta: class Meta:
model = SocialPractice model = SocialPractice
fields = ['activity_name', 'activity_date', 'activity_location', 'activity_description', 'activity_outcome'] fields = ['activity_name', 'activity_date', 'activity_location', 'activity_description', 'activity_outcome']
labels = {
'activity_name': '活动名称',
'activity_date': '活动日期',
'activity_location': '活动地点',
'activity_description': '活动描述',
'activity_outcome': '活动成果',
}
# FamilyInfo 表单 # FamilyInfo 表单
class FamilyInfoForm(forms.ModelForm): class FamilyInfoForm(forms.ModelForm):
class Meta: class Meta:
model = FamilyInfo model = FamilyInfo
fields = ['family_member', 'economic_status'] fields = ['family_member', 'economic_status']
labels = {
'family_member': '家庭成员',
'economic_status': '经济状况',
}
# AwardsPunishments 表单 # AwardsPunishments 表单
class AwardsPunishmentsForm(forms.ModelForm): class AwardsPunishmentsForm(forms.ModelForm):
class Meta: class Meta:
model = AwardsPunishments model = AwardsPunishments
fields = ['award_name', 'award_date', 'award_organization', 'discipline_date', 'discipline_issue', 'discipline_outcome'] fields = ['award_name', 'award_date', 'award_organization', 'discipline_date', 'discipline_issue', 'discipline_outcome']
labels = {
'award_name': '奖项名称',
'award_date': '获奖日期',
'award_organization': '颁奖机构',
'discipline_date': '处分日期',
'discipline_issue': '处分问题',
'discipline_outcome': '处分结果',
}
# 获取或创建各个信息模型实例 # 获取或创建各个信息模型实例
g_models = { g_models = {

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.19 on 2025-03-01 03:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ec_user', '0012_ecuser_age'),
]
operations = [
migrations.AlterField(
model_name='ecuser',
name='political_status',
field=models.CharField(blank=True, max_length=50, null=True),
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 4.2.19 on 2025-03-01 03:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ec_user', '0013_alter_ecuser_political_status'),
]
operations = [
migrations.AlterField(
model_name='contactinfo',
name='email',
field=models.EmailField(blank=True, max_length=254, null=True),
),
migrations.AlterField(
model_name='contactinfo',
name='student_contact',
field=models.CharField(blank=True, max_length=15, null=True),
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 4.2.19 on 2025-03-01 04:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ec_user', '0014_alter_contactinfo_email_and_more'),
]
operations = [
migrations.AlterField(
model_name='hobbiesinterests',
name='extracurricular_activities',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='hobbiesinterests',
name='interests',
field=models.TextField(blank=True, null=True),
),
]

View File

@ -99,18 +99,18 @@ class EcUser(AbstractUser):
('O', 'Other'), ('O', 'Other'),
] ]
name = models.CharField(max_length=100) name = models.CharField(max_length=100,verbose_name=("姓名"))
gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default='M') # 默认值设置为'M' gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default='M', verbose_name=("性别")) # 默认值设置为'M'
age = models.IntegerField(null=True, blank=True) # 允许为空可以为null age = models.IntegerField(null=True, blank=True, verbose_name=("年龄")) # 允许为空可以为null
ethnicity = models.CharField(max_length=50, default='Unknown') # 默认值设置为'Unknown' ethnicity = models.CharField(max_length=50, default='Unknown', verbose_name=("民族")) # 默认值设置为'Unknown'
dob = models.DateField(null=True, blank=True) # 允许为空可以为null dob = models.DateField(null=True, blank=True, verbose_name=("出生日期")) # 允许为空可以为null
id_card_number = models.CharField(max_length=18, unique=True) id_card_number = models.CharField(max_length=18, unique=True, verbose_name=("身份证号"))
political_status = models.CharField(max_length=50, default='Unknown') # 默认值设置为'Unknown' political_status = models.CharField(max_length=50, null=True, blank=True, verbose_name=("政治面貌")) # 默认值设置为'Unknown'
# 多选字段:开放权限的科目 # 多选字段:开放权限的科目
subjects = models.ManyToManyField(Subject, related_name='users', blank=True) # 允许为空,表示可以选择多个科目 subjects = models.ManyToManyField(Subject, related_name='users', blank=True, verbose_name=("开放权限的科目")) # 允许为空,表示可以选择多个科目
# 使用次数限制 # 使用次数限制
subject_usage_count = models.IntegerField(default=0) subject_usage_count = models.IntegerField(default=5, verbose_name=("使用次数限制")) # 默认值为0
def __str__(self): def __str__(self):
return self.name return self.name
@ -120,8 +120,8 @@ class ContactInfo(models.Model):
user = models.OneToOneField(EcUser, on_delete=models.CASCADE) user = models.OneToOneField(EcUser, on_delete=models.CASCADE)
home_address = models.CharField(max_length=255) home_address = models.CharField(max_length=255)
parent_contact = models.CharField(max_length=15) parent_contact = models.CharField(max_length=15)
student_contact = models.CharField(max_length=15) student_contact = models.CharField(max_length=15, null=True, blank=True)
email = models.EmailField() email = models.EmailField(null=True, blank=True)
def __str__(self): def __str__(self):
return f"Contact Info of {self.user.name}" return f"Contact Info of {self.user.name}"
@ -185,9 +185,9 @@ class HobbiesInterests(models.Model):
# 定义一个与EcUser一对多关联的外键 # 定义一个与EcUser一对多关联的外键
user = models.ForeignKey(EcUser, on_delete=models.CASCADE) user = models.ForeignKey(EcUser, on_delete=models.CASCADE)
# 定义一个文本字段,用于存储用户的兴趣爱好 # 定义一个文本字段,用于存储用户的兴趣爱好
interests = models.TextField() interests = models.TextField(null=True, blank=True)
# 定义一个文本字段,用于存储用户的课外活动 # 定义一个文本字段,用于存储用户的课外活动
extracurricular_activities = models.TextField() extracurricular_activities = models.TextField(null=True, blank=True)
def __str__(self): def __str__(self):
# 返回用户的名字和兴趣爱好 # 返回用户的名字和兴趣爱好

View File

@ -105,7 +105,7 @@
<!-- 学习情况 --> <!-- 学习情况 -->
<div class="form-section"> <div class="form-section">
<h4>学习情况</h4> <h4>学习情况</h4>
<div id="gradeForm" style="border: 1px solid #ccc; padding: 10px;"> <!-- <div id="gradeForm" style="border: 1px solid #ccc; padding: 10px;">
<div class="form-group"> <div class="form-group">
<label for="subject1">语文</label> <label for="subject1">语文</label>
<input type="text" id="subject1" name="subject1"> <input type="text" id="subject1" name="subject1">
@ -203,7 +203,7 @@
}) })
}) })
</script> </script>
</div> </div> -->
{{ academic_info_form.as_p }} {{ academic_info_form.as_p }}
</div> </div>

View File

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
""" """
from pathlib import Path from pathlib import Path
import os
# __init__.py # __init__.py
@ -48,6 +49,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # 添加这行
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware', # 'django.middleware.csrf.CsrfViewMiddleware',
@ -134,8 +136,16 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/ # https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'ec_static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' 500error
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field