class GalleryPictureSerializer(serializers.ModelSerializer): file = ImageField(required=True, options={'height': 700, 'smart': True}) thumbnail = ImageField(source='file', read_only=True, options={ 'height': 200, 'width': 300, 'smart': True }) raw_file = FileField(source='file', read_only=True) comments = CommentSerializer(read_only=True, many=True) comment_target = CharField(read_only=True) taggees = PublicUserField(many=True, queryset=User.objects.all(), required=False) class Meta: model = GalleryPicture fields = ('id', 'gallery', 'description', 'taggees', 'active', 'file', 'thumbnail', 'raw_file', 'comments', 'comment_target') read_only_fields = ('raw_file', 'thumbnail', 'gallery') def validate(self, attrs): gallery = Gallery.objects.get( pk=self.context['view'].kwargs['gallery_pk']) return {'gallery': gallery, **attrs}
class CompanyAdminDetailSerializer(BasisModelSerializer): comments = CommentSerializer(read_only=True, many=True) content_target = CharField(read_only=True) student_contact = PublicUserField(required=False, allow_null=True, queryset=User.objects.all()) semester_statuses = SemesterStatusDetailSerializer(many=True, read_only=True) company_contacts = CompanyContactSerializer(many=True, read_only=True) logo = ImageField(required=False, options={"height": 500}) files = CompanyFileSerializer(many=True, read_only=True) class Meta: model = Company fields = ( "id", "name", "student_contact", "description", "phone", "company_type", "website", "address", "payment_mail", "comments", "content_target", "semester_statuses", "active", "admin_comment", "logo", "files", "company_contacts", )
class DetailedPollSerializer(TagSerializerMixin, BasisModelSerializer): comments = CommentSerializer(read_only=True, many=True) comment_target = CharField(read_only=True) options = OptionSerializer(many=True) total_votes = IntegerField(read_only=True) has_answered = serializers.SerializerMethodField() def get_has_answered(self, obj): user = self.context["request"].user return obj.get_has_answered(user) class Meta: model = Poll fields = ( "id", "created_at", "valid_until", "title", "description", "options", "total_votes", "comments", "comment_target", "tags", "has_answered", "pinned", )
class GalleryPictureSerializer(serializers.ModelSerializer): file = ImageField(required=True, options={"height": 700, "smart": True}) thumbnail = ImageField( source="file", read_only=True, options={"height": 200, "width": 300, "smart": True}, ) raw_file = FileField(source="file", read_only=True) comments = CommentSerializer(read_only=True, many=True) content_target = CharField(read_only=True) taggees = PublicUserField(many=True, queryset=User.objects.all(), required=False) class Meta: model = GalleryPicture fields = ( "id", "gallery", "description", "taggees", "active", "file", "thumbnail", "raw_file", "comments", "content_target", ) read_only_fields = ("raw_file", "thumbnail", "gallery") def validate(self, attrs): gallery = Gallery.objects.get(pk=self.context["view"].kwargs["gallery_pk"]) return {"gallery": gallery, **attrs}
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
class MeetingDetailSerializer(BasisModelSerializer): invitations = MeetingInvitationSerializer(many=True, read_only=True) report = ContentSerializerField() report_author = PublicUserField(queryset=User.objects.all(), allow_null=True, required=False) created_by = PublicUserField(read_only=True) comments = CommentSerializer(read_only=True, many=True) content_target = CharField(read_only=True) class Meta: model = Meeting fields = ( "id", "created_by", "title", "location", "start_time", "end_time", "report", "report_author", "invitations", "comments", "content_target", ) read_only = True def create(self, validated_data): meeting = Meeting.objects.create(**validated_data) owner = validated_data["current_user"] meeting.invite_user(owner, owner) return meeting
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", )
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
class QuoteSerializer(TagSerializerMixin, BasisModelSerializer): comments = CommentSerializer(read_only=True, many=True) comment_target = CharField(read_only=True) text = ContentSerializerField() class Meta: model = Quote fields = ('id', 'created_at', 'text', 'source', 'approved', 'tags', 'comments', 'comment_target')
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')
class QuoteSerializer(TagSerializerMixin, BasisModelSerializer): comments = CommentSerializer(read_only=True, many=True) comment_target = CharField(read_only=True) text = ContentSerializerField() class Meta: model = Quote fields = ( "id", "created_at", "text", "source", "approved", "tags", "comments", "comment_target", )
class CompanyAdminDetailSerializer(BasisModelSerializer): comments = CommentSerializer(read_only=True, many=True) comment_target = CharField(read_only=True) student_contact = PublicUserField(required=False, allow_null=True, queryset=User.objects.all()) semester_statuses = SemesterStatusDetailSerializer(many=True, read_only=True) company_contacts = CompanyContactSerializer(many=True, read_only=True) logo = ImageField(required=False, options={'height': 500}) files = CompanyFileSerializer(many=True, read_only=True) class Meta: model = Company fields = ('id', 'name', 'student_contact', 'description', 'phone', 'company_type', 'website', 'address', 'payment_mail', 'comments', 'comment_target', 'semester_statuses', 'active', 'admin_comment', 'logo', 'files', 'company_contacts')
class MeetingDetailSerializer(BasisModelSerializer): invitations = MeetingInvitationSerializer(many=True, read_only=True) report = ContentSerializerField() report_author = PublicUserField(queryset=User.objects.all(), allow_null=True, required=False) created_by = PublicUserField(read_only=True) comments = CommentSerializer(read_only=True, many=True) comment_target = CharField(read_only=True) class Meta: model = Meeting fields = ('id', 'created_by', 'title', 'location', 'start_time', 'end_time', 'report', 'report_author', 'invitations', 'comments', 'comment_target') read_only = True def create(self, validated_data): meeting = Meeting.objects.create(**validated_data) owner = validated_data['current_user'] meeting.invite_user(owner, owner) return meeting
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", )