diff --git a/SSCM/.idea/.gitignore b/SSCM/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/SSCM/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/SSCM/.idea/SSCM.iml b/SSCM/.idea/SSCM.iml new file mode 100644 index 0000000..4c65dab --- /dev/null +++ b/SSCM/.idea/SSCM.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SSCM/.idea/inspectionProfiles/profiles_settings.xml b/SSCM/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/SSCM/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/SSCM/.idea/misc.xml b/SSCM/.idea/misc.xml new file mode 100644 index 0000000..52d3769 --- /dev/null +++ b/SSCM/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/SSCM/.idea/modules.xml b/SSCM/.idea/modules.xml new file mode 100644 index 0000000..3b163bc --- /dev/null +++ b/SSCM/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/SSCM/SSCM/__init__.py b/SSCM/SSCM/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SSCM/SSCM/__pycache__/__init__.cpython-312.pyc b/SSCM/SSCM/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..606b080 Binary files /dev/null and b/SSCM/SSCM/__pycache__/__init__.cpython-312.pyc differ diff --git a/SSCM/SSCM/__pycache__/settings.cpython-312.pyc b/SSCM/SSCM/__pycache__/settings.cpython-312.pyc new file mode 100644 index 0000000..76aaa5f Binary files /dev/null and b/SSCM/SSCM/__pycache__/settings.cpython-312.pyc differ diff --git a/SSCM/SSCM/__pycache__/urls.cpython-312.pyc b/SSCM/SSCM/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..0b2c36c Binary files /dev/null and b/SSCM/SSCM/__pycache__/urls.cpython-312.pyc differ diff --git a/SSCM/SSCM/__pycache__/wsgi.cpython-312.pyc b/SSCM/SSCM/__pycache__/wsgi.cpython-312.pyc new file mode 100644 index 0000000..d66f656 Binary files /dev/null and b/SSCM/SSCM/__pycache__/wsgi.cpython-312.pyc differ diff --git a/SSCM/SSCM/asgi.py b/SSCM/SSCM/asgi.py new file mode 100644 index 0000000..32313fa --- /dev/null +++ b/SSCM/SSCM/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for SSCM project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SSCM.settings') + +application = get_asgi_application() diff --git a/SSCM/SSCM/settings.py b/SSCM/SSCM/settings.py new file mode 100644 index 0000000..2539fda --- /dev/null +++ b/SSCM/SSCM/settings.py @@ -0,0 +1,128 @@ +""" +Django settings for SSCM project. + +Generated by 'django-admin startproject' using Django 3.2.25. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-vl@t)9s7=wylo=6a49w$pu8(k1&k(hn4$5-4nq^&u&#uo$zzm@' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'user', + 'course', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'SSCM.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [BASE_DIR / 'templates'] + , + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'SSCM.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/SSCM/SSCM/urls.py b/SSCM/SSCM/urls.py new file mode 100644 index 0000000..32ef3ee --- /dev/null +++ b/SSCM/SSCM/urls.py @@ -0,0 +1,21 @@ +"""SSCM URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path,include + +urlpatterns = [ + path('user/', include("user.urls")), +] diff --git a/SSCM/SSCM/wsgi.py b/SSCM/SSCM/wsgi.py new file mode 100644 index 0000000..329ec01 --- /dev/null +++ b/SSCM/SSCM/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for SSCM project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SSCM.settings') + +application = get_wsgi_application() diff --git a/SSCM/__pycache__/constants.cpython-312.pyc b/SSCM/__pycache__/constants.cpython-312.pyc new file mode 100644 index 0000000..ced84d0 Binary files /dev/null and b/SSCM/__pycache__/constants.cpython-312.pyc differ diff --git a/SSCM/constants.py b/SSCM/constants.py new file mode 100644 index 0000000..d53129b --- /dev/null +++ b/SSCM/constants.py @@ -0,0 +1 @@ +INVALID_KIND="Invalid kind.Kind should be one or teacher." \ No newline at end of file diff --git a/SSCM/course/__init__.py b/SSCM/course/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SSCM/course/__pycache__/__init__.cpython-312.pyc b/SSCM/course/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..e533e5a Binary files /dev/null and b/SSCM/course/__pycache__/__init__.cpython-312.pyc differ diff --git a/SSCM/course/__pycache__/admin.cpython-312.pyc b/SSCM/course/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..68cb1c2 Binary files /dev/null and b/SSCM/course/__pycache__/admin.cpython-312.pyc differ diff --git a/SSCM/course/__pycache__/apps.cpython-312.pyc b/SSCM/course/__pycache__/apps.cpython-312.pyc new file mode 100644 index 0000000..c137ed3 Binary files /dev/null and b/SSCM/course/__pycache__/apps.cpython-312.pyc differ diff --git a/SSCM/course/__pycache__/models.cpython-312.pyc b/SSCM/course/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..2d5ec5f Binary files /dev/null and b/SSCM/course/__pycache__/models.cpython-312.pyc differ diff --git a/SSCM/course/admin.py b/SSCM/course/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/SSCM/course/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/SSCM/course/apps.py b/SSCM/course/apps.py new file mode 100644 index 0000000..25f0187 --- /dev/null +++ b/SSCM/course/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CourseConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'course' diff --git a/SSCM/course/migrations/__init__.py b/SSCM/course/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SSCM/course/migrations/__pycache__/__init__.cpython-312.pyc b/SSCM/course/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..73e58ae Binary files /dev/null and b/SSCM/course/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/SSCM/course/models.py b/SSCM/course/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/SSCM/course/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/SSCM/course/tests.py b/SSCM/course/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/SSCM/course/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/SSCM/course/views.py b/SSCM/course/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/SSCM/course/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/SSCM/db.sqlite3 b/SSCM/db.sqlite3 new file mode 100644 index 0000000..1835102 Binary files /dev/null and b/SSCM/db.sqlite3 differ diff --git a/SSCM/manage.py b/SSCM/manage.py new file mode 100644 index 0000000..5c15485 --- /dev/null +++ b/SSCM/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SSCM.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/SSCM/templates/user/background.html b/SSCM/templates/user/background.html new file mode 100644 index 0000000..bd34976 --- /dev/null +++ b/SSCM/templates/user/background.html @@ -0,0 +1,23 @@ + + + + + + 学生选课管理系统 + + + +
+
+
学生选课管理系统
+
Student Course Management System
+ {% block welcome_message %} + {% endblock %} +
+
+ {% block login_container %} + {% endblock %} +
+
+ + \ No newline at end of file diff --git a/SSCM/templates/user/login_detail.html b/SSCM/templates/user/login_detail.html new file mode 100644 index 0000000..3ae1c9d --- /dev/null +++ b/SSCM/templates/user/login_detail.html @@ -0,0 +1,30 @@ +{% extends "user/background.html" %} +{% block welcome_message %} + {% if from_url == 'register' %} +
注册成功,你的 + {% if kind == "student" %}学号{% else %}账号{% endif %}是{{ uid }}
+ {% else %} +
欢迎
+ {% endif %} +
欢迎
+{% endblock %} +{% block login_container %} + {% if kind == "student" %} +
我是学生
+ {% else %} +
我是教师
+ {% endif %} +
+
+ {% csrf_token %} + {{ form.as_p }} +
+ + 注册 +
+
+
+ 返回上一页 +
+
+{% endblock %} \ No newline at end of file diff --git a/SSCM/templates/user/login_home.html b/SSCM/templates/user/login_home.html new file mode 100644 index 0000000..10c3e25 --- /dev/null +++ b/SSCM/templates/user/login_home.html @@ -0,0 +1,9 @@ +{% extends "user/background.html" %} +{% block login_container %} +
+ 学生登录 +
+
+ 教师登录 +
+{% endblock %} \ No newline at end of file diff --git a/SSCM/templates/user/register.html b/SSCM/templates/user/register.html new file mode 100644 index 0000000..277d6ea --- /dev/null +++ b/SSCM/templates/user/register.html @@ -0,0 +1,21 @@ + + + + + + 注册 + + + +
+
注册
+
+ {% csrf_token %} + {{ form.as_p }} +

+ +

+
+
+ + \ No newline at end of file diff --git a/SSCM/user/__init__.py b/SSCM/user/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SSCM/user/__pycache__/__init__.cpython-312.pyc b/SSCM/user/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..8f89d03 Binary files /dev/null and b/SSCM/user/__pycache__/__init__.cpython-312.pyc differ diff --git a/SSCM/user/__pycache__/admin.cpython-312.pyc b/SSCM/user/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..3b0c6b9 Binary files /dev/null and b/SSCM/user/__pycache__/admin.cpython-312.pyc differ diff --git a/SSCM/user/__pycache__/apps.cpython-312.pyc b/SSCM/user/__pycache__/apps.cpython-312.pyc new file mode 100644 index 0000000..834edac Binary files /dev/null and b/SSCM/user/__pycache__/apps.cpython-312.pyc differ diff --git a/SSCM/user/__pycache__/cbvs.cpython-312.pyc b/SSCM/user/__pycache__/cbvs.cpython-312.pyc new file mode 100644 index 0000000..59f08ab Binary files /dev/null and b/SSCM/user/__pycache__/cbvs.cpython-312.pyc differ diff --git a/SSCM/user/__pycache__/forms.cpython-312.pyc b/SSCM/user/__pycache__/forms.cpython-312.pyc new file mode 100644 index 0000000..2605869 Binary files /dev/null and b/SSCM/user/__pycache__/forms.cpython-312.pyc differ diff --git a/SSCM/user/__pycache__/models.cpython-312.pyc b/SSCM/user/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..f2236af Binary files /dev/null and b/SSCM/user/__pycache__/models.cpython-312.pyc differ diff --git a/SSCM/user/__pycache__/urls.cpython-312.pyc b/SSCM/user/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..52fc5d8 Binary files /dev/null and b/SSCM/user/__pycache__/urls.cpython-312.pyc differ diff --git a/SSCM/user/__pycache__/views.cpython-312.pyc b/SSCM/user/__pycache__/views.cpython-312.pyc new file mode 100644 index 0000000..28f15f1 Binary files /dev/null and b/SSCM/user/__pycache__/views.cpython-312.pyc differ diff --git a/SSCM/user/admin.py b/SSCM/user/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/SSCM/user/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/SSCM/user/apps.py b/SSCM/user/apps.py new file mode 100644 index 0000000..36cce4c --- /dev/null +++ b/SSCM/user/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UserConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'user' diff --git a/SSCM/user/cbvs.py b/SSCM/user/cbvs.py new file mode 100644 index 0000000..bbfaf6f --- /dev/null +++ b/SSCM/user/cbvs.py @@ -0,0 +1,71 @@ +from django.shortcuts import reverse,redirect +from django.views.generic import CreateView + +from user.forms import StuRegisterForm,TeaRegisterFrom + +from user.models import Student,Teacher +import random + + + +class CreateStudentView(CreateView): + model=Student + form_class=StuRegisterForm + template_name="user/register.html" + success_url="login" + + def form_valid(self,form): + grade=form.cleaned_data['grade'] + student_set=Student.objects.filter(grade=grade).order_by("-number") + if student_set.count()>0: + last_student=student_set[0] + new_number=str(int(last_student.number)+1) + for i in range(6-len(new_number)): + new_number='0'+new_number + else: + new_number='000001' + new_student=form.save(commit=False) + new_student.number=new_number + new_student.save() + + form.save_m2m() + + self.object=new_student + + uid=grade+new_number + from_url="register" + base_url=reverse(self.get_success_url(),kwargs={'kind':'student'}) + return redirect(base_url+'?uid=%sfrom_url=%s' % (uid,from_url)) + + +class CreateTeacherView(CreateView): + model=Teacher + form_class=TeaRegisterFrom + template_name="user/register.html" + success_url="login" + + def form_valid(self,form): + department_no=random.randint(0,300) + department_no='{:0>3}'.format(department_no) + teacher_set=Teacher.objects.filter(department_no=department_no).order_by("-number") + if teacher_set.count>0: + last_teacher=teacher_set[0] + new_number=str(int(last_teacher.number)+1) + new_number='{:0>7}'.format(new_number) + + + else: + new_number='0000001' + + new_teacher=form.save(commit=False) + new_teacher.number=department_no + new_teacher.save() + + form.save_m2m() + + self.object=new_teacher + + uid=department_no+new_number + from_url="register" + base_url=reverse(self.get_success_url(),kwargs={'kind':'teacher'}) + return redirect(base_url+'?uid=%sfrom_url=%s' % (uid,from_url)) \ No newline at end of file diff --git a/SSCM/user/forms.py b/SSCM/user/forms.py new file mode 100644 index 0000000..5b3bdce --- /dev/null +++ b/SSCM/user/forms.py @@ -0,0 +1,34 @@ +from django import forms +from user.models import Student , Teacher +class StuLoginForm(forms.Form): + uid=forms.CharField(label='学号', max_length=10) + password=forms.CharField(label='密码', max_length=30, widget=forms.PasswordInput) + +class TeaLoginForm(forms.Form): + uid=forms.CharField(label='教职工号',max_length=10) + password=forms.CharField(label='密码',max_length=30,widget=forms.PasswordInput) +class StuRegisterForm(forms.ModelForm): + confirm_password=forms.CharField(label='确认密码',widget=forms.PasswordInput) + + class Meta: + model=Student + fields=('grade','name','password','confirm_password','gender','birthday','email','info') + def clean(self): + clean_data=super(StuRegisterForm,self).clean() + password=clean_data.get('password') + confirm_password=clean_data.get('confirm_password','Password does not match') + + return clean_data + +class TeaRegisterFrom(forms.ModelForm): + confirm_password=forms.CharField(label='确认密码',widget=forms.PasswordInput) + + class Meta: + model=Teacher + fields=('name','password','confirm_password','gender','birthday','email','info') + def clean(self): + clean_data=super(TeaRegisterFrom,self).clean() + password=clean_data.get('password') + confirm_password=clean_data.get('confirm_password','Password does not match') + + return clean_data \ No newline at end of file diff --git a/SSCM/user/migrations/0001_initial.py b/SSCM/user/migrations/0001_initial.py new file mode 100644 index 0000000..f3c922d --- /dev/null +++ b/SSCM/user/migrations/0001_initial.py @@ -0,0 +1,46 @@ +# Generated by Django 3.2.25 on 2024-05-14 05:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Student', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50, verbose_name='姓名')), + ('gender', models.CharField(choices=[('m', '男'), ('f', '女')], default='m', max_length=10, verbose_name='性别')), + ('birthday', models.DateField(verbose_name='生日')), + ('email', models.EmailField(max_length=254, verbose_name='邮箱')), + ('info', models.CharField(help_text='一句话概括自己,不超过250字', max_length=255, verbose_name='个人简介')), + ('grade', models.CharField(max_length=4, verbose_name='年级')), + ('number', models.CharField(max_length=20, verbose_name='级内学号')), + ('password', models.CharField(max_length=30, verbose_name='密码')), + ], + ), + migrations.CreateModel( + name='Teacher', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50, verbose_name='姓名')), + ('gender', models.CharField(choices=[('m', '男'), ('f', '女')], default='m', max_length=10, verbose_name='性别')), + ('birthday', models.DateField(verbose_name='生日')), + ('email', models.EmailField(max_length=254, verbose_name='邮箱')), + ('info', models.CharField(help_text='不要超过250字', max_length=255, verbose_name='教师简介')), + ('department_no', models.CharField(max_length=3, verbose_name='院系号')), + ('number', models.CharField(max_length=7, verbose_name='院内编号')), + ('password', models.CharField(max_length=30, verbose_name='密码')), + ], + ), + migrations.AddConstraint( + model_name='student', + constraint=models.UniqueConstraint(fields=('gender', 'number'), name='student_id'), + ), + ] diff --git a/SSCM/user/migrations/0002_teacher_teacher_id.py b/SSCM/user/migrations/0002_teacher_teacher_id.py new file mode 100644 index 0000000..b91b592 --- /dev/null +++ b/SSCM/user/migrations/0002_teacher_teacher_id.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.25 on 2024-05-14 05:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('user', '0001_initial'), + ] + + operations = [ + migrations.AddConstraint( + model_name='teacher', + constraint=models.UniqueConstraint(fields=('department_no', 'number'), name='teacher_id'), + ), + ] diff --git a/SSCM/user/migrations/__init__.py b/SSCM/user/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SSCM/user/migrations/__pycache__/0001_initial.cpython-312.pyc b/SSCM/user/migrations/__pycache__/0001_initial.cpython-312.pyc new file mode 100644 index 0000000..3582b94 Binary files /dev/null and b/SSCM/user/migrations/__pycache__/0001_initial.cpython-312.pyc differ diff --git a/SSCM/user/migrations/__pycache__/0002_teacher_teacher_id.cpython-312.pyc b/SSCM/user/migrations/__pycache__/0002_teacher_teacher_id.cpython-312.pyc new file mode 100644 index 0000000..1918206 Binary files /dev/null and b/SSCM/user/migrations/__pycache__/0002_teacher_teacher_id.cpython-312.pyc differ diff --git a/SSCM/user/migrations/__pycache__/__init__.cpython-312.pyc b/SSCM/user/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..d7fedb5 Binary files /dev/null and b/SSCM/user/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/SSCM/user/models.py b/SSCM/user/models.py new file mode 100644 index 0000000..f0427d3 --- /dev/null +++ b/SSCM/user/models.py @@ -0,0 +1,49 @@ +from django.db import models + +genders = [ + ('m', '男'), + ('f', '女') +] +# Create your models here. +class Student(models.Model): + + name=models.CharField(max_length=50,verbose_name="姓名") + gender=models.CharField(max_length=10,choices=genders,default='m',verbose_name="性别") + birthday=models.DateField(verbose_name='生日') + email=models.EmailField(verbose_name="邮箱") + info=models.CharField(max_length=255,verbose_name='个人简介',help_text='一句话概括自己,不超过250字') + grade=models.CharField(max_length=4,verbose_name='年级') + number=models.CharField(max_length=20,verbose_name='级内学号') + password=models.CharField(max_length=30,verbose_name='密码') + + class Meta: + constraints=[ + models.UniqueConstraint(fields=['gender','number'],name='student_id') + ] + def get_id(self): + return "%s%s" %(self.grade,self.number) + + def __str__(self): + return "%s (%s)" % (self.get_id(),self.name) + +class Teacher(models.Model): + + name=models.CharField(max_length=50,verbose_name="姓名") + gender=models.CharField(max_length=10,choices=genders,default='m',verbose_name="性别") + birthday=models.DateField(verbose_name='生日') + email=models.EmailField(verbose_name='邮箱') + info=models.CharField(max_length=255,verbose_name='教师简介',help_text='不要超过250字') + + department_no=models.CharField(max_length=3,verbose_name='院系号') + number=models.CharField(max_length=7,verbose_name='院内编号') + password=models.CharField(max_length=30,verbose_name='密码') + + class Meta: + constraints=[ + models.UniqueConstraint(fields=['department_no','number'],name='teacher_id') + ] + def get_id(self): + return "%s%s" % (self.department_no,self.number) + + def __str__(self): + return "%s (%s)" % (self.get_id(),self.name) diff --git a/SSCM/user/tests.py b/SSCM/user/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/SSCM/user/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/SSCM/user/urls.py b/SSCM/user/urls.py new file mode 100644 index 0000000..895657b --- /dev/null +++ b/SSCM/user/urls.py @@ -0,0 +1,8 @@ +from user import views +from django.urls import path + +urlpatterns = [ + path('login/', views.home, name="login"), + path('login/',views.login,name="login"), + path('register/',views.register,name='register') +] \ No newline at end of file diff --git a/SSCM/user/views.py b/SSCM/user/views.py new file mode 100644 index 0000000..242d852 --- /dev/null +++ b/SSCM/user/views.py @@ -0,0 +1,67 @@ +from django.shortcuts import render +from django.http.response import HttpResponse + +from constants import INVALID_KIND +from user.forms import StuLoginForm, TeaLoginForm +from user.cbvs import CreateStudentView,CreateTeacherView + +def home(request): + return render(request, "user/login_home.html") + + +def login(request, *args, **kwargs): + if not kwargs or "kind" not in kwargs or kwargs["kind"] not in ["teacher", "student"]: + return HttpResponse(INVALID_KIND) + + kind=kwargs["kind"] + + + if request.method=='POST': + if kind == "teacher": + form=TeaLoginForm(data=request.POST) + else: + form=StuLoginForm(data=request.POST) + + if form.is_valid(): + uid=form.cleaned_data['uid'] + + temp_res="hello,%s" % uid + return HttpResponse(temp_res) + + elif request.method=='GET': + context = {'kind': kind} + if request.GET.get('uid'): + uid=request.GET.get('uid') + context['uid']=uid + data={'uid':uid,'password':'123456789'} + if kind =='teacher': + form=TeaLoginForm(data) + else: + form=StuLoginForm(data) + + else: + + if kind =='teacher': + form=TeaLoginForm() + else: + form=StuLoginForm() + context['form']=form + if request.GET.get('from_url'): + context['from_url']=request.GET.get('from_url') + + return render(request, 'user/login_detail.html', context) + + + +def register(request,kind): + func=None + if kind == 'student': + func=CreateStudentView.as_view() + elif kind =='teacher': + func=CreateTeacherView.as_view() + + if func: + return func(request) + else: + return HttpResponse(INVALID_KIND) +