feat: stlogserializer增加校验
This commit is contained in:
parent
2030812c18
commit
e78f864666
|
@ -50,11 +50,11 @@ class StLogSerializer(CustomModelSerializer):
|
|||
validated_data.pop('mgroup', None)
|
||||
validated_data.pop('start_time', None)
|
||||
end_time = validated_data.pop('end_time', None)
|
||||
if end_time: # 需要把涉及到的sflog都拉入
|
||||
cal_exp_duration_hour(instance.id)
|
||||
current_sflog = validated_data.pop('current_sflog')
|
||||
current_note = validated_data.pop('current_note', '')
|
||||
instance = super().update(instance, validated_data)
|
||||
if end_time: # 需要把涉及到的sflog都拉入
|
||||
cal_exp_duration_hour(instance.id)
|
||||
try:
|
||||
sflogexp = SfLogExp.objects.get(
|
||||
stlog=instance.stlog, sflog=current_sflog)
|
||||
|
@ -65,9 +65,14 @@ class StLogSerializer(CustomModelSerializer):
|
|||
return instance
|
||||
|
||||
def validate(self, attrs):
|
||||
now = timezone.now()
|
||||
start_time: datetime = attrs['start_time']
|
||||
end_time: datetime = attrs.get('end_time', None)
|
||||
if start_time > now:
|
||||
raise ParseError('开始时间应为历史时间')
|
||||
if end_time:
|
||||
if end_time > now:
|
||||
raise ParseError('开始时间应为历史时间')
|
||||
if end_time > start_time:
|
||||
attrs['duration'] = (
|
||||
end_time - start_time).total_seconds / 3600
|
||||
|
|
Loading…
Reference in New Issue