enroll app修改
This commit is contained in:
+22
-11
@@ -11,23 +11,22 @@ https://docs.djangoproject.com/en/4.0/ref/settings/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'django-insecure-@i80$q(g*+fof5(s2&^r#1=2+(@f=#=1$6!7&90=8v8lxg!y8h'
|
SECRET_KEY = 'django-insecure-0cn#v4ei2(^n+txyh4%3d5sllz6mknz#7t$!cq-d!ly*_rwvh2'
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
@@ -37,8 +36,11 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'enroll',
|
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
|
'enroll',
|
||||||
|
'history',
|
||||||
|
'comments',
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@@ -56,7 +58,7 @@ ROOT_URLCONF = 'ITShowPlatform.urls'
|
|||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [BASE_DIR / 'templates']
|
'DIRS': [os.path.join(BASE_DIR, 'templates')]
|
||||||
,
|
,
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
@@ -72,7 +74,6 @@ TEMPLATES = [
|
|||||||
|
|
||||||
WSGI_APPLICATION = 'ITShowPlatform.wsgi.application'
|
WSGI_APPLICATION = 'ITShowPlatform.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||||
|
|
||||||
@@ -87,7 +88,6 @@ DATABASES = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
@@ -106,29 +106,39 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'zh-Hans'
|
||||||
|
|
||||||
TIME_ZONE = 'Asia/Shanghai'
|
TIME_ZONE = 'Asia/Shanghai'
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
# USE_TZ = True
|
USE_L10N = True
|
||||||
|
|
||||||
|
USE_TZ = False
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = '/static/'
|
||||||
|
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||||||
|
MEDIA_URL = '/media/'
|
||||||
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
'DEFAULT_RENDERER_CLASSES': ( # 默认响应渲染类
|
||||||
|
'rest_framework.renderers.JSONRenderer', # json渲染器
|
||||||
|
'rest_framework.renderers.BrowsableAPIRenderer', # 浏览API渲染器
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
EMAIL_HOST = "smtp.qq.com" # 服务器
|
EMAIL_HOST = "smtp.qq.com" # 服务器
|
||||||
EMAIL_PORT = 465
|
EMAIL_PORT = 465
|
||||||
EMAIL_HOST_USER = "2302253692@qq.com" # 账号
|
EMAIL_HOST_USER = "2302253692@qq.com" # 账号
|
||||||
@@ -136,3 +146,4 @@ EMAIL_HOST_PASSWORD = "idujbpdlpgbmdhjg" # 密码 (注意:这里的密码指
|
|||||||
EMAIL_USE_SSL = True # 一般都为False
|
EMAIL_USE_SSL = True # 一般都为False
|
||||||
EMAIL_FROM = "2302253692@qq.com" # 邮箱来自
|
EMAIL_FROM = "2302253692@qq.com" # 邮箱来自
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from .models import Comments
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
admin.site.register(Comments)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class CommentsConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'comments'
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-04-15 14:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Comments',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('post_time', models.DateTimeField(verbose_name='发布时间')),
|
||||||
|
('content', models.CharField(max_length=50, verbose_name='弹幕内容')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class Comments(models.Model):
|
||||||
|
post_time = models.DateTimeField(verbose_name="发布时间")
|
||||||
|
content = models.CharField(verbose_name="弹幕内容", max_length=50, blank=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
|
class CommentsInfo(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Comments
|
||||||
|
fields = ['content', 'post_time']
|
||||||
|
|
||||||
|
post_time = serializers.DateTimeField(label="发布时间", required=False)
|
||||||
|
content = serializers.CharField(label="弹幕内容", max_length=50, required=True)
|
||||||
|
|
||||||
|
def validate_content(self, value):
|
||||||
|
ban = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', "_", "-"]
|
||||||
|
for i in ban:
|
||||||
|
if i in value:
|
||||||
|
raise serializers.ValidationError('非法字符')
|
||||||
|
|
||||||
|
if len(value) > 50:
|
||||||
|
raise serializers.ValidationError("弹幕过长")
|
||||||
|
elif len(value) == 0:
|
||||||
|
raise serializers.ValidationError("输入不能为空")
|
||||||
|
|
||||||
|
|
||||||
|
return value
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('comment/', views.comments.as_view()),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import time, datetime
|
||||||
|
from django.conf import settings
|
||||||
|
import re
|
||||||
|
from django.shortcuts import render
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from .models import *
|
||||||
|
from .serializers import CommentsInfo
|
||||||
|
from django.utils import timezone
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
class comments(APIView):
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
data = {}
|
||||||
|
queryset = Comments.objects.all()
|
||||||
|
serializer = CommentsInfo(queryset, many=True)
|
||||||
|
try:
|
||||||
|
data['data'] = serializer.data
|
||||||
|
except:
|
||||||
|
data['msg'] = serializer.error_messages
|
||||||
|
if len(data['data']) == 0:
|
||||||
|
data['msg'] = 'error'
|
||||||
|
data['code'] = "40000"
|
||||||
|
else:
|
||||||
|
data['msg'] = "success"
|
||||||
|
data['code'] = "20000"
|
||||||
|
return Response(data=data)
|
||||||
|
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
data = {}
|
||||||
|
serializer = CommentsInfo(data=request.data)
|
||||||
|
if not serializer.is_valid(raise_exception=True):
|
||||||
|
data['msg'] = serializer.error_messages
|
||||||
|
data['code'] = "40000"
|
||||||
|
return Response(data=data)
|
||||||
|
serializer.validated_data['post_time'] = timezone.now().replace(microsecond=0)
|
||||||
|
serializer.save()
|
||||||
|
data['data'] = serializer.validated_data
|
||||||
|
data['msg'] = "success"
|
||||||
|
data['code'] = "20000"
|
||||||
|
return Response(data=data)
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.0.4 on 2022-04-17 13:12
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('enroll', '0003_alter_new_member_email_alter_new_member_phone_number'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='emailverifyrecord',
|
||||||
|
name='send_time',
|
||||||
|
field=models.DateTimeField(auto_now_add=True, verbose_name='发送时间'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.0.4 on 2022-04-17 21:29
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('enroll', '0004_alter_emailverifyrecord_send_time'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='emailverifyrecord',
|
||||||
|
name='code',
|
||||||
|
field=models.CharField(max_length=5, verbose_name='验证码'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from .models import History
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
admin.site.register(History)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'history'
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-04-15 14:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='History',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('grade', models.IntegerField(verbose_name='年份')),
|
||||||
|
('name', models.CharField(max_length=30, verbose_name='事件名称')),
|
||||||
|
('description', models.CharField(max_length=200, verbose_name='事件描述')),
|
||||||
|
('img', models.ImageField(upload_to='', verbose_name='图片')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-04-15 14:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('history', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='history',
|
||||||
|
name='img',
|
||||||
|
field=models.ImageField(upload_to='image', verbose_name='图片'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-04-15 23:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('history', '0002_alter_history_img'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='history',
|
||||||
|
name='img',
|
||||||
|
field=models.ImageField(upload_to='', verbose_name='图片'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class History(models.Model):
|
||||||
|
grade = models.IntegerField(verbose_name="年份")
|
||||||
|
name = models.CharField(verbose_name="事件名称", max_length=30)
|
||||||
|
description = models.CharField(verbose_name="事件描述", max_length=200)
|
||||||
|
img = models.ImageField(verbose_name="图片", upload_to="image")
|
||||||
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryInfoSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = History
|
||||||
|
fields = '__all__'
|
||||||
|
grade = serializers.CharField(label="年级", required=True)
|
||||||
|
name = serializers.CharField(label="事件名称", max_length=30, required=True)
|
||||||
|
description = serializers.CharField(label="事件描述", max_length=200, required=True)
|
||||||
|
img = serializers.ImageField(label="图片", required=False)
|
||||||
|
|
||||||
|
def validate_grade(self, value):
|
||||||
|
if not (2010 < value <= 2021):
|
||||||
|
raise serializers.ValidationError("不合法输入")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
from django.conf.urls.static import static
|
||||||
|
from ITShowPlatform import settings
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('history/', views.history.as_view()),
|
||||||
|
]
|
||||||
|
|
||||||
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import time
|
||||||
|
from django.conf import settings
|
||||||
|
import re
|
||||||
|
from django.shortcuts import render
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from .models import History
|
||||||
|
from .serializers import HistoryInfoSerializer
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
class history(APIView):
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
key = []
|
||||||
|
data = {"data": key}
|
||||||
|
for i in range(2012, 2022):
|
||||||
|
temp = {}
|
||||||
|
try:
|
||||||
|
works_set = History.objects.filter(grade=i)
|
||||||
|
if works_set:
|
||||||
|
serializer = HistoryInfoSerializer(works_set, many=True)
|
||||||
|
temp['grade'] = i
|
||||||
|
temp['data'] = serializer.data
|
||||||
|
data['data'].append(temp)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if len(data['data']) == 0:
|
||||||
|
data['code'] = 40000
|
||||||
|
data['msg'] = "error"
|
||||||
|
else:
|
||||||
|
data['code'] = 20000
|
||||||
|
data['msg'] = 'success'
|
||||||
|
return Response(data=data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 81 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 720 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
Reference in New Issue
Block a user