views.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # coding=utf-8
  2. from rest_framework.decorators import action
  3. from rest_framework import permissions
  4. from rest_framework.views import APIView
  5. from django.db.models import Q
  6. from utils.custom_modelviewset import CustomModelViewSet
  7. from utils.permission import IsAdministratorUser,IsTenantUser
  8. from utils.exceptions import CustomError
  9. from utils import response_ok, response_error
  10. from apps.option.models import Option
  11. from apps.option.serializers import OptionComboboxSerializer
  12. from .models import ReportCustomer
  13. from .serializers import ReportCustomerSerializer
  14. from .filters import ReportCustomerFilter
  15. class ReportCustomerViewSet(CustomModelViewSet):
  16. permission_classes = []
  17. queryset = ReportCustomer.objects.filter()
  18. serializer_class = ReportCustomerSerializer
  19. def filter_queryset(self, queryset):
  20. f = ReportCustomerFilter(self.request.GET, queryset=queryset)
  21. return f.qs
  22. def perform_create(self, serializer):
  23. super(ReportCustomerViewSet, self).perform_create(serializer)
  24. instance = serializer.instance
  25. validated_data = serializer.validated_data
  26. def perform_update(self, serializer):
  27. super(ReportCustomerViewSet, self).perform_update(serializer)
  28. instance = serializer.instance
  29. validated_data = serializer.validated_data
  30. def destroy(self, request, *args, **kwargs):
  31. instance = self.get_object()
  32. # if instance.tenant != request.user.employee.tenant:
  33. # raise CustomError(u'禁止跨企业操作!')
  34. super(ReportCustomerViewSet, self).destroy(self, request, *args, **kwargs)
  35. return response_ok()
  36. # @action(methods=['post'], detail=False)
  37. # def check(self, request, pk):
  38. # # 审核
  39. # report_status = request.POST.get('report_status')
  40. # try:
  41. # instance = Customer.objects.filter(id=pk).first()
  42. # if not instance:
  43. # raise CustomError('当前客户报备信息有误!')
  44. #
  45. # instance.check_user = self.request.user
  46. # instance.report_status = report_status
  47. # instance.check_time = timezone.now()
  48. # instance.save()
  49. #
  50. # except CustomError as e:
  51. # return response_error(e.get_error_msg())
  52. # except Exception as e:
  53. # return response_error(str(e))
  54. # return response_ok('审核完成!')
  55. class ReportCustomerDictView(APIView):
  56. permission_classes = []
  57. def get(self, request):
  58. scouce = Option.objects.filter(type=Option.CUSTOMER_SOURCE , enable=True)
  59. project = Option.objects.filter(type=Option.CATEGORY, enable=True)
  60. serializer_scouce = OptionComboboxSerializer(scouce, many=True)
  61. serializer_project = OptionComboboxSerializer(project, many=True)
  62. return response_ok({
  63. 'source': serializer_scouce.data,
  64. 'project': serializer_project.data,
  65. })