from rest_framework.serializers import ModelSerializer

from ..mapdata.models import Level, Package, Source


class BoundsMixin:
    def to_representation(self, obj):
        result = super().to_representation(obj)
        if obj.bottom is not None:
            result['bounds'] = ((obj.bottom, obj.left), (obj.top, obj.right))
        return result


class LevelSerializer(ModelSerializer):
    class Meta:
        model = Level
        fields = ('name', 'altitude', 'package')


class PackageSerializer(BoundsMixin, ModelSerializer):
    class Meta:
        model = Package
        fields = ('name', 'depends')


class SourceSerializer(BoundsMixin, ModelSerializer):
    class Meta:
        model = Source
        fields = ('name', 'package')

@@ -1,12 +1,46 @@
+from django.conf import settings%0A%0A
 from rest_fr
@@ -135,16 +135,60 @@
  Source%0A
+from .permissions import can_access_package%0A
 %0A%0Aclass 
@@ -681,24 +681,315 @@
 'depends')%0A%0A
+    def to_representation(self, obj):%0A        result = super().to_representation(obj)%0A        result%5B'public'%5D = obj.name in settings.PUBLIC_PACKAGES%0A        if 'request' in self.context:%0A            result%5B'access'%5D = can_access_package(self.context%5B'request'%5D, obj)%0A        return result%0A%0A
 %0Aclass Sourc

add public and access to package serialization