返回完整资源地址,部分创建接口返回id
This commit is contained in:
parent
ed68baca62
commit
b77ecb46e7
|
@ -2,6 +2,7 @@ from apps.am.serializers import AreaSerializer, AreaSimpleSerializer
|
|||
from apps.ecm.models import AlgoChannel, EventCate, Remind, NotifySetting, Event
|
||||
from apps.third.serializers import TDeviceSimpleSerializer
|
||||
from apps.third.models import TDevice
|
||||
from apps.utils.fields import MyFilePathField
|
||||
from apps.utils.serializers import CustomModelSerializer
|
||||
from rest_framework import serializers
|
||||
from apps.system.serializers import UserSimpleSerializer
|
||||
|
@ -78,6 +79,9 @@ class EventSerializer(serializers.ModelSerializer):
|
|||
cates_ = EventCateSimpleSerializer(source='cates', read_only=True, many=True)
|
||||
employee_ = EmployeeSerializer(source='employee', read_only=True)
|
||||
handle_user_name = serializers.CharField(source='handle_user.name', read_only=True)
|
||||
face_img = MyFilePathField()
|
||||
global_img = MyFilePathField()
|
||||
voice = MyFilePathField()
|
||||
|
||||
class Meta:
|
||||
model = Event
|
||||
|
|
|
@ -2,6 +2,7 @@ from apps.hrm.errors import PHONE_F_WRONG
|
|||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework import serializers
|
||||
from apps.hrm.services import HrmService
|
||||
from apps.utils.fields import MyFilePathField
|
||||
|
||||
|
||||
from apps.utils.serializers import CustomModelSerializer
|
||||
|
@ -75,6 +76,9 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
|
||||
class EmployeeImproveSerializer(CustomModelSerializer):
|
||||
photo = MyFilePathField()
|
||||
signature = MyFilePathField()
|
||||
|
||||
class Meta:
|
||||
model = Employee
|
||||
fields = ['photo', 'id_number', 'email', 'gender', 'signature']
|
||||
|
@ -91,6 +95,8 @@ class EmployeeSerializer(CustomModelSerializer):
|
|||
belong_dept_name = serializers.CharField(source='belong_dept.name', read_only=True)
|
||||
post_name = serializers.CharField(source='post.name', read_only=True)
|
||||
blt_ = serializers.SerializerMethodField()
|
||||
photo = MyFilePathField()
|
||||
signature = MyFilePathField()
|
||||
|
||||
class Meta:
|
||||
model = Employee
|
||||
|
@ -125,6 +131,8 @@ class NotWorkRemarkListSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class CertificateCreateUpdateSerializer(CustomModelSerializer):
|
||||
file = MyFilePathField()
|
||||
|
||||
class Meta:
|
||||
model = Certificate
|
||||
exclude = EXCLUDE_FIELDS
|
||||
|
@ -132,6 +140,7 @@ class CertificateCreateUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
class CertificateSerializer(CustomModelSerializer):
|
||||
employee_name = serializers.CharField(source='employee.name', read_only=True)
|
||||
file = MyFilePathField()
|
||||
|
||||
class Meta:
|
||||
model = Certificate
|
||||
|
|
|
@ -2,6 +2,7 @@ from apps.hrm.models import Certificate
|
|||
from apps.opm.models import GasCheck, Operation, Opl, OplCate, OplCert, OplWorker
|
||||
from apps.system.models import Dictionary
|
||||
from apps.system.serializers import DeptSimpleSerializer, DictSerializer, DictSimpleSerializer, UserSimpleSerializer
|
||||
from apps.utils.fields import MyFilePathField
|
||||
from apps.utils.serializers import CustomModelSerializer
|
||||
from apps.utils.constants import EXCLUDE_FIELDS
|
||||
from rest_framework import serializers
|
||||
|
@ -70,7 +71,7 @@ class OplWorkerCreateSerializer(CustomModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = OplWorker
|
||||
fields = ['worker', 'duty', 'certificates', 'opl']
|
||||
fields = ['id', 'worker', 'duty', 'certificates', 'opl']
|
||||
|
||||
def create(self, validated_data):
|
||||
opl = validated_data['opl']
|
||||
|
@ -101,7 +102,7 @@ class OplWorkerUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = OplWorker
|
||||
fields = ['duty', 'certificates']
|
||||
fields = ['id', 'duty', 'certificates']
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
certificates = validated_data.pop('certificates')
|
||||
|
@ -121,6 +122,12 @@ class OplWorkerUpdateSerializer(CustomModelSerializer):
|
|||
oplc.save()
|
||||
return oplw
|
||||
|
||||
class OplCertSerializer(CustomModelSerializer):
|
||||
file = MyFilePathField()
|
||||
class Meta:
|
||||
model = OplCert
|
||||
fields = ['certificate', 'name', 'type', 'number', 'issue_date', 'expiration_date', 'review_date', 'file']
|
||||
|
||||
|
||||
class OplWorkerSerializer(CustomModelSerializer):
|
||||
worker_ = UserSimpleSerializer(source='worker', read_only=True)
|
||||
|
@ -132,7 +139,7 @@ class OplWorkerSerializer(CustomModelSerializer):
|
|||
|
||||
def get_certificates_(self, obj):
|
||||
cs = OplCert.objects.filter(opl_worker=obj)
|
||||
return cs.values('certificate', 'name', 'type', 'number', 'issue_date', 'expiration_date', 'review_date', 'file')
|
||||
return OplCertSerializer(instance=cs, many=True).data
|
||||
|
||||
|
||||
class GasCheckCreateUpdateSerializer(CustomModelSerializer):
|
||||
|
|
|
@ -5,6 +5,7 @@ from apps.hrm.serializers import phone_check
|
|||
from apps.rpm.models import Rcertificate, Remployee, Rfile, Rparty, Rpjcertificate, Rpjfile, Rpjmember, Rpj
|
||||
from apps.system.models import Dept
|
||||
from apps.utils.constants import EXCLUDE_FIELDS
|
||||
from apps.utils.fields import MyFilePathField
|
||||
from apps.utils.serializers import CustomModelSerializer
|
||||
from apps.system.serializers import DictSerializer, DictSimpleSerializer, FileSerializer
|
||||
from rest_framework import serializers
|
||||
|
@ -77,7 +78,7 @@ class RpjCreateUpdateSerializer(CustomModelSerializer):
|
|||
belong_dept = serializers.PrimaryKeyRelatedField(queryset=Dept.objects.all(), required=False)
|
||||
class Meta:
|
||||
model = Rpj
|
||||
fields = ['name', 'contract_number', 'type', 'come_time', 'leave_time', 'belong_dept', 'rparty']
|
||||
fields = ['id', 'name', 'contract_number', 'type', 'come_time', 'leave_time', 'belong_dept', 'rparty']
|
||||
|
||||
|
||||
class RpjListSerializer(CustomModelSerializer):
|
||||
|
@ -116,7 +117,6 @@ class RpjListSerializer(CustomModelSerializer):
|
|||
|
||||
class RemployeeCreateSerializer(CustomModelSerializer):
|
||||
rparty = serializers.PrimaryKeyRelatedField(queryset=Rparty.objects.all(), label='相关方ID', required=False)
|
||||
|
||||
class Meta:
|
||||
model = Remployee
|
||||
fields = ['name', 'phone', 'photo', 'id_number', 'rparty']
|
||||
|
@ -140,7 +140,7 @@ class RemployeeUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
class RemployeeSerializer(CustomModelSerializer):
|
||||
rparty_name = serializers.CharField(source='rparty.name', read_only=True)
|
||||
|
||||
photo = MyFilePathField()
|
||||
class Meta:
|
||||
model = Remployee
|
||||
fields = '__all__'
|
||||
|
@ -155,7 +155,7 @@ class RcertificateCreateUpdateSerializer(CustomModelSerializer):
|
|||
class RcertificateSerializer(CustomModelSerializer):
|
||||
remployee_name = serializers.CharField(source='remployee.name', read_only=True)
|
||||
rparty_name = serializers.CharField(source='rparty.name', read_only=True)
|
||||
|
||||
file = MyFilePathField()
|
||||
class Meta:
|
||||
model = Rcertificate
|
||||
fields = '__all__'
|
||||
|
@ -236,6 +236,11 @@ class RpjmemberUpdateSerializer(CustomModelSerializer):
|
|||
Rpjmember.objects.exclude(id=ins.id).update(is_manager=False)
|
||||
return ins
|
||||
|
||||
class RpjcertificateSerializer(CustomModelSerializer):
|
||||
file = MyFilePathField()
|
||||
class Meta:
|
||||
model = Rpjcertificate
|
||||
fields = ['rcertificate', 'name', 'type', 'number', 'issue_date', 'expiration_date', 'review_date', 'file']
|
||||
|
||||
class RpjmemberSerializer(CustomModelSerializer):
|
||||
remployee_ = RemployeeSerializer(source='remployee', read_only=True)
|
||||
|
@ -247,7 +252,7 @@ class RpjmemberSerializer(CustomModelSerializer):
|
|||
|
||||
def get_rcertificates_(self, obj):
|
||||
cs = Rpjcertificate.objects.filter(rpj_member=obj)
|
||||
return cs.values('rcertificate', 'name', 'type', 'number', 'issue_date', 'expiration_date', 'review_date', 'file')
|
||||
return RpjcertificateSerializer(instance=cs, many=True).data
|
||||
|
||||
|
||||
class RpjfileSerializer(CustomModelSerializer):
|
||||
|
|
|
@ -4,6 +4,7 @@ from rest_framework import serializers
|
|||
from django_celery_results.models import TaskResult
|
||||
from apps.hrm.errors import PHONE_EXIST
|
||||
from apps.system.errors import USERNAME_EXIST
|
||||
from apps.utils.fields import MyFilePathField
|
||||
from apps.utils.serializers import CustomModelSerializer
|
||||
from apps.utils.constants import EXCLUDE_FIELDS, EXCLUDE_FIELDS_BASE
|
||||
from .models import (Dictionary, DictType, File, Dept, Permission, Post, PostRole,
|
||||
|
@ -299,7 +300,7 @@ class UserListSerializer(CustomModelSerializer):
|
|||
"""
|
||||
belong_dept_ = DeptSimpleSerializer(source='belong_dept', read_only=True)
|
||||
# posts_ = PostSimpleSerializer(source='posts', many=True)
|
||||
|
||||
avatar = MyFilePathField()
|
||||
class Meta:
|
||||
model = User
|
||||
exclude = ['password', 'secret']
|
||||
|
|
|
@ -460,7 +460,7 @@ class UserViewSet(CustomModelViewSet):
|
|||
'type': user.type,
|
||||
'name': user.name,
|
||||
'roles': user.roles.values_list('name', flat=True),
|
||||
'avatar': user.avatar,
|
||||
'avatar': settings.BASE_URL + user.avatar,
|
||||
'perms': perms,
|
||||
'belong_dept_name': user.belong_dept.name if user.belong_dept else '',
|
||||
'post_name': user.post.name if user.post else '',
|
||||
|
|
|
@ -85,7 +85,8 @@ class XxClient:
|
|||
# if settings.DEBUG:
|
||||
# print_roundtrip(r)
|
||||
ret = r.json()
|
||||
if ret.get('errorCode') == '1060000':
|
||||
if ret.get('errorCode') in ['1060000', 1060000]:
|
||||
print(ret.get('errorCode'))
|
||||
self.get_token() # 重新获取token
|
||||
self.request(url, method, params, json, timeout, raise_exception) # 重新请求
|
||||
else:
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
from django.conf import settings
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class MyFilePathField(serializers.CharField):
|
||||
|
||||
def to_representation(self, value):
|
||||
if 'http' in value:
|
||||
return str(value)
|
||||
return settings.BASE_URL + str(value)
|
|
@ -1,6 +1,7 @@
|
|||
from requests import request
|
||||
from apps.hrm.models import Employee
|
||||
from apps.utils.constants import EXCLUDE_FIELDS
|
||||
from apps.utils.fields import MyFilePathField
|
||||
from apps.utils.serializers import CustomModelSerializer
|
||||
from apps.vm.models import Visit, Visitor, Vpeople
|
||||
from rest_framework import serializers
|
||||
|
@ -15,7 +16,7 @@ from apps.wf.serializers import TicketSerializer
|
|||
class VisitCreateUpdateSerializer(CustomModelSerializer):
|
||||
class Meta:
|
||||
model = Visit
|
||||
fields = ['purpose', 'name', 'description', 'visit_time',
|
||||
fields = ['id', 'purpose', 'name', 'description', 'visit_time',
|
||||
'leave_time', 'receptionist', 'company', 'level', 'count_people']
|
||||
|
||||
|
||||
|
@ -44,6 +45,8 @@ class VisitorCreateSerializer(CustomModelSerializer):
|
|||
|
||||
|
||||
class VisitorSerializer(CustomModelSerializer):
|
||||
photo = MyFilePathField()
|
||||
|
||||
class Meta:
|
||||
model = Visitor
|
||||
fields = '__all__'
|
||||
|
|
Loading…
Reference in New Issue