修改了一些模型
配置了django托管静态文件 Debug=False
This commit is contained in:
parent
a80e18dc83
commit
bb3d03b26d
@ -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
|
||||
@ -20,3 +20,7 @@ class OpenAIDiagnoseAdmin(admin.ModelAdmin):
|
||||
return format_html('<a href="{}">查看</a>', url) # 创建 HTML 链接
|
||||
|
||||
custom_link.short_description = '详细信息' # 设置列标题
|
||||
|
||||
@admin.register(Questions)
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'content')
|
||||
@ -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,14 +116,34 @@ 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 认证
|
||||
|
||||
21
diagnose/migrations/0004_questions.py
Normal file
21
diagnose/migrations/0004_questions.py
Normal 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()),
|
||||
],
|
||||
),
|
||||
]
|
||||
@ -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),
|
||||
),
|
||||
]
|
||||
@ -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) # 更新时间
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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'),
|
||||
|
||||
@ -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 = {
|
||||
|
||||
18
ec_user/migrations/0013_alter_ecuser_political_status.py
Normal file
18
ec_user/migrations/0013_alter_ecuser_political_status.py
Normal 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),
|
||||
),
|
||||
]
|
||||
23
ec_user/migrations/0014_alter_contactinfo_email_and_more.py
Normal file
23
ec_user/migrations/0014_alter_contactinfo_email_and_more.py
Normal 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),
|
||||
),
|
||||
]
|
||||
@ -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),
|
||||
),
|
||||
]
|
||||
@ -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):
|
||||
# 返回用户的名字和兴趣爱好
|
||||
|
||||
@ -105,7 +105,7 @@
|
||||
<!-- 学习情况 -->
|
||||
<div class="form-section">
|
||||
<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">
|
||||
<label for="subject1">语文</label>
|
||||
<input type="text" id="subject1" name="subject1">
|
||||
@ -203,7 +203,7 @@
|
||||
})
|
||||
})
|
||||
</script>
|
||||
</div>
|
||||
</div> -->
|
||||
{{ academic_info_form.as_p }}
|
||||
</div>
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user