def destroy(self, request, *args, **kwargs): try: data = request.data traderid = data.get('trader', None) investorid = data.get('investor', None) projid = data.get('proj', None) if not data or not traderid or not investorid: raise InvestError(code=20071) dataroomquery = self.get_queryset().filter(isPublic=False, proj_id=projid, investor_id=investorid, trader_id=traderid) if not dataroomquery.exists(): raise InvestError(code=6002) if request.user.has_perm('dataroom.admin_deletedataroom'): pass elif request.user.has_perm('dataroom.user_deletedataroom',dataroomquery.get(investor_id=investorid)): pass else: raise InvestError(code=2009) with transaction.atomic(): for instance in dataroomquery: instance.dataroom_directories.all().update(is_deleted=True,deletedtime=datetime.datetime.now()) for fileOrDirectory in instance.dataroom_directories.all(): if fileOrDirectory.isFile and fileOrDirectory.key: deleteqiniufile(fileOrDirectory.bucket, fileOrDirectory.key) instance.is_deleted = True instance.deleteduser = request.user instance.deletedtime = datetime.datetime.now() instance.save() return JSONResponse(SuccessResponse(returnListChangeToLanguage(DataroomSerializer(dataroomquery,many=True).data))) except InvestError as err: return JSONResponse(InvestErrorResponse(err)) except Exception: catchexcption(request) return JSONResponse(ExceptionResponse(traceback.format_exc().split('\n')[-2]))
def deleteAttachment(self, request, *args, **kwargs): try: lang = request.GET.get('lang') instance = self.get_object() if request.user.has_perm('BD.manageMeetBD'): pass elif request.user.has_perm('BD.user_manageMeetBD', instance): pass elif request.user in [ instance.proj.takeUser, instance.proj.makeUser ]: pass else: raise InvestError(2009) with transaction.atomic(): bucket = instance.attachmentbucket key = instance.attachment deleteqiniufile(bucket, key) instance.attachmentbucket = None instance.attachment = None instance.save() return JSONResponse( SuccessResponse( returnDictChangeToLanguage( MeetingBDSerializer(instance).data, lang))) except InvestError as err: return JSONResponse(InvestErrorResponse(err)) except Exception: catchexcption(request) return JSONResponse( ExceptionResponse(traceback.format_exc().split('\n')[-2]))
def deleteUpload(request): try: data = request.data record = data.get('record') recordDic = read_from_cache(record) if recordDic is None: raise InvestError(8003, msg='没有这条记录') if recordDic['key'] and recordDic['bucket']: deleteqiniufile(key=recordDic['key'], bucket=recordDic['bucket']) cache_delete_key(record) return JSONResponse(SuccessResponse({record: read_from_cache(record)})) except InvestError as err: return JSONResponse(InvestErrorResponse(err)) except Exception: return JSONResponse( ExceptionResponse(traceback.format_exc().split('\n')[-2]))
def deleteInstance(self,instance,deleteuser): if instance.isFile: instance.is_deleted = True instance.deleteduser = deleteuser instance.deletedtime = datetime.datetime.now() instance.save() if instance.isShadow: pass else: if not instance.bucket or not instance.key: pass else: deleteqiniufile(instance.bucket, instance.key) else: instance.is_deleted = True instance.deleteduser = deleteuser instance.deletedtime = datetime.datetime.now() instance.save()
def destroy(self, request, *args, **kwargs): try: with transaction.atomic(): instance = self.get_object() bucket = instance.attachmentbucket key = instance.attachment deleteqiniufile(bucket, key) instance.is_deleted = True instance.deleteduser = request.user instance.deletedtime = datetime.datetime.now() instance.save() return JSONResponse(SuccessResponse({ 'isDeleted': True, })) except InvestError as err: return JSONResponse(InvestErrorResponse(err)) except Exception: catchexcption(request) return JSONResponse( ExceptionResponse(traceback.format_exc().split('\n')[-2]))