class ResponseFileSerializer(serializers.ModelSerializer): author = UserSerializer() creation_date = DateTimeFieldWihTZ(source='created', format='%A %d %B %Y') creation_time = DateTimeFieldWihTZ(source='created', format='%X') class Meta: model = ResponseFile fields = ('id', 'url', 'basename', 'creation_date', 'creation_time', 'author')
class InquirerSerializer(serializers.Serializer): inquirerId = serializers.IntegerField(source='id', read_only=True) inquirerTitle = serializers.CharField(source='title') inquirerStartDate = DateTimeFieldWihTZ(source='date_start') inquirerEndDate = DateTimeFieldWihTZ(source='date_end') def validate(self, data): if data['date_start'] >= data['date_end']: raise serializers.ValidationError({'inquirerStartDate': 'Дата начала не может быть больше даты окончания'}) elif data['date_start'] <= datetime.now(pytz.timezone(settings.TIME_ZONE)): raise serializers.ValidationError({'inquirerStartDate': 'Дата начала не может быть в прошлом'}) return data
class ControlDetailQuestionnaireSerializer(serializers.ModelSerializer): editor = ControlDetailUserSerializer(read_only=True, required=False) modified_date = DateTimeFieldWihTZ(source='modified', format='%a %d %B %Y', read_only=True) modified_time = DateTimeFieldWihTZ(source='modified', format='%X', read_only=True) class Meta: model = Questionnaire fields = ('id', 'title', 'numbering', 'url', 'is_draft', 'sent_date', 'end_date', 'editor', 'modified_date', 'modified_time')
class QuestionnaireSerializer(serializers.ModelSerializer): themes = ThemeSerializer(many=True, read_only=True) editor = ControlDetailUserSerializer(read_only=True, required=False) modified_date = DateTimeFieldWihTZ(source='modified', format='%a %d %B %Y', read_only=True) modified_time = DateTimeFieldWihTZ(source='modified', format='%X', read_only=True) class Meta: model = Questionnaire fields = ('id', 'title', 'sent_date', 'end_date', 'description', 'control', 'themes', 'is_draft', 'editor', 'title_display', 'numbering', 'modified_date', 'modified_time') extra_kwargs = {'control': {'required': True}}
class UserInquirerSerializer(serializers.Serializer): userInquirerId = serializers.IntegerField(source="id") inquirerTitle = serializers.CharField(source="inquirer.title") userTests = UserTestsSerializer(many=True, source="tests") dateStart = DateTimeFieldWihTZ(source="inquirer.date_start") dateEnd = DateTimeFieldWihTZ(source="inquirer.date_end")