예제 #1
0
파일: serializers.py 프로젝트: rtm516/core
class SelfSerializer(IncorrectSolvesMixin, serializers.ModelSerializer):
    from team.serializers import MinimalTeamSerializer
    solves = SolveSerializer(many=True, read_only=True)
    team = MinimalTeamSerializer(read_only=True)
    team_name = serializers.ReadOnlyField(source='team.name')
    email = serializers.EmailField()
    incorrect_solves = serializers.SerializerMethodField()
    has_2fa = serializers.BooleanField()

    class Meta:
        model = get_user_model()
        fields = ['id', 'username', 'is_staff', 'bio', 'discord', 'discordid', 'twitter', 'reddit', 'team', 'email',
                  'has_2fa', 'points', 'solves', 'team_name', 'leaderboard_points', 'date_joined',
                  'incorrect_solves', 'is_verified']
        read_only_fields = ['id', 'is_staff', 'team', 'email', 'points', 'leaderboard_points', 'date_joined',
                            'incorrect_solves', 'is_verified']

    def validate_email(self, value):
        self.instance.password_reset_token = secrets.token_hex()
        self.instance.email_token = secrets.token_hex()
        self.instance.save()
        return value

    def update(self, instance, validated_data):
        if not config.get("enable_teams"):
            if instance.team:
                instance.team.name = validated_data.get("username", instance.username)
        return super(SelfSerializer, self).update(instance, validated_data)
예제 #2
0
파일: serializers.py 프로젝트: rtm516/core
class AdminMemberSerializer(IncorrectSolvesMixin, serializers.ModelSerializer):
    solves = SolveSerializer(many=True, read_only=True)
    team_name = serializers.ReadOnlyField(source='team.name')
    incorrect_solves = serializers.SerializerMethodField()

    class Meta:
        model = get_user_model()
        fields = ['id', 'username', 'is_staff', 'bio', 'discord', 'discordid', 'twitter', 'reddit', 'team',
                  'points', 'is_visible', 'is_active', 'solves', 'team_name', 'email', 'email_verified',
                  'leaderboard_points', 'date_joined', 'state_actor', 'incorrect_solves', 'is_verified']
예제 #3
0
class AdminTeamSerializer(IncorrectSolvesMixin, serializers.ModelSerializer):
    members = MinimalMemberSerializer(many=True, read_only=True)
    solves = SolveSerializer(many=True, read_only=True)
    incorrect_solves = serializers.SerializerMethodField()

    class Meta:
        model = Team
        fields = [
            'id', 'is_visible', 'name', 'password', 'owner', 'description',
            'members', 'solves', 'incorrect_solves'
        ]
예제 #4
0
class TeamSerializer(IncorrectSolvesMixin, serializers.ModelSerializer):
    members = MinimalMemberSerializer(many=True, read_only=True)
    solves = SolveSerializer(many=True, read_only=True)
    incorrect_solves = serializers.SerializerMethodField()

    class Meta:
        model = Team
        fields = [
            'id', 'is_visible', 'name', 'owner', 'description', 'members',
            'solves', 'incorrect_solves'
        ]

    def get_incorrect_solves(self, instance):
        return instance.solves.filter(correct=False).count()
예제 #5
0
파일: serializers.py 프로젝트: rtm516/core
class AdminTeamSerializer(IncorrectSolvesMixin, serializers.ModelSerializer):
    members = MinimalMemberSerializer(many=True, read_only=True)
    solves = SolveSerializer(many=True, read_only=True)
    incorrect_solves = serializers.SerializerMethodField()

    class Meta:
        model = Team
        fields = [
            "id",
            "is_visible",
            "name",
            "password",
            "owner",
            "description",
            "members",
            "solves",
            "incorrect_solves",
            "size_limit_exempt",
        ]
예제 #6
0
파일: serializers.py 프로젝트: rtm516/core
class SelfTeamSerializer(IncorrectSolvesMixin, serializers.ModelSerializer):
    members = MinimalMemberSerializer(many=True, read_only=True)
    solves = SolveSerializer(many=True, read_only=True)
    incorrect_solves = serializers.SerializerMethodField()

    class Meta:
        model = Team
        fields = [
            "id",
            "is_visible",
            "name",
            "password",
            "owner",
            "description",
            "members",
            "solves",
            "incorrect_solves",
            "points",
            "leaderboard_points",
        ]
        read_only_fields = ["id", "is_visible", "incorrect_solves"]
예제 #7
0
파일: serializers.py 프로젝트: rtm516/core
class TeamSerializer(IncorrectSolvesMixin, serializers.ModelSerializer):
    members = MinimalMemberSerializer(many=True, read_only=True)
    solves = SolveSerializer(many=True, read_only=True)
    incorrect_solves = serializers.SerializerMethodField()

    class Meta:
        model = Team
        fields = [
            "id",
            "is_visible",
            "name",
            "owner",
            "description",
            "members",
            "solves",
            "incorrect_solves",
            "points",
            "leaderboard_points",
        ]

    def get_incorrect_solves(self, instance):
        return instance.solves.filter(correct=False).count()