diff --git a/server/apps/exam/views.py b/server/apps/exam/views.py index a37e6b4..79f6ecc 100644 --- a/server/apps/exam/views.py +++ b/server/apps/exam/views.py @@ -270,6 +270,35 @@ class PaperViewSet(ModelViewSet): PaperQuestion.objects.filter(paper=paper).delete() PaperQuestion.objects.bulk_create(q_list) return Response() + + + @action(methods=['put'], detail=True, url_path='clone', url_name='clone_paper', + perms_map=[{'put':'clone_paper'}]) + def clone(self, request, pk=None): + ''' + 克隆试卷 + ''' + paper = self.get_object() + obj = Paper() + obj.name = '克隆卷-'+paper.name + obj.workscope = paper.workscope + obj.limit = paper.limit + obj.total_score = paper.total_score + obj.pass_score = paper.pass_score + obj.danxuan_count = paper.danxuan_count + obj.danxuan_score = paper.danxuan_score + obj.duoxuan_count = paper.duoxuan_count + obj.duoxuan_score = paper.duoxuan_score + obj.panduan_count = paper.panduan_count + obj.panduan_score = paper.panduan_score + obj.save() + for i in PaperQuestion.objects.filter(paper=paper): + o = PaperQuestion() + o.paper = obj + o.question = i.question + o.total_score = i.total_score + o.save() + return Response(status=200) @action(methods=['post'], detail=False, perms_map={'post': 'question'}, serializer_class=Serializer) def upload_paper(self, request): @@ -277,7 +306,6 @@ class PaperViewSet(ModelViewSet): question_type = request.data.get('question_type') excel_path = settings.BASE_DIR + "/media/default/question.xlsx" doc_path = settings.BASE_DIR + doc_path - # excel_path = "C:\code\data\question.xlsx" timenow = timezone.now().strftime('%Y%m%d%H%M%S') question_excel_name = "question_excel_"+timenow question_excel = os.path.join(os.path.dirname(excel_path), question_excel_name) diff --git a/server/server/settings_dev.py b/server/server/settings_dev.py index 3065e84..2d5ce36 100644 --- a/server/server/settings_dev.py +++ b/server/server/settings_dev.py @@ -1,14 +1,14 @@ from .settings import * DEBUG = True DATABASES = { - # 'default': { - # 'ENGINE': 'django.db.backends.postgresql', - # 'NAME': 'cma', - # 'USER': 'postgres', - # 'PASSWORD': 'zcDsj2021', - # 'HOST': '49.232.14.174', - # 'PORT': '5432', - # }, + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'cma', + 'USER': 'postgres', + 'PASSWORD': 'zcDsj2021', + 'HOST': '49.232.14.174', + 'PORT': '5432', + }, # 'default': { # 'ENGINE': 'django.db.backends.postgresql', # 'NAME': 'cma', @@ -18,16 +18,14 @@ DATABASES = { # # 'HOST': '1.203.161.102', # 'PORT': '5432', # } - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'cma', - 'USER': 'cma', - 'PASSWORD': 'cma123', - 'HOST': '172.16.80.102', - # 'HOST': '127.0.0.1', - # 'HOST':'1.203.161.101', - 'PORT': '5432', - } - - + # 'default': { + # 'ENGINE': 'django.db.backends.postgresql', + # 'NAME': 'cma', + # 'USER': 'cma', + # 'PASSWORD': 'cma123', + # 'HOST': '172.16.80.102', + # # 'HOST': '127.0.0.1', + # # 'HOST':'1.203.161.101', + # 'PORT': '5432', + # } }