예제 #1
0
class SemesterStatusDetailSerializer(SemesterStatusSerializer):
    contract = FileField(required=False, allow_null=True)
    statistics = FileField(required=False, allow_null=True)
    evaluation = FileField(required=False, allow_null=True)

    contract_name = CharField(source='contract_id', read_only=True)
    statistics_name = CharField(source='statistics_id', read_only=True)
    evaluation_name = CharField(source='evaluation_id', read_only=True)

    class Meta:
        model = SemesterStatus
        fields = ('id', 'semester', 'contacted_status', 'contract',
                  'statistics', 'evaluation', 'contract_name',
                  'statistics_name', 'evaluation_name')
예제 #2
0
파일: serializers.py 프로젝트: vhellem/lego
class GalleryPictureSerializer(serializers.ModelSerializer):

    file = ImageField(required=True, options={'height': 700, 'smart': True})
    thumbnail = ImageField(source='file',
                           read_only=True,
                           options={
                               'height': 200,
                               'width': 300,
                               'smart': True
                           })
    raw_file = FileField(source='file', read_only=True)
    comments = CommentSerializer(read_only=True, many=True)
    comment_target = CharField(read_only=True)
    taggees = PublicUserField(many=True,
                              queryset=User.objects.all(),
                              required=False)

    class Meta:
        model = GalleryPicture
        fields = ('id', 'gallery', 'description', 'taggees', 'active', 'file',
                  'thumbnail', 'raw_file', 'comments', 'comment_target')
        read_only_fields = ('raw_file', 'thumbnail', 'gallery')

    def validate(self, attrs):
        gallery = Gallery.objects.get(
            pk=self.context['view'].kwargs['gallery_pk'])
        return {'gallery': gallery, **attrs}
예제 #3
0
class GalleryPictureSerializer(serializers.ModelSerializer):

    file = ImageField(required=True, options={"height": 700, "smart": True})
    thumbnail = ImageField(
        source="file",
        read_only=True,
        options={"height": 200, "width": 300, "smart": True},
    )
    raw_file = FileField(source="file", read_only=True)
    comments = CommentSerializer(read_only=True, many=True)
    content_target = CharField(read_only=True)
    taggees = PublicUserField(many=True, queryset=User.objects.all(), required=False)

    class Meta:
        model = GalleryPicture
        fields = (
            "id",
            "gallery",
            "description",
            "taggees",
            "active",
            "file",
            "thumbnail",
            "raw_file",
            "comments",
            "content_target",
        )
        read_only_fields = ("raw_file", "thumbnail", "gallery")

    def validate(self, attrs):
        gallery = Gallery.objects.get(pk=self.context["view"].kwargs["gallery_pk"])
        return {"gallery": gallery, **attrs}
예제 #4
0
class CompanyFileSerializer(serializers.ModelSerializer):
    file = FileField()

    class Meta:
        model = CompanyFile
        fields = ("id", "file")

    def create(self, validated_data):
        company = Company.objects.get(pk=self.context["view"].kwargs["company_pk"])
        validated_data["company"] = company
        return super().create(validated_data)
예제 #5
0
class CompanyFileSerializer(serializers.ModelSerializer):
    file = FileField()

    class Meta:
        model = CompanyFile
        fields = ('id', 'file')

    def create(self, validated_data):
        company = Company.objects.get(
            pk=self.context['view'].kwargs['company_pk'])
        validated_data['company'] = company
        return super().create(validated_data)
예제 #6
0
class SemesterStatusDetailSerializer(SemesterStatusSerializer):
    contract = FileField(required=False, allow_null=True)
    statistics = FileField(required=False, allow_null=True)
    evaluation = FileField(required=False, allow_null=True)

    contract_name = CharField(source="contract_id", read_only=True)
    statistics_name = CharField(source="statistics_id", read_only=True)
    evaluation_name = CharField(source="evaluation_id", read_only=True)

    class Meta:
        model = SemesterStatus
        fields = (
            "id",
            "semester",
            "contacted_status",
            "contract",
            "statistics",
            "evaluation",
            "contract_name",
            "statistics_name",
            "evaluation_name",
        )
예제 #7
0
파일: test_fields.py 프로젝트: webkom/lego
class FileFieldTestCase(BaseTestCase):

    fixtures = ["test_users.yaml", "test_files.yaml"]

    def setUp(self):
        self.field = FileField()
        self.file = File.objects.get(key="abakus.png")

    def test_options(self):
        field = FileField(allowed_types=["image"])
        self.assertEqual(field.allowed_types, ["image"])

    @mock.patch("lego.apps.files.fields.storage.generate_signed_url")
    def test_to_representation(self, mock_generate_signed_url):
        """To representation should return a presigned get"""
        file_mock = mock.Mock()
        self.assertEqual(
            self.field.to_representation(file_mock),
            mock_generate_signed_url.return_value,
        )
        mock_generate_signed_url.assert_called_once_with(
            File.bucket, file_mock.pk)

    def test_to_internal_value(self):
        """Make sure to_internal_value only accepts a key with valid token"""
        self.assertRaises(ValidationError, self.field.to_internal_value,
                          "file.png")
        self.assertRaises(ValidationError, self.field.to_internal_value,
                          "file.png:")
        self.assertRaises(ValidationError, self.field.to_internal_value,
                          "file.png:token:")

        self.assertEqual(self.field.to_internal_value("abakus.png:token"),
                         self.file)
        self.assertRaises(ValidationError, self.field.to_internal_value,
                          "abakus.png:_token")
예제 #8
0
파일: test_fields.py 프로젝트: webkom/lego
 def test_options(self):
     field = FileField(allowed_types=["image"])
     self.assertEqual(field.allowed_types, ["image"])
예제 #9
0
파일: test_fields.py 프로젝트: webkom/lego
 def setUp(self):
     self.field = FileField()
     self.file = File.objects.get(key="abakus.png")