def to_internal_value(self, data): full_logo_name = data.get('cover', None) category = data.get('category', None) platforms = data.get('platforms', None) language = data.get('language', None) online = data.get('online', None) data._mutable = True if category: data['category'] = ",".join(data.getlist('category')) if language: data['language'] = ",".join(data.getlist('language')) if platforms: data['platforms'] = ",".join(data.getlist('platforms')) # if online: # data['platforms'] = "online" # else: # data['online'] = False if full_logo_name: logofile = save_image(full_logo_name) data['cover'] = logofile # else: # del data['cover'] # if not data.get("save_path"): # del data["save_path"] if not data.get("public"): data['public'] = False data._mutable = False return super(ToolSerializer, self).to_internal_value(data)
def to_internal_value(self, data): full_logo_name = data.get('logo', None) data._mutable = True if full_logo_name: data['logo'] = save_image(full_logo_name) data._mutable = False ret = super(CourseSerializer, self).to_internal_value(data) return ret
def to_internal_value(self, data): full_logo_name = data.get('logo', None) data._mutable = True if full_logo_name: logofile = save_image(full_logo_name) data['logo'] = logofile data._mutable = False ret = super(SystemConfigurationSerializer, self).to_internal_value(data) return ret
def to_internal_value(self, data): full_logo_name = data.get('logo', None) password = data.get('password', None) data._mutable = True if full_logo_name: logofile = save_image(full_logo_name) data['logo'] = logofile data._mutable = False ret = super(UserSerializer, self).to_internal_value(data) if password: pattern_password = re.compile(unicode(REGEX.REGEX_PASSWORD)) if not pattern_password.match(password): from x_person.web.response import ResError raise exceptions.NotAcceptable(ResError.NEW_PASSWORD_WRONG) password = make_password(password) ret['password'] = password return ret
def custom_tool_detail(request, tool_id): if request.method == 'PUT': params = QueryDict(request.body) if "cover" in params: tool = Tool.objects.get(id=tool_id) if tool.cover: tool.cover.delete() tool.save() if "save_path" in params: tool = Tool.objects.get(id=tool_id) if tool.save_path: tool.save_path.delete() tool.save() return HttpResponse(None, status=200) elif request.method == 'POST': try: tool = Tool.objects.get(id=tool_id) name = request.POST.get("name") if name is not None: tool.name = name category = request.POST.get('category') if category is not None: tool.category = ",".join(request.POST.getlist('category')) cover = request.POST.get("cover") if cover is not None: tool.cover = save_image(cover) save_path = request.FILES.get("save_path") if save_path is not None: tool.save_path = save_path homepage = request.POST.get("homepage") if homepage is not None: tool.homepage = homepage size = request.POST.get("size") if size is not None: tool.size = size version = request.POST.get("version") if version is not None: tool.version = version language = request.POST.get('language') if language is not None: tool.language = ",".join(request.POST.getlist('language')) license_model = request.POST.get("license_model") if license_model is not None: tool.license_model = license_model introduction = request.POST.get("introduction") if introduction is not None: tool.introduction = introduction tool.public = True if request.POST.get("public") else False tool.online = True if request.POST.get("online") else False if tool.online: tool.platforms = "online" else: platforms = request.POST.get('platforms') if platforms is not None: tool.platforms = ",".join( request.POST.getlist('platforms')) tool.save() except Exception, e: pass return HttpResponse(None, status=200)
def handler_task_list(request, testpaper_id): examname = request.data.get('examname', '') examDescription = request.data.get('examDescription', '') datas = request.data.get('data', '') testpaper_id = int(testpaper_id) if request.method == "GET": rows = [] if testpaper_id != 0: taskArrary = TestPaperTask.objects.filter( test_paper__id=testpaper_id) for t in taskArrary: task = get_task_object(t.task_hash) if not task: continue data = SerializerNew(task, t).data rows.append(data) return Response(data=rows, status=status.HTTP_200_OK) if not datas or not json.loads(datas): raise exceptions.ParseError(PracticeResError.NO_EXAM_QUESTIONS) if not examname: raise exceptions.ParseError(PracticeResError.WARN_MESSAGES_7) if capability_models.TestPaper.objects.filter( status=capability_models.TestPaper.Status.NORMAL, name=examname).exclude(pk=testpaper_id).exists(): raise exceptions.ParseError(PracticeResError.WARN_MESSAGES_6) datas = json.loads(datas) number = 0 allScore = 0 for data in datas: number = number + 1 allScore = allScore + float(data['score']) logo_url = request.data.get("logo", None) if testpaper_id == 0: # 新增 # 创建一张试卷 if logo_url is not None and logo_url != '': logo = save_image(logo_url) else: logo = None testPaper = capability_models.TestPaper.objects.create( name=examname, task_number=number, task_all_score=allScore, introduction=examDescription, create_time=timezone.now(), create_user=request.user, logo=logo, public=True, ) else: testPaper = capability_models.TestPaper.objects.filter(id=testpaper_id) if not testPaper: raise exceptions.NotFound(PracticeResError.NOT_FOUND_EXAM) testPaper = testPaper[0] testPaper.name = examname testPaper.task_number = number testPaper.task_all_score = allScore testPaper.introduction = examDescription if logo_url is not None and logo_url != '': logos = save_image(logo_url) testPaper.logo = logos testPaper.save() event_task_list = TestPaperTask.objects.filter(test_paper=testPaper) if event_task_list: # 判断原来是否存在初始数据, 批量删除 try: event_task_list.delete() except ProtectedError: raise exceptions.ParseError( PracticeResError.CANNT_CHANGE_HAS_DONE) event_task_list = [] for data in datas: # copy_hash = copy_task(data['hash']) # if not copy_hash: # continue hash_list = [] if int(data['hash'].split('.')[-1]) != 0: hash_list.append(data['hash']) task_handler_class = TaskHandler copy_hash = task_handler_class.handle_tasks(hash_list) copy_hash = copy_hash[0] else: copy_hash = copy_task(data['hash']) if not copy_hash: continue event_task = TestPaperTask(test_paper=testPaper, task_hash=copy_hash, score=data['score']) event_task_list.append(event_task) TestPaperTask.objects.bulk_create(event_task_list) cache = CacheProduct( "%s-%s" % (TestPaperViewSet.__module__, TestPaperViewSet.__name__)) delete_cache(cache) return Response(data={'type': 'success'}, status=status.HTTP_200_OK)