class ProjDetailSerializer_user_withsecretinfo(serializers.ModelSerializer): tags = serializers.SerializerMethodField() service = serializers.SerializerMethodField() industries = serializers.SerializerMethodField() country = countrySerializer() transactionType = serializers.SerializerMethodField() finance = serializers.SerializerMethodField() attachment = serializers.SerializerMethodField() supportUser = UserCommenSerializer() takeUser = UserCommenSerializer() makeUser = UserCommenSerializer() linkpdfurl = serializers.SerializerMethodField() class Meta: model = project exclude = ('createuser', 'lastmodifyuser', 'deleteduser', 'deletedtime', 'datasource', 'isSendEmail') depth = 1 def get_tags(self, obj): qs = obj.tags.filter(tag_projects__is_deleted=False) if qs.exists(): return tagSerializer(qs, many=True).data return None def get_industries(self, obj): qs = obj.project_industries.filter(is_deleted=False) if qs.exists(): return ProjIndustrySerializer(qs, many=True).data return None def get_transactionType(self, obj): qs = obj.transactionType.filter( transactionType_projects__is_deleted=False) if qs.exists(): return transactionTypeSerializer(qs, many=True).data return None def get_finance(self, obj): usertrader = obj.proj_finances.filter(is_deleted=False) if usertrader.exists(): return FinanceSerializer(usertrader, many=True).data return None def get_attachment(self, obj): usertrader = obj.proj_attachment.filter(is_deleted=False) if usertrader.exists(): return ProjAttachmentSerializer(usertrader, many=True).data return None def get_service(self, obj): qs = obj.service.filter(service_projects__is_deleted=False) if qs.exists(): return serviceSerializer(qs, many=True).data return None def get_linkpdfurl(self, obj): if obj.linkpdfkey and obj.ismarketplace: return getUrlWithBucketAndKey('file', obj.linkpdfkey) return None
class TimeLineListSerializer_admin(serializers.ModelSerializer): investor = UserCommenSerializer() trader = UserCommenSerializer() proj = ProjSimpleSerializer() transationStatu = serializers.SerializerMethodField() supportor = serializers.SerializerMethodField() class Meta: model = timeline # fields = '__all__' exclude = ('is_deleted', 'deleteduser', 'deletedtime', 'lastmodifyuser', 'lastmodifytime', 'createuser', 'createdtime') def get_supportor(self, obj): user = obj.proj.supportUser if user.is_deleted: return None return UserCommenSerializer(user).data def get_transationStatu(self, obj): qs = obj.timeline_transationStatus.all().filter(is_deleted=False, isActive=True) if qs.exists(): return TimeLineStatuSerializer(qs.first()).data return None
class FavoriteSerializer(serializers.ModelSerializer): user = UserCommenSerializer() trader = UserCommenSerializer() proj = ProjCommonSerializer() class Meta: model = favoriteProject fields = '__all__'
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}
class ProjSerializer(serializers.ModelSerializer): supportUser = UserCommenSerializer() takeUser = UserCommenSerializer() makeUser = UserCommenSerializer() proj_finances = ProjFinanceSerializer(many=True) proj_attachment = ProjAttachmentSerializer(many=True) class Meta: model = project exclude = ('isSendEmail', 'datasource', 'realname') depth = 1
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
class OrgBDBlackSerializer(serializers.ModelSerializer): org = OrgCommonSerializer() proj = ProjSimpleSerializer() createuser = UserCommenSerializer() class Meta: model = OrgBDBlack exclude = ('deleteduser', 'deletedtime', 'datasource', 'is_deleted')
class ProjSerializer(serializers.ModelSerializer): supportUser = UserCommenSerializer() PM = UserCommenSerializer() projTraders = serializers.SerializerMethodField() proj_finances = ProjFinanceSerializer(many=True) proj_attachment = ProjAttachmentSerializer(many=True) lastProject = ProjSimpleSerializer() class Meta: model = project exclude = ('isSendEmail', 'datasource', 'realname') depth = 1 def get_projTraders(self, obj): qs = obj.proj_traders.filter(is_deleted=False, user__isnull=False) if qs.exists(): return ProjTradersSerializer(qs, many=True).data return None
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
class ScheduleSerializer(serializers.ModelSerializer): user = UserInfoSerializer() createuser = UserCommenSerializer() country = countrySerializer() proj = ProjCommonSerializer() location = orgAreaSerializer() meeting = WebEXMeetingSerializer() class Meta: model = schedule exclude = ('deleteduser', 'datasource', 'is_deleted', 'deletedtime')
class ScheduleSerializer(serializers.ModelSerializer): user = UserInfoSerializer() createuser = UserCommenSerializer() country = countrySerializer() proj = ProjCommonSerializer() location = orgAreaSerializer() class Meta: model = schedule fields = ('id', 'comments', 'scheduledtime', 'user', 'address', 'projtitle', 'proj', 'createuser', 'createdtime', 'country', 'location')
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
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
def get_useinfo(self, obj): if obj.bduser: return UserCommenSerializer(obj.bduser).data return None
class ProjDetailSerializer_all(serializers.ModelSerializer): tags = serializers.SerializerMethodField() service = serializers.SerializerMethodField() industries = serializers.SerializerMethodField() transactionType = serializers.SerializerMethodField() finance = serializers.SerializerMethodField() attachment = serializers.SerializerMethodField() country = countryWithContinentSerializer() supportUser = UserCommenSerializer() PM = UserCommenSerializer() createuser = UserCommenSerializer() projTraders = serializers.SerializerMethodField() linkpdfurl = serializers.SerializerMethodField() lastProject = ProjSimpleSerializer() currency = currencyTypeSerializer() projstatus = ProjectStatusSerializer() class Meta: model = project exclude = ( 'lastmodifyuser', 'deleteduser', 'deletedtime', 'datasource', 'isSendEmail', ) def get_service(self, obj): qs = obj.service.filter(service_projects__is_deleted=False) if qs.exists(): return serviceSerializer(qs, many=True).data return None def get_projTraders(self, obj): qs = obj.proj_traders.filter(is_deleted=False, user__isnull=False) if qs.exists(): return ProjTradersSerializer(qs, many=True).data return None def get_tags(self, obj): qs = obj.tags.filter(tag_projects__is_deleted=False) if qs.exists(): return tagSerializer(qs, many=True).data return None def get_industries(self, obj): qs = obj.project_industries.filter(is_deleted=False) if qs.exists(): return ProjIndustrySerializer(qs, many=True).data return None def get_transactionType(self, obj): qs = obj.transactionType.filter( transactionType_projects__is_deleted=False) if qs.exists(): return transactionTypeSerializer(qs, many=True).data return None def get_finance(self, obj): usertrader = obj.proj_finances.filter(is_deleted=False) if usertrader.exists(): return FinanceSerializer(usertrader, many=True).data return None def get_attachment(self, obj): usertrader = obj.proj_attachment.filter(is_deleted=False) if usertrader.exists(): return ProjAttachmentSerializer(usertrader, many=True).data return None def get_linkpdfurl(self, obj): return None
class ProjTradersSerializer(serializers.ModelSerializer): user = UserCommenSerializer() class Meta: model = projTraders fields = '__all__'
class ProjectBDManagersSerializer(serializers.ModelSerializer): manager = UserCommenSerializer() class Meta: model = ProjectBDManagers fields = ('manager', 'id', 'createdtime', 'projectBD', 'createuser')
def get_supportor(self, obj): user = obj.proj.supportUser if user.is_deleted: return None return UserCommenSerializer(user).data