Beispiel #1
0
    def post(self, request):
        serializer = FileSerializer(
            data={
                'name': request.data['name'],
                'ext': request.data['name'].split('.')[1]
            })
        serializer.is_valid(raise_exception=True)
        f = serializer.save()
        key = str(f.id) + '-' + request.data['name'].split(
            '.')[0] + '/' + request.data['name']
        f.key = key
        f.save()

        s3 = boto3.client('s3',
                          settings.AWS_REGION,
                          endpoint_url=settings.AWS_S3_ENDPOINT_URL,
                          aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
                          aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
                          config=Config(signature_version='s3v4'))
        url = s3.generate_presigned_url(ClientMethod='put_object',
                                        ExpiresIn=3600,
                                        Params={
                                            'Bucket':
                                            settings.AWS_STORAGE_BUCKET_NAME,
                                            'Key': key
                                        })
        return Response({'url': url, 'id': f.id})
Beispiel #2
0
 def put(self, request, id):
     file = get_object_or_404(File, pk=id)
     file.active = True
     file.save()
     org = Organization.object.get()
     org.logo = file
     org.save()
     return Response(FileSerializer(file).data)
class IntroEmployeeSerializer(serializers.ModelSerializer):
    name = serializers.SerializerMethodField()
    profile_image = FileSerializer(read_only=True)

    class Meta:
        model = get_user_model()
        fields = ('id', 'first_name', 'last_name', 'email', 'position', 'phone', 'full_name', 'slack_user_id',
                  'twitter', 'facebook', 'linkedin', 'message', 'profile_image', 'name')

    def get_name(self, obj):
        return obj.first_name + ' ' + obj.last_name
class BadgeSerializer(serializers.ModelSerializer):
    search_type = serializers.CharField(default='badge', read_only=True)
    content = ContentField()
    image = FileSerializer(read_only=True)
    image_id = serializers.PrimaryKeyRelatedField(
        source='image',
        queryset=File.objects.all(),
        required=False,
        allow_null=True
    )

    class Meta:
        model = Badge
        fields = '__all__'
Beispiel #5
0
 def email_message(self):
     email_data = []
     for i in self.content_json.filter(type__in=[
             'p', 'quote', 'hr', 'ul', 'ol', 'h1', 'h2', 'h3', 'image',
             'file'
     ]):
         if i.type == 'quote':
             email_data.append({"type": 'block', "text": i.content})
         else:
             files = []
             if i.files.all().exists():
                 files = FileSerializer(i.files.all(), many=True).data
             email_data.append({
                 "type": i.type,
                 "text": i.content,
                 "items": i.items,
                 "files": files
             })
     return email_data
class EmployeeSerializer(BaseUserSerializer):
    search_type = serializers.CharField(default='employee', read_only=True)
    slack_loading = serializers.BooleanField(default=False, read_only=True)
    email_loading = serializers.BooleanField(default=False, read_only=True)
    role = serializers.IntegerField(default='3', read_only=True)
    name = serializers.SerializerMethodField()
    has_pwd = serializers.SerializerMethodField()
    profile_image = FileSerializer(read_only=True)
    profile_image_id = serializers.PrimaryKeyRelatedField(
        source='profile_image', queryset=File.objects.all(), required=False)

    class Meta:
        model = get_user_model()
        fields = ('id', 'first_name', 'last_name', 'email', 'position',
                  'phone', 'full_name', 'slack_user_id', 'has_pwd',
                  'search_type', 'twitter', 'facebook', 'linkedin', 'message',
                  'profile_image', 'profile_image_id', 'name', 'role',
                  'slack_loading', 'email_loading', 'department')

    def get_has_pwd(self, obj):
        return obj.password != ''

    def get_name(self, obj):
        return obj.first_name + ' ' + obj.last_name
Beispiel #7
0
 def put(self, request, id):
     file = get_object_or_404(File, pk=id)
     file.active = True
     file.save()
     return Response(FileSerializer(file).data)
class DetailOrganizationSerializer(BaseOrganizationSerializer):
    logo = FileSerializer(read_only=True)

    class Meta:
        model = Organization
        fields = '__all__'
Beispiel #9
0
class DetailOrganizationSerializer(BaseOrganizationSerializer):
    logo = FileSerializer(allow_null=True)

    class Meta:
        model = Organization
        fields = '__all__'