From bf9de457022ee8df307430491bc244d9886cba6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=20=E4=BA=9A=E5=AE=81?= <1553770945@qq.com> Date: Mon, 16 Nov 2020 22:29:18 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=87=87=E7=94=A8=E8=AF=BB=E5=85=A5=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HomeWork/settings.py | 16 +++++++++++++--- main.ini | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 main.ini diff --git a/HomeWork/settings.py b/HomeWork/settings.py index d2fe494..193f158 100644 --- a/HomeWork/settings.py +++ b/HomeWork/settings.py @@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/ from pathlib import Path import os - +from common.common import conf # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -76,10 +76,20 @@ WSGI_APPLICATION = 'HomeWork.wsgi.application' # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': BASE_DIR / 'db.sqlite3', +# } +# } DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'homework', + 'USER':conf.get("mysql","username"), + 'PASSWORD':conf.get("mysql","password"), + 'HOST':conf.get("mysql","host"), + 'PORT':'3306', } } diff --git a/main.ini b/main.ini new file mode 100644 index 0000000..db3f959 --- /dev/null +++ b/main.ini @@ -0,0 +1,4 @@ +[mysql] +username=username +password=password +host=localhost \ No newline at end of file -- Gitee From ed937d661d350bde965eec2b5e9f0dfa0ae8f789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=20=E4=BA=9A=E5=AE=81?= <1553770945@qq.com> Date: Tue, 17 Nov 2020 11:44:03 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HomeWork/urls.py | 32 ++++++++++++++++---------------- work/views.py | 6 +++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/HomeWork/urls.py b/HomeWork/urls.py index b809d42..86fda79 100644 --- a/HomeWork/urls.py +++ b/HomeWork/urls.py @@ -19,21 +19,21 @@ from login.views import LoginView,LogOutView,MeView,RegisterView from work.views import HomeWorkView,MyHomeWorkNumView,MyHomeWorkView,SubmitView,DownloadView,ExportView,DoneListView from group.views import GroupView,MyGroupNumView,MyGroupView,GroupMembersView urlpatterns = [ - path('admin/', admin.site.urls), - path('login/',LoginView.as_view()), - path('logout/',LogOutView.as_view()), - path('me/',MeView.as_view()), - path('homework/',HomeWorkView.as_view()), - path('myhomeworknum/',MyHomeWorkNumView.as_view()), - path('myhomework/',MyHomeWorkView.as_view()), - path('submit/',SubmitView.as_view(),), - path('group/',GroupView.as_view()), - path('mygroup/',MyGroupView.as_view()), - path('mygroupnum/',MyGroupNumView.as_view()), - path('register/',RegisterView.as_view()), - path('groupmembers/',GroupMembersView.as_view()), - path('download/',DownloadView.as_view()), - path('export/',ExportView.as_view()), - path('donelist/',DoneListView.as_view()), + path('api/admin/', admin.site.urls), + path('api/login/',LoginView.as_view()), + path('api/logout/',LogOutView.as_view()), + path('api/me/',MeView.as_view()), + path('api/homework/',HomeWorkView.as_view()), + path('api/myhomeworknum/',MyHomeWorkNumView.as_view()), + path('api/myhomework/',MyHomeWorkView.as_view()), + path('api/submit/',SubmitView.as_view(),), + path('api/group/',GroupView.as_view()), + path('api/mygroup/',MyGroupView.as_view()), + path('api/mygroupnum/',MyGroupNumView.as_view()), + path('api/register/',RegisterView.as_view()), + path('api/groupmembers/',GroupMembersView.as_view()), + path('api/download/',DownloadView.as_view()), + path('api/export/',ExportView.as_view()), + path('api/donelist/',DoneListView.as_view()), ] diff --git a/work/views.py b/work/views.py index c594866..9960de0 100644 --- a/work/views.py +++ b/work/views.py @@ -529,16 +529,16 @@ class ExportView(APIView): return Response(context) else: if export.get_error_status(): - context['er_code'] = 5001 + context['err_code'] = 5001 context['error'] = export.get_error() return Response(context) if export.get_done_status(): status = data.get('status') if status is not None: - context['er_code'] = 0 + context['err_code'] = 0 context['data'] = dict() - context['done'] = True + context['data']['done'] = True return Response(context) else: file = export.file_name -- Gitee From 3f48ed47d229b343c445f3891baf30f6032c8fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=20=E4=BA=9A=E5=AE=81?= <1553770945@qq.com> Date: Tue, 17 Nov 2020 12:33:59 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=8E=8B=E7=BC=A9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=9C=A8=E5=A4=96=E9=83=A8=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=EF=BC=8C=E9=83=A8=E5=88=86=E8=AE=BE=E7=BD=AE=E4=BB=8E=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HomeWork/settings.py | 4 ++-- work/views.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/HomeWork/settings.py b/HomeWork/settings.py index 193f158..bf65f7b 100644 --- a/HomeWork/settings.py +++ b/HomeWork/settings.py @@ -20,10 +20,10 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'x7(a(2*+u=vu(86j^+j=^3xo94m3*bf^-p1_dvhv=768@5=g@@' +SECRET_KEY = conf.get("django","secret_key") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = bool(conf.get("django","debug")) ALLOWED_HOSTS = ['*'] diff --git a/work/views.py b/work/views.py index 9960de0..f4e3713 100644 --- a/work/views.py +++ b/work/views.py @@ -608,7 +608,8 @@ def export_thread(dir_path, work_id): class ExportThread: def __init__(self, dir_path, work_id): self.dir_path = dir_path - self.file_name = os.path.join(self.dir_path, 'export.zip') + import time + self.file_name = os.path.join(os.path.abspath(os.path.dirname(dir_path)+os.path.sep+"."), 'export{}.zip'.format(str(time.time()))) self.is_done = False self.error = False self.err_msg = '' -- Gitee From 3cc26d4c8a5398b2f0bcf96341e10fd6e7059ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=20=E4=BA=9A=E5=AE=81?= <1553770945@qq.com> Date: Sun, 22 Nov 2020 23:06:02 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=B8=8D=E8=83=BD=E6=9B=B4=E6=96=B0=E7=9A=84?= =?UTF-8?q?BUG=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- README.md | 10 +++++++++- r.txt | 9 +++++++++ work/models.py | 1 - work/views.py | 16 ++++++---------- 5 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 r.txt diff --git a/.gitignore b/.gitignore index 5ab05f5..723ab0e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ venv .idea /*/migrations *.pyc -file \ No newline at end of file +file +*.docx +main.ini \ No newline at end of file diff --git a/README.md b/README.md index 74bf214..95be44e 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,12 @@ Django 3.1.2 +Django Rest Framework 3.12.1 ## 返回说明 本项目利用Django Rest Framework提供API,并遵循以下原则: -每个api必定返回err_code,用来标识本次操作结果,err_code=表示请求成功。 \ No newline at end of file +每个api必定返回err_code,用来标识本次操作结果,err_code不为0表示请求失败,同时返回error为错误原因,err_code=0表示请求成功,所有数据都在data里面,以下所说返回参数无特殊说明均为data里。 +## 各个api说明 +| API | 请求方式 | 请求参数 | 说明 | +| - | - | - | + +| API | 请求方式 | 请求参数 | 说明 | 返回参数 | 返回类型 +| ---- | ---- | ---- | ---- | ---- | ---- | +| login | GET | 无 |检测是否登录 | done + diff --git a/r.txt b/r.txt new file mode 100644 index 0000000..db08e53 --- /dev/null +++ b/r.txt @@ -0,0 +1,9 @@ +asgiref==3.2.10 +Django==3.1.2 +djangorestframework==3.12.1 +mysqlclient==2.0.1 +pypandoc==1.5 +PySnooper==0.4.2 +pytz==2020.1 +six==1.15.0 +sqlparse==0.4.1 diff --git a/work/models.py b/work/models.py index 03c6d86..96c0d0a 100644 --- a/work/models.py +++ b/work/models.py @@ -60,7 +60,6 @@ def create_homework_members(sender, instance, **kwargs): def change_end_time(sender, instance, **kwargs): - logger.critical("触发一次次改截止时间") HomeWorkMembersModel.objects.filter(work=instance).update(end_time=instance.end_time) diff --git a/work/views.py b/work/views.py index f4e3713..e8ed891 100644 --- a/work/views.py +++ b/work/views.py @@ -175,16 +175,12 @@ class HomeWorkView(APIView): context['err_code'] = 4003 context['error'] = "您无权执行此操作" return Response(context) - querys.update(name=data['name'], - type=data['type'], - subject=data['subject'], - remark=data.get('remark') if data.get('remark') else '', - owner=user, - member_can_know_donelist=True if data[ - 'member_can_know_donelist'] == 'true' else False, - member_can_see_others=True if data[ - 'member_can_see_others'] == 'true' else False, - ) + query.name = data['name'] + query.type = data['type'] + query.subject = data['subject'] + query.remark = data.get('remark') if data.get('remark') else '' + query.member_can_know_donelist=True if data['member_can_know_donelist'] == 'true' else False + query.member_can_see_others=True if data['member_can_see_others'] == 'true' else False query.end_time = datetime(year=int(end_time[0:4]), month=int(end_time[5:7]), day=int(end_time[8:10]), -- Gitee From 119c2db427157a6329f1fccf60ecd323c682f08d Mon Sep 17 00:00:00 2001 From: li155370945 <1553770945@qq.com> Date: Thu, 3 Dec 2020 11:50:14 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=B7=B2=E8=B6=85=E8=BF=87=E6=88=AA=E6=AD=A2?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HomeWork/settings.py | 24 ++++++++++++------------ work/admin.py | 15 +++++++++++---- work/models.py | 9 +++++---- work/serializers.py | 2 +- work/views.py | 11 +++++++++-- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/HomeWork/settings.py b/HomeWork/settings.py index bf65f7b..3fd5600 100644 --- a/HomeWork/settings.py +++ b/HomeWork/settings.py @@ -76,22 +76,22 @@ WSGI_APPLICATION = 'HomeWork.wsgi.application' # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.sqlite3', -# 'NAME': BASE_DIR / 'db.sqlite3', -# } -# } DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'homework', - 'USER':conf.get("mysql","username"), - 'PASSWORD':conf.get("mysql","password"), - 'HOST':conf.get("mysql","host"), - 'PORT':'3306', + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', } } +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.mysql', +# 'NAME': 'homework', +# 'USER':conf.get("mysql","username"), +# 'PASSWORD':conf.get("mysql","password"), +# 'HOST':conf.get("mysql","host"), +# 'PORT':'3306', +# } +# } # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators diff --git a/work/admin.py b/work/admin.py index 32fb724..f71cd26 100644 --- a/work/admin.py +++ b/work/admin.py @@ -5,16 +5,23 @@ from .models import HomeWorkInfModel, HomeWorkMembersModel # Register your models here. class HomeWorkAdmin(admin.ModelAdmin): - list_display = ['name', 'owner'] - list_display_links = ['name', 'owner'] + list_display = ['name', 'owner_name'] + def owner_name(self,obj): + return obj.owner.first_name + owner_name.short_description = "创建人" + list_display_links = ['name', 'owner_name'] search_fields = ['name'] readonly_fields = ['create_time'] list_filter = ['owner', 'subject'] class HomeWorkMembersAdmin(admin.ModelAdmin): - list_display = ['work','owner','done'] - list_display_links =['work','owner'] + def owner_name(self,obj): + return obj.owner.first_name + owner_name.short_description = "完成人" + list_display = ['work','owner_name','done'] + list_display_links =['work','owner_name'] + search_fields = ['work__name'] admin.site.register(HomeWorkInfModel, HomeWorkAdmin) diff --git a/work/models.py b/work/models.py index 96c0d0a..e97d70d 100644 --- a/work/models.py +++ b/work/models.py @@ -21,9 +21,9 @@ class HomeWorkInfModel(models.Model): type = models.CharField(max_length=100, choices=(('file', "文件"), ('hypertext', "超文本")), default="hypertext", verbose_name="作业类型") create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间") # 创建的时间 - subject = models.CharField(max_length=30, verbose_name="科目") + subject = models.CharField(max_length=30, verbose_name="科目",db_index=True) remark = models.CharField(max_length=500, verbose_name="备注", null=True, blank=True) - owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name="ReleaseHomeWork", verbose_name="创建人") + owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name="ReleaseHomeWork", verbose_name="创建人",db_index=True) end_time = models.DateTimeField(verbose_name="截止时间", default=datetime.datetime.now()) member_can_know_donelist = models.BooleanField(verbose_name="成员可查看完成情况", choices=((False, "否"), (True, "是")), default=False) @@ -33,6 +33,7 @@ class HomeWorkInfModel(models.Model): members = models.ManyToManyField(to=User, related_name='work', verbose_name='参与人员', through='HomeWorkMembersModel') + can_submit_after_end = models.BooleanField(default=True,verbose_name="截止时间已过仍然可以提交") class HomeWorkMembersModel(models.Model): class Meta: @@ -43,8 +44,8 @@ class HomeWorkMembersModel(models.Model): def __str__(self): return "{}-{}".format(self.work, self.owner) - work = models.ForeignKey(to=HomeWorkInfModel, verbose_name="作业", on_delete=models.CASCADE, related_name='done') - owner = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name="Done", verbose_name="参与人") + work = models.ForeignKey(to=HomeWorkInfModel, verbose_name="作业", on_delete=models.CASCADE, related_name='done',db_index=True) + owner = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name="Done", verbose_name="参与人",db_index=True) done = models.BooleanField(verbose_name="已完成", db_index=True, default=False) end_time = models.DateTimeField(verbose_name="截止时间") # 创建的时间 diff --git a/work/serializers.py b/work/serializers.py index aad0d90..dd03ac4 100644 --- a/work/serializers.py +++ b/work/serializers.py @@ -10,7 +10,7 @@ class HomeWorkUpSerializer(serializers.Serializer): # 用于登录的表单合 end_time = serializers.CharField() member_can_know_donelist = serializers.CharField() member_can_see_others = serializers.CharField() - + can_submit_after_end = serializers.CharField() def validate_name(self, name): if len(name) > 50: raise serializers.ValidationError("名称长度过长") diff --git a/work/views.py b/work/views.py index e8ed891..5dc4d23 100644 --- a/work/views.py +++ b/work/views.py @@ -9,7 +9,7 @@ from rest_framework.authentication import SessionAuthentication, BasicAuthentica from django.http import QueryDict, FileResponse import os from group.models import GroupModel, GroupMembersModel - +import pytz class CsrfExemptSessionAuthentication(SessionAuthentication): @@ -80,6 +80,8 @@ class HomeWorkView(APIView): 'member_can_know_donelist'] == 'true' else False, member_can_see_others=True if data[ 'member_can_see_others'] == 'true' else False, + can_submit_after_end=True if data[ + 'can_submit_after_end'] == 'true' else False, end_time=datetime(year=int(end_time[0:4]), month=int(end_time[5:7]), day=int(end_time[8:10]), @@ -181,6 +183,7 @@ class HomeWorkView(APIView): query.remark = data.get('remark') if data.get('remark') else '' query.member_can_know_donelist=True if data['member_can_know_donelist'] == 'true' else False query.member_can_see_others=True if data['member_can_see_others'] == 'true' else False + query.can_submit_after_end=True if data['can_submit_after_end'] == 'true' else False query.end_time = datetime(year=int(end_time[0:4]), month=int(end_time[5:7]), day=int(end_time[8:10]), @@ -291,7 +294,7 @@ class MyHomeWorkView(APIView): return Response(context) return Response(context) - +# TODO 提交作业不能撤回 class SubmitView(APIView): authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication) @@ -323,6 +326,10 @@ class SubmitView(APIView): context['err_code'] = 4004 context['error'] = "您没有次参加本作业" return Response(context) + if not work.can_submit_after_end and datetime.utcnow().replace(tzinfo=pytz.UTC) > work.end_time: + context['err_code'] = 6001 + context['error'] = "很抱歉,该作业提交截止时间已过" + return Response(context) done = done.first() file = request.FILES.get("file") # 获取上传的文件,如果没有文件,则默认为None if not file: -- Gitee From 8c63805583a525da8da93f222d72b48099fc6ed9 Mon Sep 17 00:00:00 2001 From: li1553770945 <1553770945@qq.com> Date: Mon, 7 Dec 2020 22:28:38 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HomeWork/settings.py | 12 ++++++++++-- HomeWork/urls.py | 6 ++++-- main.ini | 5 ++++- r.txt | 9 --------- 4 files changed, 18 insertions(+), 14 deletions(-) delete mode 100644 r.txt diff --git a/HomeWork/settings.py b/HomeWork/settings.py index 3fd5600..4c5ed45 100644 --- a/HomeWork/settings.py +++ b/HomeWork/settings.py @@ -26,7 +26,12 @@ SECRET_KEY = conf.get("django","secret_key") DEBUG = bool(conf.get("django","debug")) ALLOWED_HOSTS = ['*'] - +INTERNAL_IPS = ['*'] +DEBUG_TOOLBAR_CONFIG = { + 'JQUERY_URL': 'https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js', + 'SHOW_COLLAPSED': True, + 'SHOW_TOOLBAR_CALLBACK': lambda x: True, +} # Application definition INSTALLED_APPS = [ @@ -40,8 +45,9 @@ INSTALLED_APPS = [ 'rest_framework', 'work', 'group', + 'debug_toolbar', ] - +DEBUG_TOOLBAR_PATCH_SETTINGS = False MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -50,6 +56,8 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'debug_toolbar.middleware.DebugToolbarMiddleware', + ] ROOT_URLCONF = 'HomeWork.urls' diff --git a/HomeWork/urls.py b/HomeWork/urls.py index 86fda79..ac4f96e 100644 --- a/HomeWork/urls.py +++ b/HomeWork/urls.py @@ -14,10 +14,11 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path,include from login.views import LoginView,LogOutView,MeView,RegisterView from work.views import HomeWorkView,MyHomeWorkNumView,MyHomeWorkView,SubmitView,DownloadView,ExportView,DoneListView from group.views import GroupView,MyGroupNumView,MyGroupView,GroupMembersView +import debug_toolbar urlpatterns = [ path('api/admin/', admin.site.urls), path('api/login/',LoginView.as_view()), @@ -35,5 +36,6 @@ urlpatterns = [ path('api/download/',DownloadView.as_view()), path('api/export/',ExportView.as_view()), path('api/donelist/',DoneListView.as_view()), - + path('__debug__/',include(debug_toolbar.urls)) ] + diff --git a/main.ini b/main.ini index db3f959..7054062 100644 --- a/main.ini +++ b/main.ini @@ -1,4 +1,7 @@ [mysql] username=username password=password -host=localhost \ No newline at end of file +host=localhost +[django] +secret_key=x7(a(2*+u=vu(86j^+j=^3xo94m3*bf^-p1_dvhv=768@5=g@@ +debug=1 \ No newline at end of file diff --git a/r.txt b/r.txt deleted file mode 100644 index db08e53..0000000 --- a/r.txt +++ /dev/null @@ -1,9 +0,0 @@ -asgiref==3.2.10 -Django==3.1.2 -djangorestframework==3.12.1 -mysqlclient==2.0.1 -pypandoc==1.5 -PySnooper==0.4.2 -pytz==2020.1 -six==1.15.0 -sqlparse==0.4.1 -- Gitee From 8c01784a60183b5ded332758fccccc193fb7a65c Mon Sep 17 00:00:00 2001 From: li1553770945 <1553770945@qq.com> Date: Tue, 15 Dec 2020 23:39:47 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E9=AA=8C=E8=AF=81=EF=BC=8C=E5=85=B3=E9=97=AD?= =?UTF-8?q?debugtoolbar,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HomeWork/settings.py | 6 +++--- HomeWork/urls.py | 2 +- group/serializers.py | 6 ++---- requirements.txt | 8 ++++++++ work/views.py | 1 + 5 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 requirements.txt diff --git a/HomeWork/settings.py b/HomeWork/settings.py index 4c5ed45..587af93 100644 --- a/HomeWork/settings.py +++ b/HomeWork/settings.py @@ -45,11 +45,11 @@ INSTALLED_APPS = [ 'rest_framework', 'work', 'group', - 'debug_toolbar', + # 'debug_toolbar', ] DEBUG_TOOLBAR_PATCH_SETTINGS = False MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', + # 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', # 'django.middleware.csrf.CsrfViewMiddleware', @@ -61,7 +61,7 @@ MIDDLEWARE = [ ] ROOT_URLCONF = 'HomeWork.urls' - +STATIC_ROOT = 'static_all' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', diff --git a/HomeWork/urls.py b/HomeWork/urls.py index ac4f96e..f99b25c 100644 --- a/HomeWork/urls.py +++ b/HomeWork/urls.py @@ -36,6 +36,6 @@ urlpatterns = [ path('api/download/',DownloadView.as_view()), path('api/export/',ExportView.as_view()), path('api/donelist/',DoneListView.as_view()), - path('__debug__/',include(debug_toolbar.urls)) + #path('__debug__/',include(debug_toolbar.urls)) ] diff --git a/group/serializers.py b/group/serializers.py index 0ae3581..4c4ffc0 100644 --- a/group/serializers.py +++ b/group/serializers.py @@ -27,10 +27,10 @@ class GroupUnSerializer(serializers.Serializer): raise serializers.ValidationError("组名格式不正确") def validate_desc(self, desc): - if valid_group_information('desc', desc): + if len(desc) <= 500: return desc else: - raise serializers.ValidationError("描述格式不正确") + raise serializers.ValidationError("描述过长") def validate_password(self, password): if valid_group_information('password', password): @@ -42,8 +42,6 @@ class GroupUnSerializer(serializers.Serializer): def valid_group_information(name, data): if name == 'name': return re.match("^[a-zA-Z0-9\u4e00-\u9fa5_丶]{1,20}$", data) is not None - if name == 'desc': - return re.match("^[a-zA-Z0-9\u4e00-\u9fa5_丶]{0,200}$", data) is not None if name == 'password': return re.match("^[0-9a-zA-Z]{6,18}$", data) is not None diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e6d0a65 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +asgiref==3.3.1 +Django==3.1.4 +django-debug-toolbar==3.2 +django-rest-framework==0.1.0 +djangorestframework==3.12.2 +mysqlclient==2.0.1 +pytz==2020.4 +sqlparse==0.4.1 diff --git a/work/views.py b/work/views.py index 5dc4d23..c3a58f6 100644 --- a/work/views.py +++ b/work/views.py @@ -10,6 +10,7 @@ from django.http import QueryDict, FileResponse import os from group.models import GroupModel, GroupMembersModel import pytz +from django.db.models import Q class CsrfExemptSessionAuthentication(SessionAuthentication): -- Gitee From f00cac5924e851bf501771eab420d290ec829f06 Mon Sep 17 00:00:00 2001 From: li1553770945 <1553770945@qq.com> Date: Tue, 19 Jan 2021 00:01:56 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=BC=80=E6=94=BE=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- HomeWork/settings.py | 4 ++-- login/views.py | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 723ab0e..bcd9f18 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ venv *.pyc file *.docx -main.ini \ No newline at end of file +main.ini +static_all \ No newline at end of file diff --git a/HomeWork/settings.py b/HomeWork/settings.py index 587af93..ac7fc08 100644 --- a/HomeWork/settings.py +++ b/HomeWork/settings.py @@ -33,7 +33,7 @@ DEBUG_TOOLBAR_CONFIG = { 'SHOW_TOOLBAR_CALLBACK': lambda x: True, } # Application definition - +CAN_REGISTER = False INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', @@ -56,7 +56,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'debug_toolbar.middleware.DebugToolbarMiddleware', + #'debug_toolbar.middleware.DebugToolbarMiddleware', ] diff --git a/login/views.py b/login/views.py index 9a187f8..1fc3845 100644 --- a/login/views.py +++ b/login/views.py @@ -70,6 +70,11 @@ class RegisterView(APIView): # 注册相关视图类 authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication) def post(self, request): context = dict() + from django.conf import settings + if not settings.CAN_REGISTER: + context['err_code'] = 4004 + context['error'] = "暂不开放注册" + return Response(context) context['err_code']=0 data = RegisterSerializer(data=request.POST) if not data.is_valid(): # 验证数据的有效性,如果无效证明绕过了前端 -- Gitee