From bb3d03b26d490369d87ddb64cb55a7bb87eb1ccd Mon Sep 17 00:00:00 2001 From: pzc-x99 <927068267@qq.com> Date: Sat, 1 Mar 2025 15:12:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=20=E9=85=8D=E7=BD=AE=E4=BA=86django=E6=89=98?= =?UTF-8?q?=E7=AE=A1=E9=9D=99=E6=80=81=E6=96=87=E4=BB=B6=20Debug=3DFalse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diagnose/admin.py | 8 ++- diagnose/dp_views.py | 31 ++++++++-- diagnose/migrations/0004_questions.py | 21 +++++++ ...0005_papers_subject_papers_text_version.py | 23 +++++++ diagnose/models.py | 6 ++ diagnose/openai_dia.py | 3 +- diagnose/urls.py | 3 +- ec_user/forms.py | 61 ++++++++++++++++++- .../0013_alter_ecuser_political_status.py | 18 ++++++ .../0014_alter_contactinfo_email_and_more.py | 23 +++++++ ...sts_extracurricular_activities_and_more.py | 23 +++++++ ec_user/models.py | 26 ++++---- ec_user/templates/all_info_form.html | 4 +- educheck/settings.py | 12 +++- 14 files changed, 234 insertions(+), 28 deletions(-) create mode 100644 diagnose/migrations/0004_questions.py create mode 100644 diagnose/migrations/0005_papers_subject_papers_text_version.py create mode 100644 ec_user/migrations/0013_alter_ecuser_political_status.py create mode 100644 ec_user/migrations/0014_alter_contactinfo_email_and_more.py create mode 100644 ec_user/migrations/0015_alter_hobbiesinterests_extracurricular_activities_and_more.py diff --git a/diagnose/admin.py b/diagnose/admin.py index 29c2e0c..7f4f248 100644 --- a/diagnose/admin.py +++ b/diagnose/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin # Register your models here. -from . models import Papers, OpenAIDiagnose +from . models import Papers, OpenAIDiagnose, Questions from django.urls import reverse from django.utils.html import format_html @@ -19,4 +19,8 @@ class OpenAIDiagnoseAdmin(admin.ModelAdmin): url = reverse('dia_report', args=[obj.pk]) # 生成链接 return format_html('查看', url) # 创建 HTML 链接 - custom_link.short_description = '详细信息' # 设置列标题 \ No newline at end of file + custom_link.short_description = '详细信息' # 设置列标题 + +@admin.register(Questions) +class QuestionAdmin(admin.ModelAdmin): + list_display = ('name', 'content') \ No newline at end of file diff --git a/diagnose/dp_views.py b/diagnose/dp_views.py index faa5eb3..c31dbf5 100644 --- a/diagnose/dp_views.py +++ b/diagnose/dp_views.py @@ -52,8 +52,6 @@ class DpArguments(): # 用字典中的数据恢复对象状态 self.__dict__.update(state) - - class MyProtectedGeneratePaper(APIView): authentication_classes = [CustomTokenAuthentication] # 使用自定义的 Token 认证 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,\ 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() user.subject_usage_count = user.subject_usage_count - 1 user.save() @@ -117,15 +116,35 @@ class MyProtectedGenerateCheck(APIView): except json.JSONDecodeError: return JsonResponse({"error": "Invalid JSON format"}, status=400) try: - # print(uuid_str) + # print("uuid: ", uuid_str) obj = Papers.objects.get(uuid=uuid_str, user=user) # 只获取一个对象 if obj.status == 'D': return JsonResponse({"status": "done", "download_url": f'/diagnose/download/?uuid_str={uuid_str}'}) else: return JsonResponse({"status": "processing", "download_url": None}) 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): authentication_classes = [CustomTokenAuthentication] # 使用自定义的 Token 认证 permission_classes = [IsAuthenticated] # 需要用户认证才能访问 diff --git a/diagnose/migrations/0004_questions.py b/diagnose/migrations/0004_questions.py new file mode 100644 index 0000000..f4c205d --- /dev/null +++ b/diagnose/migrations/0004_questions.py @@ -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()), + ], + ), + ] diff --git a/diagnose/migrations/0005_papers_subject_papers_text_version.py b/diagnose/migrations/0005_papers_subject_papers_text_version.py new file mode 100644 index 0000000..f9ef051 --- /dev/null +++ b/diagnose/migrations/0005_papers_subject_papers_text_version.py @@ -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), + ), + ] diff --git a/diagnose/models.py b/diagnose/models.py index 92b6db8..ae4ab64 100644 --- a/diagnose/models.py +++ b/diagnose/models.py @@ -2,6 +2,10 @@ from django.db import models from ec_user.models import EcUser # Create your models here. +class Questions(models.Model): + name = models.CharField(max_length=100) # 问题名称 + content = models.TextField() # 问题内容 + class Papers(models.Model): STATUS_CHOICES = ( ('C', '任务创建'), @@ -12,6 +16,8 @@ class Papers(models.Model): # 定义一个与EcUser一对多关联的外键 user = models.ForeignKey(EcUser, on_delete=models.CASCADE) # 当EcUser被删除时,关联的Papers也会被删除 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) # 创建时间 updated_at = models.DateTimeField(auto_now=True,null=True, blank=True) # 更新时间 diff --git a/diagnose/openai_dia.py b/diagnose/openai_dia.py index de654b6..abe9fa8 100644 --- a/diagnose/openai_dia.py +++ b/diagnose/openai_dia.py @@ -62,7 +62,8 @@ def openai_diagnoser_asyna_wraper(uuid_str: str, username: str, diagnose_type: s "content": [ { "type": "text", - "text": "图中是几个题目,我已经用笔作答了。通过我的作答情况给出本学科的学情分析。", + "text": """图中是几个题目,我已经用笔作答了,先帮我判题,然后通过我的作答情况给出本学科的学情分析。 + 从基础知识、学科素养、综合能力等方面给出学员指导意见""", }, { "type": "image_url", diff --git a/diagnose/urls.py b/diagnose/urls.py index 8cfd0df..6f6d4e5 100644 --- a/diagnose/urls.py +++ b/diagnose/urls.py @@ -1,6 +1,6 @@ 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 .views import dia_report, dia_report_update @@ -9,6 +9,7 @@ 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('user_papers_info/', MyProtectedUserPapersInfo.as_view(), name='api_user_papers_info'), path('upload/', MyProtectedUploadDiagnose.as_view(), name='api_upload_file'), path('upload_diagnose_check/', MyProtectedDiagnoseCheck.as_view(), name='api_diagnose_file'), diff --git a/ec_user/forms.py b/ec_user/forms.py index b072087..dcde108 100644 --- a/ec_user/forms.py +++ b/ec_user/forms.py @@ -12,55 +12,112 @@ class ContactInfoForm(forms.ModelForm): class Meta: model = ContactInfo fields = ['home_address', 'parent_contact', 'student_contact', 'email'] + labels = { + 'home_address': '家庭住址', + 'parent_contact': '家长联系方式', + 'student_contact': '学生联系方式', + 'email': '电子邮箱', + } # SchoolInfo 表单 class SchoolInfoForm(forms.ModelForm): class Meta: model = SchoolInfo fields = ['school_name', 'grade', 'class_name', 'admission_date', 'expected_graduation_date'] + labels = { + 'school_name': '学校名称', + 'grade': '年级', + 'class_name': '班级名称', + 'admission_date': '入学日期', + 'expected_graduation_date': '预计毕业日期', + } # AcademicInfo 表单 class AcademicInfoForm(forms.ModelForm): class Meta: model = AcademicInfo 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 表单 class HealthInfoForm(forms.ModelForm): class Meta: model = HealthInfo 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 表单 class SelfEvaluationForm(forms.ModelForm): class Meta: model = SelfEvaluation fields = ['strengths', 'weaknesses', 'study_attitude', 'future_plans'] + labels = { + 'strengths': '优点', + 'weaknesses': '缺点', + 'study_attitude': '学习态度', + 'future_plans': '未来计划', + } # HobbiesInterests 表单 class HobbiesInterestsForm(forms.ModelForm): class Meta: model = HobbiesInterests fields = ['interests', 'extracurricular_activities'] + labels = { + 'interests': '兴趣爱好', + 'extracurricular_activities': '课外活动', + } # SocialPractice 表单 class SocialPracticeForm(forms.ModelForm): class Meta: model = SocialPractice fields = ['activity_name', 'activity_date', 'activity_location', 'activity_description', 'activity_outcome'] + labels = { + 'activity_name': '活动名称', + 'activity_date': '活动日期', + 'activity_location': '活动地点', + 'activity_description': '活动描述', + 'activity_outcome': '活动成果', + } # FamilyInfo 表单 class FamilyInfoForm(forms.ModelForm): class Meta: model = FamilyInfo fields = ['family_member', 'economic_status'] + labels = { + 'family_member': '家庭成员', + 'economic_status': '经济状况', + } # AwardsPunishments 表单 class AwardsPunishmentsForm(forms.ModelForm): class Meta: model = AwardsPunishments 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 = { diff --git a/ec_user/migrations/0013_alter_ecuser_political_status.py b/ec_user/migrations/0013_alter_ecuser_political_status.py new file mode 100644 index 0000000..9c1f752 --- /dev/null +++ b/ec_user/migrations/0013_alter_ecuser_political_status.py @@ -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), + ), + ] diff --git a/ec_user/migrations/0014_alter_contactinfo_email_and_more.py b/ec_user/migrations/0014_alter_contactinfo_email_and_more.py new file mode 100644 index 0000000..0cae295 --- /dev/null +++ b/ec_user/migrations/0014_alter_contactinfo_email_and_more.py @@ -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), + ), + ] diff --git a/ec_user/migrations/0015_alter_hobbiesinterests_extracurricular_activities_and_more.py b/ec_user/migrations/0015_alter_hobbiesinterests_extracurricular_activities_and_more.py new file mode 100644 index 0000000..373fe7d --- /dev/null +++ b/ec_user/migrations/0015_alter_hobbiesinterests_extracurricular_activities_and_more.py @@ -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), + ), + ] diff --git a/ec_user/models.py b/ec_user/models.py index e56339c..1e8c013 100644 --- a/ec_user/models.py +++ b/ec_user/models.py @@ -99,18 +99,18 @@ class EcUser(AbstractUser): ('O', 'Other'), ] - name = models.CharField(max_length=100) - gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default='M') # 默认值设置为'M' - age = models.IntegerField(null=True, blank=True) # 允许为空,可以为null - ethnicity = models.CharField(max_length=50, default='Unknown') # 默认值设置为'Unknown' - dob = models.DateField(null=True, blank=True) # 允许为空,可以为null - id_card_number = models.CharField(max_length=18, unique=True) - political_status = models.CharField(max_length=50, default='Unknown') # 默认值设置为'Unknown' + name = models.CharField(max_length=100,verbose_name=("姓名")) + gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default='M', verbose_name=("性别")) # 默认值设置为'M' + age = models.IntegerField(null=True, blank=True, verbose_name=("年龄")) # 允许为空,可以为null + ethnicity = models.CharField(max_length=50, default='Unknown', verbose_name=("民族")) # 默认值设置为'Unknown' + dob = models.DateField(null=True, blank=True, verbose_name=("出生日期")) # 允许为空,可以为null + id_card_number = models.CharField(max_length=18, unique=True, verbose_name=("身份证号")) + 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): return self.name @@ -120,8 +120,8 @@ class ContactInfo(models.Model): user = models.OneToOneField(EcUser, on_delete=models.CASCADE) home_address = models.CharField(max_length=255) parent_contact = models.CharField(max_length=15) - student_contact = models.CharField(max_length=15) - email = models.EmailField() + student_contact = models.CharField(max_length=15, null=True, blank=True) + email = models.EmailField(null=True, blank=True) def __str__(self): return f"Contact Info of {self.user.name}" @@ -185,9 +185,9 @@ class HobbiesInterests(models.Model): # 定义一个与EcUser一对多关联的外键 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): # 返回用户的名字和兴趣爱好 diff --git a/ec_user/templates/all_info_form.html b/ec_user/templates/all_info_form.html index cdfd3b2..3aa7dcb 100644 --- a/ec_user/templates/all_info_form.html +++ b/ec_user/templates/all_info_form.html @@ -105,7 +105,7 @@

学习情况

-
+ {{ academic_info_form.as_p }}
diff --git a/educheck/settings.py b/educheck/settings.py index 3d66f7f..4e60857 100644 --- a/educheck/settings.py +++ b/educheck/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ """ from pathlib import Path +import os # __init__.py @@ -48,6 +49,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', # 添加这行 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', # 'django.middleware.csrf.CsrfViewMiddleware', @@ -134,8 +136,16 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ - 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 # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field