Ejemplo n.º 1
0
class MemberSerializer(serializers.ModelSerializer):
    semester = SemesterSerializer(read_only=True, required=False)
    seller = UserSimpleSerializer(read_only=True)
    last_edited_by = UserSimpleSerializer(read_only=True)

    class Meta:
        model = Member
        fields = ('id', 'name', 'email', 'date_joined', 'semester', 'lifetime',
                  'honorary', 'date_lifetime', 'uio_username', 'seller',
                  'comments', 'last_edited_by')
Ejemplo n.º 2
0
class VaretellingVareExpandedSerializer(serializers.ModelSerializer):
    class VaretellingRåvareSerializer(serializers.ModelSerializer):
        class Priser(serializers.ModelSerializer):
            class Meta:
                model = Råvarepris
                fields = ('pris', 'pant', 'dato', 'aktiv')
                depth = 1

        innkjopskonto = KontoSimpleSerializer()
        priser = Priser(many=True, read_only=True)

        class Meta:
            model = Råvare
            fields = (
                'id',
                'kategori',
                'navn',
                'mengde',
                'enhet',
                'mengde_svinn',
                'antall',
                'innkjopskonto',
                'status',
                'priser',
            )

    added_by = UserSimpleSerializer()
    raavare = VaretellingRåvareSerializer()

    class Meta:
        model = VaretellingVare
        fields = ('id', 'sted', 'antall', 'antallpant', 'kommentar', 'raavare',
                  'time_price', 'added_by', 'time_added')
Ejemplo n.º 3
0
class EventSerializer(serializers.ModelSerializer):
    start = EventMomentSerializer()
    end = EventMomentSerializer()
    organizer = UserSimpleSerializer()

    class Meta:
        model = Event
        depth = 1
        fields = ('id', 'start', 'end', 'is_allday', 'title', 'description',
                  'comment', 'link', 'is_published', 'is_public',
                  'is_external', 'in_escape', 'is_cancelled', 'organizer')
Ejemplo n.º 4
0
class WorkLogSerializer(serializers.ModelSerializer):
    wallet = VoucherWalletSerializer(read_only=True)
    date_worked = serializers.DateField(validators=[valid_date_worked])
    issuing_user = UserSimpleSerializer(read_only=True)
    can_edit = serializers.SerializerMethodField("_can_edit")
    can_delete = serializers.SerializerMethodField("_can_delete")

    def _can_edit(self, instance):
        return register_log_has_perm(self.context["request"], instance,
                                     "change")

    def _can_delete(self, instance):
        return register_log_has_perm(self.context["request"], instance,
                                     "delete")

    class Meta:
        model = WorkLog
        fields = (
            "id",
            "wallet",
            "date_issued",
            "date_worked",
            "work_group",
            "hours",
            "vouchers",
            "issuing_user",
            "comment",
            "can_edit",
            "can_delete",
        )
        read_only_fields = (
            "id",
            "wallet",
            "date_issued",
            "issuing_user",
        )

    def update(self, instance, validated_data):
        if ("hours" in validated_data
                and validated_data["hours"] != instance.hours
                and ("vouchers" not in validated_data
                     or validated_data["vouchers"] == instance.vouchers)):
            instance.vouchers = instance.calculate_vouchers(
                validated_data["hours"])
            validated_data.pop("vouchers", None)

        if "date_worked" in validated_data:
            date = validated_data["date_worked"]
            wallet = VoucherWallet.objects.get_or_create(
                user=instance.wallet.user,
                semester=get_semester_of_date(date))[0]
            instance.wallet = wallet

        return super().update(instance, validated_data)
Ejemplo n.º 5
0
class MemberSerializer(serializers.ModelSerializer):
    semester = SemesterSerializer(read_only=True, required=False)
    seller = UserSimpleSerializer(read_only=True)
    last_edited_by = UserSimpleSerializer(read_only=True)

    class Meta:
        model = Member
        fields = (
            "id",
            "name",
            "email",
            "date_joined",
            "semester",
            "lifetime",
            "honorary",
            "date_lifetime",
            "uio_username",
            "seller",
            "comments",
            "last_edited_by",
        )
Ejemplo n.º 6
0
class WorkLogSerializer(serializers.ModelSerializer):
    wallet = VoucherWalletSerializer(read_only=True)
    date_worked = serializers.DateField(validators=[valid_date_worked])
    issuing_user = UserSimpleSerializer(read_only=True)
    can_edit = serializers.SerializerMethodField('_can_edit')
    can_delete = serializers.SerializerMethodField('_can_delete')

    def _can_edit(self, instance):
        return register_log_has_perm(self.context['request'], instance,
                                     'change')

    def _can_delete(self, instance):
        return register_log_has_perm(self.context['request'], instance,
                                     'delete')

    class Meta:
        model = WorkLog
        fields = (
            'id',
            'wallet',
            'date_issued',
            'date_worked',
            'work_group',
            'hours',
            'vouchers',
            'issuing_user',
            'comment',
            'can_edit',
            'can_delete',
        )
        read_only_fields = (
            'id',
            'wallet',
            'date_issued',
            'issuing_user',
        )

    def update(self, instance, validated_data):
        if 'hours' in validated_data and validated_data['hours'] != instance.hours and \
                ('vouchers' not in validated_data or validated_data['vouchers'] == instance.vouchers):
            instance.vouchers = instance.calculate_vouchers(
                validated_data['hours'])
            validated_data.pop('vouchers', None)

        if 'date_worked' in validated_data:
            date = validated_data['date_worked']
            wallet = VoucherWallet.objects.get_or_create(
                user=instance.wallet.user,
                semester=get_semester_of_date(date))[0]
            instance.wallet = wallet

        return super().update(instance, validated_data)
Ejemplo n.º 7
0
class ManualDataUploadVerboseSerializer(ModelSerializer):

    user = UserSimpleSerializer(read_only=True)
    import_batch = ImportBatchSerializer(read_only=True)
    platform = PlatformSerializer(read_only=True)
    organization = OrganizationSerializer(read_only=True)
    report_type = ReportTypeSimpleSerializer(read_only=True)
    can_edit = BooleanField(read_only=True)

    class Meta:
        model = ManualDataUpload
        fields = ('pk', 'report_type', 'organization', 'platform', 'data_file',
                  'user', 'created', 'is_processed', 'log', 'import_batch',
                  'extra', 'can_edit', 'owner_level')
Ejemplo n.º 8
0
class VoucherWalletSerializer(WalletSerializer):
    user = UserSimpleSerializer()

    class Meta:
        model = VoucherWallet
        fields = (
            "id",
            "user",
            "semester",
            "cached_balance",
            "cached_hours",
            "cached_vouchers",
            "cached_vouchers_used",
            "is_valid",
        )
Ejemplo n.º 9
0
class VoucherWalletSerializer(WalletSerializer):
    user = UserSimpleSerializer()

    class Meta:
        model = VoucherWallet
        fields = (
            'id',
            'user',
            'semester',
            'cached_balance',
            'cached_hours',
            'cached_vouchers',
            'cached_vouchers_used',
            'is_valid',
        )
Ejemplo n.º 10
0
class VaretellingVareExpandedSerializer(serializers.ModelSerializer):
    class VaretellingRåvareSerializer(serializers.ModelSerializer):
        class Priser(serializers.ModelSerializer):
            class Meta:
                model = Råvarepris
                fields = ("antall", "pris", "pant", "dato", "aktiv")
                depth = 1

        innkjopskonto = KontoSimpleSerializer()
        priser = Priser(many=True, read_only=True)

        class Meta:
            model = Råvare
            fields = (
                "id",
                "kategori",
                "navn",
                "type",
                "mengde",
                "enhet",
                "mengde_svinn",
                "antall",
                "innkjopskonto",
                "status",
                "priser",
            )

    added_by = UserSimpleSerializer()
    raavare = VaretellingRåvareSerializer()

    class Meta:
        model = VaretellingVare
        fields = (
            "id",
            "sted",
            "antall",
            "antallpant",
            "kommentar",
            "raavare",
            "time_price",
            "added_by",
            "time_added",
        )
Ejemplo n.º 11
0
class RegisterLogSerializer(serializers.ModelSerializer):
    wallet = CoffeeWalletSerializer(read_only=True)
    issuing_user = UserSimpleSerializer(read_only=True)
    can_edit = serializers.SerializerMethodField("_can_edit")
    can_delete = serializers.SerializerMethodField("_can_delete")

    def _can_edit(self, instance):
        return register_log_has_perm(self.context["request"], instance,
                                     "change")

    def _can_delete(self, instance):
        return register_log_has_perm(self.context["request"], instance,
                                     "delete")

    class Meta:
        model = CoffeeRegisterLog
        fields = (
            "id",
            "wallet",
            "date_issued",
            "vouchers",
            "issuing_user",
            "comment",
            "can_edit",
            "can_delete",
        )
        read_only_fields = (
            "id",
            "wallet",
            "date_issued",
            "issuing_user",
        )

    def update(self, instance, validated_data):
        if ("vouchers" in validated_data
                or validated_data["vouchers"] != instance.vouchers):
            instance.vouchers = int(validated_data["vouchers"])
            validated_data.pop("vouchers", None)

        return super().update(instance, validated_data)
Ejemplo n.º 12
0
class RegisterLogSerializer(serializers.ModelSerializer):
    wallet = CoffeeWalletSerializer(read_only=True)
    issuing_user = UserSimpleSerializer(read_only=True)
    can_edit = serializers.SerializerMethodField('_can_edit')
    can_delete = serializers.SerializerMethodField('_can_delete')

    def _can_edit(self, instance):
        return register_log_has_perm(self.context['request'], instance,
                                     'change')

    def _can_delete(self, instance):
        return register_log_has_perm(self.context['request'], instance,
                                     'delete')

    class Meta:
        model = CoffeeRegisterLog
        fields = (
            'id',
            'wallet',
            'date_issued',
            'vouchers',
            'issuing_user',
            'comment',
            'can_edit',
            'can_delete',
        )
        read_only_fields = (
            'id',
            'wallet',
            'date_issued',
            'issuing_user',
        )

    def update(self, instance, validated_data):
        if 'vouchers' in validated_data or validated_data[
                'vouchers'] != instance.vouchers:
            instance.vouchers = int(validated_data['vouchers'])
            validated_data.pop('vouchers', None)

        return super().update(instance, validated_data)
Ejemplo n.º 13
0
class UseLogSerializer(serializers.ModelSerializer):
    issuing_user = UserSimpleSerializer(read_only=True)