作业证书增加bug
This commit is contained in:
parent
5823d4443c
commit
f63ae9c247
|
@ -57,14 +57,20 @@ class OplWorkerCreateSerializer(CustomModelSerializer):
|
|||
certificates = validated_data.pop('certificates')
|
||||
if OplWorker.objects.filter(worker=validated_data['worker'], opl=validated_data['opl']).exists():
|
||||
raise ParseError('该成员已加入')
|
||||
oplw = super().create(validated_data)
|
||||
for x in certificates:
|
||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
||||
defaults={'opl_worker': oplw, 'certificate': x})
|
||||
for f in Certificate._meta.fields:
|
||||
if f.name not in ['id']:
|
||||
setattr(oplc, f.name, getattr(x, f.name, None))
|
||||
oplc.save()
|
||||
with transaction.atomic():
|
||||
oplw = super().create(validated_data)
|
||||
for x in certificates:
|
||||
oplc = OplCert.objects.filter(opl_worker=oplw, certificate=x).first()
|
||||
if oplc:
|
||||
pass
|
||||
else:
|
||||
oplc = OplCert
|
||||
oplc.opl_worker = oplw
|
||||
oplc.certificate = x
|
||||
for f in Certificate._meta.fields:
|
||||
if f.name not in ['id']:
|
||||
setattr(oplc, f.name, getattr(x, f.name, None))
|
||||
oplc.save()
|
||||
return oplw
|
||||
|
||||
|
||||
|
@ -77,14 +83,20 @@ class OplWorkerUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
def update(self, instance, validated_data):
|
||||
certificates = validated_data.pop('certificates')
|
||||
oplw = super().update(instance, validated_data)
|
||||
for x in certificates:
|
||||
oplc, _ = OplCert.objects.get_or_create(opl_worker=oplw, certificate=x,
|
||||
defaults={'opl_worker': oplw, 'certificate': x})
|
||||
for f in Certificate._meta.fields:
|
||||
if f.name not in ['id']:
|
||||
setattr(oplc, f.name, getattr(x, f.name, None))
|
||||
oplc.save()
|
||||
with transaction.atomic():
|
||||
oplw = super().update(instance, validated_data)
|
||||
for x in certificates:
|
||||
oplc = OplCert.objects.filter(opl_worker=oplw, certificate=x).first()
|
||||
if oplc:
|
||||
pass
|
||||
else:
|
||||
oplc = OplCert
|
||||
oplc.opl_worker = oplw
|
||||
oplc.certificate = x
|
||||
for f in Certificate._meta.fields:
|
||||
if f.name not in ['id']:
|
||||
setattr(oplc, f.name, getattr(x, f.name, None))
|
||||
oplc.save()
|
||||
return oplw
|
||||
|
||||
|
||||
|
@ -123,7 +135,7 @@ class OplCreateUpdateSerializer(CustomModelSerializer):
|
|||
'power_end_time', 'power_start_time', 'power_days',
|
||||
'other_risk', 'other_emr', 'escape_route',
|
||||
'risks_checked', 'measures_checked', 'create_imgs']
|
||||
|
||||
|
||||
def create(self, validated_data):
|
||||
operation = validated_data['operation']
|
||||
if operation.state == Operation.OP_CLOSE:
|
||||
|
@ -133,6 +145,7 @@ class OplCreateUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
class OplSerializer(CustomModelSerializer):
|
||||
cate_name = serializers.CharField(source='cate.name', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Opl
|
||||
fields = '__all__'
|
||||
|
|
Loading…
Reference in New Issue