Esempio n. 1
0
class ProjectBDSerializer(serializers.ModelSerializer):
    BDComments = serializers.SerializerMethodField()
    location = orgAreaSerializer()
    usertitle = titleTypeSerializer()
    bd_status = BDStatusSerializer()
    manager = serializers.SerializerMethodField()
    contractors = UserCommenSerializer()
    financeCurrency = currencyTypeSerializer()

    class Meta:
        model = ProjectBD
        exclude = ('deleteduser', 'deletedtime', 'datasource', 'is_deleted')

    def get_manager(self, obj):
        qs = obj.ProjectBD_managers.filter(is_deleted=False)
        if qs.exists():
            return {
                'main': UserCommenSerializer(obj.manager).data,
                'normal': ProjectBDManagersSerializer(qs, many=True).data
            }
        return {'main': UserCommenSerializer(obj.manager).data, 'normal': None}

    def get_BDComments(self, obj):
        user_id = self.context.get('user_id')
        manage = self.context.get('manage')
        indGroup_id = self.context.get('indGroup_id')
        if manage or is_projBDManager(
                user_id, obj) or (obj.indGroup
                                  and obj.indGroup.id == indGroup_id):
            qs = obj.ProjectBD_comments.filter(
                is_deleted=False).order_by('-createdtime')
            if qs.exists():
                return ProjectBDCommentsSerializer(qs, many=True).data
        return None
Esempio n. 2
0
class UserWorkingPositionRecordsSerializer(serializers.ModelSerializer):
    user = UserSimpleSerializer()
    indGroup = industryGroupSerializer()
    title = titleTypeSerializer()

    class Meta:
        model = UserWorkingPositionRecords
        exclude = ('deleteduser', 'datasource', 'is_deleted', 'deletedtime')
Esempio n. 3
0
class UserCommenSerializer(serializers.ModelSerializer):
    tags = serializers.SerializerMethodField()
    photourl = serializers.SerializerMethodField()
    title = titleTypeSerializer()
    mobile = serializers.SerializerMethodField()
    email = serializers.SerializerMethodField()
    org = OrgCommonSerializer()
    education = EducationSerializer()
    directSupervisor = UserNameSerializer()
    mentor = UserNameSerializer()
    userstatus = AuditStatusSerializer()
    indGroup = industryGroupSerializer

    class Meta:
        model = MyUser
        fields = ('id', 'usernameC', 'usernameE', 'tags', 'userstatus', 'photourl', 'title', 'onjob', 'mobile', 'workType',
                  'mobileAreaCode', 'email', 'is_active', 'org', 'indGroup', 'entryTime', 'bornTime', 'isMarried',
                  'directSupervisor', 'mentor', 'school', 'specialty', 'education', 'specialtyhobby', 'others')

    def get_tags(self, obj):
        qs = obj.tags.filter(tag_usertags__is_deleted=False, is_deleted=False)
        if qs.exists():
            return tagSerializer(qs, many=True).data
        return None

    def get_photourl(self, obj):
        if obj.photoKey:
            return getUrlWithBucketAndKey('image', obj.photoKey)
        else:
            return None

    def get_mobile(self, obj):
        if obj.mobile and obj.mobile not in ['', u'']:
            length = len(obj.mobile)
            if length > 4:
                center = str(obj.mobile)[0: (length - 4) // 2] + '****' + str(obj.mobile)[(length - 4) // 2 + 4:]
            else:
                center = '****'
            return center
        else:
            return None

    def get_email(self, obj):
        if obj.email and obj.email not in ['', u'']:
            index = str(obj.email).find('@')
            if index >= 0:
                center = '****' + str(obj.email)[index:]
            else:
                center = '****'
            return center
        else:
            return None
class UserCommenSerializer(serializers.ModelSerializer):
    tags = serializers.SerializerMethodField()
    photourl = serializers.SerializerMethodField()
    title = titleTypeSerializer()
    mobile = serializers.SerializerMethodField()
    email = serializers.SerializerMethodField()
    org = OrgCommonSerializer()

    class Meta:
        model = MyUser
        fields = ('id', 'usernameC', 'usernameE', 'tags', 'userstatus',
                  'photourl', 'title', 'onjob', 'mobile', 'email', 'org')

    def get_tags(self, obj):
        qs = obj.tags.filter(tag_usertags__is_deleted=False)
        if qs.exists():
            return tagSerializer(qs, many=True).data
        return None

    def get_photourl(self, obj):
        if obj.photoKey:
            return getUrlWithBucketAndKey('image', obj.photoKey)
        else:
            return None

    def get_mobile(self, obj):
        if obj.mobile and obj.mobile not in ['', u'']:
            length = len(obj.mobile)
            if length > 4:
                center = str(obj.mobile)[0:(length - 4) // 2] + '****' + str(
                    obj.mobile)[(length - 4) // 2 + 4:]
            else:
                center = '****'
            return center
        else:
            return None

    def get_email(self, obj):
        if obj.email and obj.email not in ['', u'']:
            index = str(obj.email).find('@')
            if index >= 0:
                center = '****' + str(obj.email)[index:]
            else:
                center = '****'
            return center
        else:
            return None
Esempio n. 5
0
class ProjectBDSerializer(serializers.ModelSerializer):
    BDComments = serializers.SerializerMethodField()
    location = orgAreaSerializer()
    usertitle = titleTypeSerializer()
    bd_status = BDStatusSerializer()
    manager = UserCommenSerializer()

    class Meta:
        model = ProjectBD
        exclude = ('deleteduser', 'deletedtime', 'datasource', 'is_deleted',
                   'createuser')

    def get_BDComments(self, obj):
        qs = obj.ProjectBD_comments.filter(is_deleted=False)
        if qs.exists():
            return ProjectBDCommentsSerializer(qs, many=True).data
        return None
Esempio n. 6
0
class MeetingBDSerializer(serializers.ModelSerializer):
    org = OrgCommonSerializer()
    proj = ProjSimpleSerializer()
    usertitle = titleTypeSerializer()
    manager = UserCommenSerializer()
    attachmenturl = serializers.SerializerMethodField()

    class Meta:
        model = MeetingBD
        exclude = ('deleteduser', 'deletedtime', 'datasource', 'is_deleted',
                   'createuser')

    def get_attachmenturl(self, obj):
        if obj.attachmentbucket and obj.attachment:
            return getUrlWithBucketAndKey(obj.attachmentbucket, obj.attachment)
        else:
            return None
Esempio n. 7
0
class OrgBDSerializer(serializers.ModelSerializer):
    org = OrgCommonSerializer()
    proj = ProjSimpleSerializer()
    BDComments = serializers.SerializerMethodField()
    usertitle = titleTypeSerializer()
    bd_status = BDStatusSerializer()
    manager = UserCommenSerializer()
    wechat = serializers.SerializerMethodField()
    email = serializers.SerializerMethodField()
    useinfo = serializers.SerializerMethodField()
    createuser = UserCommenSerializer()
    makeUser = serializers.SerializerMethodField()

    class Meta:
        model = OrgBD
        exclude = ('deleteduser', 'deletedtime', 'datasource', 'is_deleted')

    def get_BDComments(self, obj):
        qs = obj.OrgBD_comments.filter(is_deleted=False)
        if qs.exists():
            return OrgBDCommentsSerializer(qs, many=True).data
        return None

    def get_wechat(self, obj):
        if obj.bduser:
            return obj.bduser.wechat
        return None

    def get_email(self, obj):
        if obj.bduser:
            return obj.bduser.email
        return None

    def get_useinfo(self, obj):
        if obj.bduser:
            return UserCommenSerializer(obj.bduser).data
        return None

    def get_makeUser(self, obj):
        if obj.proj:
            if obj.proj.makeUser:
                return obj.proj.makeUser_id
        return None
Esempio n. 8
0
class OrgBDSerializer(serializers.ModelSerializer):
    org = OrgCommonSerializer()
    proj = ProjSimpleSerializer()
    BDComments = serializers.SerializerMethodField()
    usertitle = titleTypeSerializer()
    cardurl = serializers.SerializerMethodField()
    userreamrk = serializers.SerializerMethodField()
    userattachment = serializers.SerializerMethodField()
    manager = UserSimpleSerializer()
    userinfo = serializers.SerializerMethodField()
    createuser = UserSimpleSerializer()

    class Meta:
        model = OrgBD
        exclude = ('deleteduser', 'deletedtime', 'datasource', 'is_deleted',
                   'usermobile')

    def get_BDComments(self, obj):
        qs = obj.OrgBD_comments.filter(is_deleted=False)
        if qs.exists():
            return OrgBDCommentsSerializer(qs, many=True).data
        return None

    def get_cardurl(self, obj):
        if obj.bduser:
            if obj.bduser.cardKey:
                return getUrlWithBucketAndKey('image', obj.bduser.cardKey)
        return None

    def get_userreamrk(self, obj):
        if obj.bduser:
            return UserRemarkSimpleSerializer(
                obj.bduser.user_remarks.all().filter(is_deleted=False),
                many=True).data
        return None

    def get_userattachment(self, obj):
        if obj.bduser:
            return UserAttachmentSerializer(
                obj.bduser.user_userAttachments.all().filter(is_deleted=False),
                many=True).data
        return None

    def get_userinfo(self, obj):
        user_id = self.context.get("user_id")
        info = {
            'email': None,
            'mobile': None,
            'wechat': None,
            'tags': None,
            'photourl': None,
            'cardurl': None
        }
        if obj.bduser:
            tags = obj.bduser.tags.filter(tag_usertags__is_deleted=False)
            if tags.exists():
                info['tags'] = tagSerializer(tags, many=True).data
            if obj.bduser.photoKey:
                info['photourl'] = getUrlWithBucketAndKey(
                    'image', obj.bduser.photoKey)
            if obj.bduser.photoKey:
                info['cardurl'] = getUrlWithBucketAndKey(
                    'image', obj.bduser.cardKey)
            if user_id:
                if obj.manager.id == user_id or is_userInvestor(
                        obj.bduser, user_id):
                    info['email'] = obj.bduser.email
                    info['mobile'] = obj.bduser.mobile
                    info['wechat'] = obj.bduser.wechat
        return info