def __init__(self, **kwargs): """ Initialize the class. :param kwargs: The keyword arguments to pass on :type kwargs: any """ Field.__init__(self, **kwargs, read_only=True)
class NetworkHostResource(ModelSerializer): class Meta: model = NetworkHost fields = ('mac_address', 'ip_address', 'first_connection', 'online', 'vendor', 'is_console') ordering = ('mac_address') vendor = Field(source='vendor') is_console = Field(source='is_console')
class LocationTypeSimpleSerializer(serializers.MongoEngineModelSerializer): id = serializers.fields.CharField(read_only=True) group = Field(source="group") # just make is serialize like everybody else description = Field(source="long_description") class Meta: model = LocationType fields = ('id', 'name', 'group', 'description', 'last_updated', 'icon')
class BasePodcastSerializer(ModelSerializer): slug = Field() num_episodes = Field() cover = CoverSerializer() class Meta: model = Podcast fields = ('id', 'slug', 'creator', 'title', 'description', 'url', 'stream', 'chat', 'cover', 'type', 'deleted', 'approved', 'create_date', 'num_episodes', 'episodes')
class ImporterLogSerializer(ModelSerializer): sources = ImporterDatasourceLogSerializer(many=True) runtime = Field() succeeded = Field() class Meta: fields = ('starttime', 'endtime', 'runtime', 'succeeded', 'sources') model = ImporterLog depth = 3
class EventAttendanceResource(ModelSerializer): """ Event attendance object. """ reset_count = Field(source='reset_count') quota_remaining = Field(source='quota_remaining') class Meta: model = EventAttendance fields = ('quota_amount', 'reset_count', 'quota_unmetered', 'quota_used', 'quota_remaining')
class PermissiveUserProfileResource(UserProfileResource): """ Permissive version of UserProfileResource, which provides the user's real name. """ first_name = Field(source='first_name') last_name = Field(source='last_name') class Meta(UserProfileResource.Meta): fields = UserProfileResource.Meta.fields + [ 'first_name', 'last_name', ]
class UserProfileResource(ModelSerializer): """ Restricted UserProfile resource, which doesn't provide the user's real name. """ username = Field(source='username') user_id = Field(source='user_id') class Meta: model = UserProfile fields = [ 'internet_on', 'user_id', 'username', ]
class LocationSimpleSerializer(serializers.MongoEngineModelSerializer): id = serializers.fields.CharField(read_only=True) group = Field(source="group") class Meta: model = Location fields = ('id', 'name', 'group')
class ImporterJobLogSerializer(ModelSerializer): runtime = Field() class Meta: fields = ('starttime', 'endtime', 'runtime', 'name', 'succeeded', 'error', 'created', 'deleted', 'skipped', 'updated') model = ImporterJobLog
class DocumentSerializer(ModelSerializer): episode = SubEpisodeSerializer() meta = DocumentMetaSerializer() urlname = Field() class Meta: model = Document fields = ('name', 'editor', 'create_date', 'episode', 'meta', 'urlname')
class LocationTypeSerializer(serializers.MongoEngineModelSerializer): id = serializers.fields.CharField(read_only=True) location_count = Field(source="location_count") class Meta: model = LocationType fields = ('id', 'name', 'allow_media', 'allow_galleries', 'allow_forms', 'allow_categories', 'created', 'last_updated', 'view_privacy', 'taxonomies', 'icon', 'location_count', 'desc', 'custom_field_form')
class BaseDatasetSerializer(ModelSerializer): time = TimeField() resource = ResourceField(required=False) policy_domains = SlugRelatedField(many=True, slug_field='domain', source='domains') spatials = SlugRelatedField(required=False, many=True, slug_field='spatial', source='dataset_spatials') creator_path = Field(source='creator_path') def to_native(self, obj): """ Deserializes the Django model object """ if obj is None: return super(BaseDatasetSerializer, self).to_native(obj) dataset = super(BaseDatasetSerializer, self).to_native(obj) result = SortedDictWithMetadata() # Set the self attribute. result['self'] = reverse('dataset-detail', args=[obj.pk]) result.update(dataset) return result def validate(self, attrs): return attrs def restore_object(self, attrs, instance=None): return super(BaseDatasetSerializer, self).restore_object(attrs, instance) class Meta: exclude = ('time_resolution', 'time_start', 'time_end', 'resource_url', 'resource_id', 'resource_issued', 'resource_publisher', 'data') fields = () model = Dataset
def __init__(self, values, *args, **kwargs): self.values = values Field.__init__(self, *args, **kwargs)
class ShippingItemSerializer(ModelSerializer): item = Field(source="item.item_number") class Meta: model = ShippingItem