def addDomainMappingForm(Id,mapping,root): """ 将申请单 域名映射部分存入数据库 Id: 该域名映射对应的申请单ID mapping:域名映射数据 root:域名映射对应的父域名 """ main = get_object_or_404(DomainApplication,id=Id) main.status = staticVar.WAITINGFORVERIFY main.save() #创建一条标记表单状态流转的记录 status = FormStatus(status=staticVar.WAITINGFORVERIFY) status.status_user = main.creater status.status_da = main status.createTime = datetime.datetime.now() status.save() domainName = mapping.values()[0] try: #如果域名存在 则查出来 没有就创建一条新的 这里创建的是 Type=1的域名 domain1 = DomainForm.objects.get(domainName=domainName,domainType=1) except DomainForm.DoesNotExist: domain1 = DomainForm(domainName=domainName,domainType=1) domain1.domain_zone = Zone.objects.get(zoneName=root) domain1.status = staticVar.CANNOT_APPLY domain1.save() domain = DomainForm(domainName=domainName,domainType=0) domain.domain_zone = Zone.objects.get(zoneName=root) domain.status = staticVar.CANNOT_APPLY domain.save() domain.da_domain.add(main) domain.save() mappingData = mapping.values()[1] #将ip mode sp 这样的映射关系存入数据库 for m in mappingData: domainMapping = DomainMapping(mode=m.get("mode"),aim= m.get("aim")) domainMapping.dm_domain = domain domainMapping.dm_sp = ServiceProvider.objects.get(spName=m.get("spName")) domainMapping.save()
def changeForm(request,Id,operation): """ 改变表单的状态 Id:表单的Id Operation:对该表单进行的操作 如 审核 检查 如何要修改operation的名字 除了修改这里之外 还要修改 show_form.html 里面对应的名字 返回一个Url用来指引action部分的跳转 """ def __createStatusRecord(): """ 创建表单状态流转记录 由于每一次改变表单状态都需要创建这么一条记录 所以 写成函数会方便很多 """ user = userService.getUser(request) status = FormStatus(status=form.status) status.status_user = user status.status_da = form status.createTime = datetime.datetime.now() if(request.POST and request.POST.get("comment")): status.statusDes = request.POST.get("comment") status.save() root = "/handleForm/" form = get_object_or_404(DomainApplication,id=Id) if(operation=="verify"): form.status = staticVar.VERIFIED url = root + "show_unverified_form" elif(operation=="reject"): if(form.status==staticVar.WAITINGFORVERIFY): form.status = staticVar.REJECTED url = root + "show_unverified_form" elif(form.status==staticVar.VERIFIED): form.status = staticVar.REJECTED url = root + "show_unimplemented_form" elif(form.status==staticVar.OPERATED): form.status = staticVar.VERIFIED url = root + "show_unchecked_form" elif(operation=="close"): form.status = staticVar.CLOSED #改变表单对应的DOMAIN的状态 在表单完被关闭后 该表弟那对应的域名 都应该设置为 可以被申请 for domain in DomainForm.objects.filter(da_domain=form): domain.status = staticVar.CAN_APPLY domain1 = DomainForm.objects.get(domainName=domain.domainName,domainType=1) domain1.status = staticVar.CAN_APPLY domain1.save() domain.save() url = root + "show_applied_form" elif(operation=="edit"): if(form.status==staticVar.REJECTED): url = root +"edit_form/"+str(Id) else: url = "/index" return url elif(operation=="operate"): form.status = staticVar.OPERATED url=root + "show_unimplemented_form" elif(operation=="check"): form.status = staticVar.CHECKED url = root + "show_unchecked_form" elif(operation=="confirm"): if(form.status==staticVar.CHECKED): form.status = staticVar.COMPLETED #改变表单对应的DOMAIN的状态 在表单完成流程后 该表弟那对应的域名 都应该设置为 可以被申请 for domain in DomainForm.objects.filter(da_domain=form): domain.status = staticVar.CAN_APPLY domain.save() domain1 = DomainForm.objects.get(domainName=domain.domainName,domainType=1) domain1.status = staticVar.CAN_APPLY domain1.save() #如果该域名有绑定的映射 就删除掉映射 然后 再绑定新的 如果没有 就直接创建新的域名绑定 #这个部分是服务于 发现数据库设计bug后的修复 if(DomainMapping.objects.filter(dm_domain=domain1)): for m in DomainMapping.objects.filter(dm_domain=domain1): m.delete() for m in DomainMapping.objects.filter(dm_domain=domain): domainMapping = DomainMapping(mode=m.mode,aim= m.aim) domainMapping.dm_domain = domain1 domainMapping.dm_sp = m.dm_sp domainMapping.save() url = root + "show_applied_form" else: url = "/index" else: return "/index" __createStatusRecord() form.save() return url