|
@@ -9,6 +9,7 @@ from utils.permission import IsAdministratorUser
|
|
|
from .serializer import OperationHelpSerializer
|
|
|
from apps.tenant import tenant_log
|
|
|
from apps.log.models import BizLog
|
|
|
+from utils.exceptions import CustomError
|
|
|
from .filters import OperationHelpFilter
|
|
|
from utils import response_ok, response_error
|
|
|
from django.db import transaction
|
|
@@ -42,9 +43,9 @@ class OperationHelpViewSet(CustomModelViewSet):
|
|
|
file = self.request.FILES.get('file')
|
|
|
user = self.request.user
|
|
|
operation_help_img = OperationHelpImg.objects.create(tenant=user.employee.tenant)
|
|
|
- if file:
|
|
|
- operation_help_img._add_img(file, user)
|
|
|
- image = operation_help_img.image
|
|
|
+ operation_help_img._add_img(file, user)
|
|
|
+ image = operation_help_img.image
|
|
|
+ if image:
|
|
|
data={
|
|
|
"src": image
|
|
|
}
|
|
@@ -56,11 +57,20 @@ class OperationHelpViewSet(CustomModelViewSet):
|
|
|
file = self.request.FILES.get('file')
|
|
|
user = self.request.user
|
|
|
operation_help_radio = OperationHelpRadio.objects.create(tenant=user.employee.tenant)
|
|
|
- if file:
|
|
|
- operation_help_radio._add_radio(file, user)
|
|
|
- radio_path = operation_help_radio.radio_path
|
|
|
+ operation_help_radio._add_radio(file, user)
|
|
|
+ radio_path = operation_help_radio.radio_path
|
|
|
+ if radio_path:
|
|
|
data = {
|
|
|
"src": radio_path
|
|
|
}
|
|
|
return response_ok(data)
|
|
|
- return response_error('上传失败,请重新上传!')
|
|
|
+ return response_error('上传失败,请重新上传!')
|
|
|
+
|
|
|
+ def destroy(self, request, *args, **kwargs):
|
|
|
+ with transaction.atomic():
|
|
|
+ instance = self.get_object()
|
|
|
+ if instance.tenant != request.user.employee.tenant:
|
|
|
+ raise CustomError(u'禁止跨企业操作!')
|
|
|
+ super(OperationHelpViewSet, self).destroy(self, request, *args, **kwargs)
|
|
|
+ tenant_log(self.request.user.employee, BizLog.DELETE, u'删除运维帮助[%s],id=%d' % (instance.title, instance.id))
|
|
|
+ return response_ok()
|