Exemple #1
0
class PodcastSerializer(BasisModelSerializer):

    description = ContentSerializerField()
    authors = PublicUserSerializer(many=True)
    thanks = PublicUserSerializer(many=True)

    class Meta:
        model = Podcast
        fields = ('id', 'source', 'created_at', 'description', 'authors',
                  'thanks')
Exemple #2
0
class PodcastSerializer(BasisModelSerializer):

    description = ContentSerializerField()
    authors = PublicUserSerializer(many=True)
    thanks = PublicUserSerializer(many=True)

    class Meta:
        model = Podcast
        fields = ("id", "source", "created_at", "description", "authors",
                  "thanks")
Exemple #3
0
class RegistrationPublicReadSerializer(BasisModelSerializer):
    user = PublicUserSerializer()

    class Meta:
        model = Registration
        fields = ('id', 'user', 'pool', 'status')
        read_only = True
Exemple #4
0
class GroupedReactionSerializer(serializers.Serializer):
    count = serializers.IntegerField()
    type = serializers.CharField()
    users = PublicUserSerializer(many=True)

    class Meta:
        fields = ("count", "type", "users")
Exemple #5
0
class EventReadDetailedSerializer(TagSerializerMixin, BasisModelSerializer):
    comments = CommentSerializer(read_only=True, many=True)
    comment_target = CharField(read_only=True)
    cover = ImageField(required=False, options={'height': 500})
    company = CompanyField(queryset=Company.objects.all())
    responsible_group = AbakusGroupField(queryset=AbakusGroup.objects.all(),
                                         required=False,
                                         allow_null=True)
    pools = PoolReadSerializer(many=True)
    active_capacity = serializers.ReadOnlyField()
    text = ContentSerializerField()
    created_by = PublicUserSerializer()

    class Meta:
        model = Event
        fields = ('id', 'title', 'description', 'cover', 'text', 'event_type',
                  'location', 'comments', 'comment_target', 'start_time',
                  'end_time', 'merge_time', 'pools', 'unregistration_deadline',
                  'company', 'responsible_group', 'active_capacity',
                  'feedback_description', 'feedback_required', 'is_priced',
                  'price_member', 'price_guest', 'use_stripe',
                  'payment_due_date', 'use_captcha',
                  'waiting_registration_count', 'tags', 'is_merged',
                  'heed_penalties', 'created_by', 'is_abakom_only',
                  'registration_count', 'survey')
        read_only = True
Exemple #6
0
class CommentSerializer(BasisModelSerializer):
    author = PublicUserSerializer(read_only=True, source="created_by")
    created_at = DateTimeField(read_only=True)
    updated_at = DateTimeField(read_only=True)
    content_target = GenericRelationField(source="content_object")
    text = ContentSerializerField()

    class Meta:
        model = Comment
        fields = (
            "id",
            "text",
            "author",
            "content_target",
            "created_at",
            "updated_at",
            "parent",
        )

    def validate(self, attrs):
        content_target = attrs.get("content_object")

        if content_target and "parent" in attrs:
            parent = attrs["parent"]
            if (
                parent.object_id != content_target.id
                or parent.content_type
                != ContentType.objects.get_for_model(content_target)
            ):
                raise ValidationError(
                    {"parent": "parent does not point to the same content_target"}
                )

        return attrs
Exemple #7
0
class RegistrationPublicReadSerializer(BasisModelSerializer):
    user = PublicUserSerializer()

    class Meta:
        model = Registration
        fields = ("id", "user", "pool", "status")
        read_only = True
Exemple #8
0
class CommentSerializer(BasisModelSerializer):
    author = PublicUserSerializer(read_only=True, source='created_by')
    created_at = DateTimeField(read_only=True)
    updated_at = DateTimeField(read_only=True)
    comment_target = GenericRelationField(source='content_object')
    text = ContentSerializerField()

    class Meta:
        model = Comment
        fields = ('id', 'text', 'author', 'comment_target', 'created_at', 'updated_at', 'parent')

    def validate(self, attrs):
        comment_target = attrs.get('content_object')

        if comment_target and 'parent' in attrs:
            parent = attrs['parent']
            if parent.object_id != comment_target.id or parent.content_type != \
                    ContentType.objects.get_for_model(comment_target):
                raise ValidationError(
                    {
                        'parent': 'parent does not point to the same comment_target'
                    }
                )

        return attrs
Exemple #9
0
class GroupedReactionSerializer(serializers.Serializer):
    count = serializers.IntegerField()
    type = serializers.CharField()
    users = PublicUserSerializer(many=True)

    class Meta:
        fields = ('count', 'type', 'users')
Exemple #10
0
class SubmissionReadSerializer(BasisModelSerializer):
    answers = AnswerSerializer(many=True)
    user = PublicUserSerializer()

    class Meta:
        model = Submission
        fields = ("id", "user", "survey", "answers")
Exemple #11
0
class SubmissionReadSerializer(BasisModelSerializer):
    answers = AnswerSerializer(many=True)
    user = PublicUserSerializer()

    class Meta:
        model = Submission
        fields = ('id', 'user', 'survey', 'answers')
Exemple #12
0
class DetailedArticleSerializer(TagSerializerMixin, BasisModelSerializer):
    author = PublicUserSerializer(read_only=True, source="created_by")
    comments = CommentSerializer(read_only=True, many=True)
    cover = ImageField(required=False, options={"height": 500})
    content_target = CharField(read_only=True)
    content = ContentSerializerField(source="text")
    reactions_grouped = serializers.SerializerMethodField()

    def get_reactions_grouped(self, obj):
        user = self.context["request"].user
        return obj.get_reactions_grouped(user)

    class Meta:
        model = Article
        fields = (
            "id",
            "title",
            "cover",
            "author",
            "description",
            "comments",
            "content_target",
            "tags",
            "content",
            "created_at",
            "pinned",
            "reactions_grouped",
            "youtube_url",
        )
Exemple #13
0
class EventReadDetailedSerializer(TagSerializerMixin, BasisModelSerializer):
    comments = CommentSerializer(read_only=True, many=True)
    content_target = CharField(read_only=True)
    cover = ImageField(required=False, options={"height": 500})
    company = CompanyField(queryset=Company.objects.all())
    responsible_group = AbakusGroupField(queryset=AbakusGroup.objects.all(),
                                         required=False,
                                         allow_null=True)
    pools = PoolReadSerializer(many=True)
    active_capacity = serializers.ReadOnlyField()
    text = ContentSerializerField()
    created_by = PublicUserSerializer()

    registration_close_time = serializers.DateTimeField(read_only=True)

    class Meta:
        model = Event
        fields = (
            "id",
            "title",
            "description",
            "cover",
            "text",
            "event_type",
            "event_status_type",
            "location",
            "comments",
            "content_target",
            "start_time",
            "end_time",
            "merge_time",
            "pools",
            "registration_close_time",
            "registration_deadline_hours",
            "unregistration_deadline",
            "company",
            "responsible_group",
            "active_capacity",
            "feedback_description",
            "feedback_required",
            "is_priced",
            "price_member",
            "price_guest",
            "use_stripe",
            "payment_due_date",
            "use_captcha",
            "waiting_registration_count",
            "tags",
            "is_merged",
            "heed_penalties",
            "created_by",
            "is_abakom_only",
            "registration_count",
            "survey",
            "use_consent",
            "youtube_url",
        )
        read_only = True
Exemple #14
0
class ReactionSerializer(BasisModelSerializer):
    created_by = PublicUserSerializer(read_only=True)
    target = GenericRelationField(source='content_object')

    # type = ReactionTypeSerializer(read_only=True)

    class Meta:
        model = Reaction
        fields = ('id', 'type', 'created_by', 'target')
Exemple #15
0
class ReactionSerializer(BasisModelSerializer):
    created_by = PublicUserSerializer(read_only=True)
    target = GenericRelationField(source="content_object")

    # type = ReactionTypeSerializer(read_only=True)

    class Meta:
        model = Reaction
        fields = ("id", "type", "created_by", "target")
Exemple #16
0
class PublicArticleSerializer(TagSerializerMixin, BasisModelSerializer):

    cover = ImageField(required=False, options={'height': 300})
    author = PublicUserSerializer(read_only=True, source='created_by')

    class Meta:
        model = Article
        fields = ('id', 'title', 'cover', 'author', 'description', 'tags',
                  'created_at', 'pinned')
Exemple #17
0
class DetailedArticleSerializer(TagSerializerMixin, BasisModelSerializer):
    author = PublicUserSerializer(read_only=True, source='created_by')
    comments = CommentSerializer(read_only=True, many=True)
    cover = ImageField(required=False, options={'height': 500})
    comment_target = CharField(read_only=True)
    content = ContentSerializerField(source='text')

    class Meta:
        model = Article
        fields = ('id', 'title', 'cover', 'author', 'description', 'comments',
                  'comment_target', 'tags', 'content', 'created_at', 'pinned')
Exemple #18
0
class AnnouncementListSerializer(BasisModelSerializer):

    users = PublicUserSerializer(many=True, read_only=True)
    groups = PublicAbakusGroupSerializer(many=True, read_only=True)
    events = EventReadSerializer(many=True, read_only=True)
    meetings = MeetingDetailSerializer(many=True, read_only=True)

    class Meta:
        model = Announcement
        fields = ("id", "message", "sent", "users", "groups", "events",
                  "meetings")
        read_only_fields = ("sent", )
Exemple #19
0
class MeetingInvitationSerializer(BasisModelSerializer):
    user = PublicUserSerializer()
    status = serializers.ChoiceField(choices=(constants.ATTENDING,
                                              constants.NOT_ATTENDING))

    class Meta:
        model = MeetingInvitation
        fields = ('user', 'status', 'meeting')

    def create(self, validated_data):
        meeting = Meeting.objects.get(
            id=self.context['view'].kwargs['meeting_pk'])
        meeting_invitation = MeetingInvitation.objects.create(meeting=meeting,
                                                              **validated_data)
        return meeting_invitation
Exemple #20
0
class PublicArticleSerializer(TagSerializerMixin, BasisModelSerializer):

    cover = ImageField(required=False, options={"height": 300})
    author = PublicUserSerializer(read_only=True, source="created_by")

    class Meta:
        model = Article
        fields = (
            "id",
            "title",
            "cover",
            "author",
            "description",
            "tags",
            "created_at",
            "pinned",
        )
Exemple #21
0
class AnnouncementListSerializer(BasisModelSerializer):

    users = PublicUserSerializer(many=True, read_only=True)
    groups = PublicAbakusGroupSerializer(many=True, read_only=True)
    events = EventReadSerializer(many=True, read_only=True)
    meetings = MeetingDetailSerializer(many=True, read_only=True)

    class Meta:
        model = Announcement
        fields = (
            'id',
            'message',
            'sent',
            'users',
            'groups',
            'events',
            'meetings',
        )
        read_only_fields = ('sent', )
Exemple #22
0
class DetailedArticleSerializer(TagSerializerMixin, BasisModelSerializer):
    author = PublicUserSerializer(read_only=True, source="created_by")
    comments = CommentSerializer(read_only=True, many=True)
    cover = ImageField(required=False, options={"height": 500})
    comment_target = CharField(read_only=True)
    content = ContentSerializerField(source="text")

    class Meta:
        model = Article
        fields = (
            "id",
            "title",
            "cover",
            "author",
            "description",
            "comments",
            "comment_target",
            "tags",
            "content",
            "created_at",
            "pinned",
        )
Exemple #23
0
    def to_representation(self, value):
        from lego.apps.users.serializers.users import PublicUserSerializer

        serializer = PublicUserSerializer(instance=value)
        return serializer.data