# Path: src/sa_api_v2/serializers.py
# class SimplePlaceSerializer (BasePlaceSerializer):
#     class Meta (BasePlaceSerializer.Meta):
#         read_only_fields = ('dataset',)
# 
# class SimpleSubmissionSerializer (BaseSubmissionSerializer):
#     class Meta (BaseSubmissionSerializer.Meta):
#         read_only_fields = ('dataset', 'place')
# 
# class SimpleDataSetSerializer (BaseDataSetSerializer, serializers.ModelSerializer):
#     keys = ApiKeySerializer(many=True, read_only=False)
#     origins = OriginSerializer(many=True, read_only=False)
#     groups = SimpleGroupSerializer(many=True, read_only=False)
#     permissions = DataSetPermissionSerializer(many=True, read_only=False)
# 
#     class Meta (BaseDataSetSerializer.Meta):
#         pass
# 
# Path: src/sa_api_v2/renderers.py
# class JSONPRenderer (JSONRenderer):
# class PaginatedCSVRenderer (CSVRenderer):
# class GeoJSONRenderer(JSONRenderer):
# class GeoJSONPRenderer(JSONPRenderer, GeoJSONRenderer):
# class NullJSONRenderer(JSONRenderer):
# class NullJSONPRenderer(JSONPRenderer, NullJSONRenderer):
#     def get_callback(self, renderer_context):
#     def render(self, data, accepted_media_type=None, renderer_context=None):
#     def render(self, data, media_type=None, renderer_context=None):
#     def render(self, data, media_type=None, renderer_context=None):
#     def get_feature(self, data):
#     def render(self, data, media_type=None, renderer_context=None):


import requests
import ujson as json
import logging
from celery import shared_task
from celery.result import AsyncResult
from django.db import transaction
from django.test.client import RequestFactory
from django.utils.timezone import now
from itertools import chain
from .models import DataSnapshotRequest, DataSnapshot, DataSet, User, Place, Submission
from .serializers import SimplePlaceSerializer, SimpleSubmissionSerializer, SimpleDataSetSerializer
from .renderers import CSVRenderer, JSONRenderer, GeoJSONRenderer
            # Construct the dataset from metadata
            metadata = data.get('metadata')
            if metadata:
                metadata.pop('id', None)
                metadata.pop('owner', None)
                serializer = SimpleDataSetSerializer(dataset, data=data.get('metadata'))
                assert serializer.is_valid, list_errors(serializer.errors)
                serializer.save()

            # Create a stub view object to use in serializer contexts.
            class Stub (object): pass
            view = Stub()
            view.request = Stub()
            view.request.META = {'HTTP_X_SHAREABOUTS_SILENT': 'True'}
            view.request.user = Stub()
            view.request.user.is_authenticated = lambda: False

            # Construct each place and submission individually
            for place_data in data.get('features'):
                place_data.pop('type', None)
                place_data.update(place_data.pop('properties', {}))

                place_data.pop('id', None)
                place_data.pop('dataset', None)
                place_data.pop('created_datetime', None)
                place_data.pop('updated_datetime', None)
                submission_sets_data = place_data.pop('submission_sets', {})
                submitter_data = place_data.pop('submitter', None)

                serializer_context = {'view': view, 'request': view.request}

# Path: src/sa_api_v2/serializers.py
# class SimplePlaceSerializer (BasePlaceSerializer):
#     class Meta (BasePlaceSerializer.Meta):
#         read_only_fields = ('dataset',)
# 
# class SimpleSubmissionSerializer (BaseSubmissionSerializer):
#     class Meta (BaseSubmissionSerializer.Meta):
#         read_only_fields = ('dataset', 'place')
# 
# class SimpleDataSetSerializer (BaseDataSetSerializer, serializers.ModelSerializer):
#     keys = ApiKeySerializer(many=True, read_only=False)
#     origins = OriginSerializer(many=True, read_only=False)
#     groups = SimpleGroupSerializer(many=True, read_only=False)
#     permissions = DataSetPermissionSerializer(many=True, read_only=False)
# 
#     class Meta (BaseDataSetSerializer.Meta):
#         pass
# 
# Path: src/sa_api_v2/renderers.py
# class JSONPRenderer (JSONRenderer):
# class PaginatedCSVRenderer (CSVRenderer):
# class GeoJSONRenderer(JSONRenderer):
# class GeoJSONPRenderer(JSONPRenderer, GeoJSONRenderer):
# class NullJSONRenderer(JSONRenderer):
# class NullJSONPRenderer(JSONPRenderer, NullJSONRenderer):
#     def get_callback(self, renderer_context):
#     def render(self, data, accepted_media_type=None, renderer_context=None):
#     def render(self, data, media_type=None, renderer_context=None):
#     def render(self, data, media_type=None, renderer_context=None):
#     def get_feature(self, data):
#     def render(self, data, media_type=None, renderer_context=None):


# Path: src/sa_api_v2/tasks.py
import requests
import ujson as json
import logging
from celery import shared_task
from celery.result import AsyncResult
from django.db import transaction
from django.test.client import RequestFactory
from django.utils.timezone import now
from itertools import chain
from .models import DataSnapshotRequest, DataSnapshot, DataSet, User, Place, Submission
from .serializers import SimplePlaceSerializer, SimpleSubmissionSerializer, SimpleDataSetSerializer
from .renderers import CSVRenderer, JSONRenderer, GeoJSONRenderer

            # Construct the dataset from metadata
            metadata = data.get('metadata')
            if metadata:
                metadata.pop('id', None)
                metadata.pop('owner', None)
                serializer = SimpleDataSetSerializer(dataset, data=data.get('metadata'))
                assert serializer.is_valid, list_errors(serializer.errors)
                serializer.save()

            # Create a stub view object to use in serializer contexts.
            class Stub (object): pass
            view = Stub()
            view.request = Stub()
            view.request.META = {'HTTP_X_SHAREABOUTS_SILENT': 'True'}
            view.request.user = Stub()
            view.request.user.is_authenticated = lambda: False

            # Construct each place and submission individually
            for place_data in data.get('features'):
                place_data.pop('type', None)
                place_data.update(place_data.pop('properties', {}))

                place_data.pop('id', None)
                place_data.pop('dataset', None)
                place_data.pop('created_datetime', None)
                place_data.pop('updated_datetime', None)
                submission_sets_data = place_data.pop('submission_sets', {})
                submitter_data = place_data.pop('submitter', None)

                serializer_context = {'view': view, 'request': view.request}

                serializer = SimplePlaceSerializer(data=place_data, context=serializer_context)