class ProjectRoleSerializer(serializers.ModelSerializer): exo_role = CategoryExORoleSerializer() project = serializers.HiddenField(default=CurrentProjectDefault()) class Meta: model = ProjectRole fields = ['exo_role', 'project']
class UserInTeamSerializer(serializers.ModelSerializer): name = serializers.CharField(source='team.name') exo_role = CategoryExORoleSerializer(source='team_role.exo_role') team_pk = serializers.IntegerField(source='team.pk') class Meta: model = UserTeamRole fields = ['name', 'exo_role', 'pk', 'team_pk']
class TeamRoleSerializer(serializers.ModelSerializer): project = serializers.HiddenField( default=CurrentProjectDefault()) exo_role = CategoryExORoleSerializer() class Meta: model = ProjectTeamRole fields = ['pk', 'project', 'exo_role']
def get_project_roles(self, obj): COACH_OR_PARTICIPANT = [ settings.EXO_ROLE_CODE_SPRINT_COACH, settings.EXO_ROLE_CODE_SPRINT_PARTICIPANT, ] queryset = obj.user_project_roles.filter( project_role__code__in=COACH_OR_PARTICIPANT).exo_roles() return CategoryExORoleSerializer(queryset, many=True).data
class JobSerializer(serializers.ModelSerializer): category = ExORoleCategorySerializer() exo_role = CategoryExORoleSerializer() class Meta: model = Job fields = [ 'pk', 'uuid', 'category', 'title', 'start', 'end', 'status', 'status_detail', 'exo_role', 'url', 'extra_data', ]
def get_project_roles(self, obj): user = self.context.get('request').user exo_roles = user.user_project_roles.filter( project_role__project=obj).exo_roles() return CategoryExORoleSerializer(exo_roles, many=True).data
class TeamRoleSimpleSerializer(serializers.ModelSerializer): exo_role = CategoryExORoleSerializer() class Meta: model = ProjectTeamRole fields = ['exo_role', 'pk']
def get_roles(self, obj): user = self.context.get('request').user queryset = obj.user_team_roles.filter(user=user).exo_roles() return CategoryExORoleSerializer(queryset, many=True).data
def get_project_roles(self, obj): project = self.context.get('view').project queryset = obj.user_project_roles.filter( project_role__project=project).exo_roles() return CategoryExORoleSerializer(queryset, many=True).data