# Path: observations/filters.py
# class MeasurementFilter(django_filters.FilterSet):
#     from_date = django_filters.DateTimeFilter(
#         name='reference_timestamp', lookup_type='gte',
#         initial=date.today() - timedelta(days=365),
#         widget=DateTimeWidget(options={
#                 'format': 'yyyy/mm/dd',
#                 'autoclose': 'true',
#                 'showMeridian': 'true',
#                 'weekStart': 1,
#                 'endDate': date.today(),
#                 'todayBtn': 'true',
#                 'todayHighlight': 'true',
#                 'minView': 2,
#                 'startView': 3,
#                 'pickerPosition': 'bottom-left',
#             })
#     )
#     to_date = django_filters.DateTimeFilter(
#         name='reference_timestamp', lookup_type='lte',
#         initial=date.today(),
#         widget=DateTimeWidget(options={
#                 'format': 'yyyy/mm/dd',
#                 'autoclose': 'true',
#                 'showMeridian': 'true',
#                 'weekStart': 1,
#                 'endDate': date.today() + timedelta(days=1),
#                 'todayBtn': 'true',
#                 'todayHighlight': 'true',
#                 'minView': 2,
#                 'startView': 3,
#                 'pickerPosition': 'bottom-left',
#             })
#     )
#     parameter = django_filters.ModelMultipleChoiceFilter(
#         label='Parameters',
#         name='parameters__parameter', lookup_type='in',
#         queryset=Parameter.objects.all(),
#         widget=ChosenSelectMultiple,
#     )
# 
#     class Meta:
#         model = Measurement
#         fields = ['from_date', 'to_date']
# 
#     def __init__(self, *args, **kwargs):
#         super(MeasurementFilter, self).__init__(*args, **kwargs)
#         self.filters['parameter'].field.help_text = ""
# 
# Path: observations/models.py
# class Measurement(models.Model):
#     """A measurement at a point in space/time."""
#     created_timestamp = models.DateTimeField(auto_now_add=True)
#     reference_timestamp = models.DateTimeField(
#         verbose_name="Observation date/time",
#         null=True, blank=True,
#         help_text="When was the sample/measurement taken?"
#     )
#     location = models.PointField()
#     location_reference = models.CharField(
#         verbose_name="Location name",
#         max_length=200, null=True, blank=True,
#         help_text="A friendly/reference name for this site")
#     observations = hstore.DictionaryField(null=True, blank=True)
#     parameters = models.ManyToManyField(Test, through='TestValue')
# 
#     observer = models.EmailField(
#         verbose_name="Email address",
#         null=True, blank=True,
#         help_text="Your email address - don't worry, we won't share it with "
#         "anyone!")
#     source = models.ForeignKey(
#         'supplements.DataSource', null=True, blank=True,
#         help_text="If this data came from an historic source, what is it?"
#     )
# 
#     objects = models.GeoManager()
#     observations_manager = hstore.HStoreManager()
# 
#     class Meta:
#         ordering = ('-reference_timestamp',)
# 
#     def __unicode__(self):
#         return u"Observation at {0}".format(self.created_timestamp)
# 
#     def _observed_as_string(self):
#         """Returns a list of parameter names that were obeserved."""
#         return ", ".join([
#             test.parameter.name for test in self.parameters.all()])
# 
#     def get_timestamp(self):
#         """Return the most useful timestamp."""
#         return self.reference_timestamp or self.created_timestamp
# 
#     def get_location(self):
#         """Return a nice location name."""
#         return self.location_reference or "{0:0.2f}, {1:0.2f}".format(
#             self.location.x, self.location.y)
# 
# Path: observations/api/serializers.py
# class CompactMeasurementSerializer(geo_serializers.GeoFeatureModelSerializer):
#     class Meta:
#         model = Measurement
#         geo_field = 'location'
#         fields = ('id', 'location')
# 
# class MeasurementSerializer(geo_serializers.GeoFeatureModelSerializer):
#     observations = DictionaryField()
# 
#     class Meta:
#         model = Measurement
#         geo_field = 'location'
#         fields = (
#             'id', 'created_timestamp', 'reference_timestamp', 'location',
#             'location_reference', 'observations', 'source',
#         )
# 
# Path: utils/mapit.py
# def lookup_postcode(postcode):
# def geocode_postcode(postcode):


import requests
import json
from rest_framework import generics
from django.conf import settings
from django.http import HttpResponse
from observations.filters import MeasurementFilter
from observations.models import Measurement
from observations.api.serializers import (
    CompactMeasurementSerializer, MeasurementSerializer,
)
from utils import mapit





class MeasurementList(generics.ListAPIView):
    serializer_class = MeasurementSerializer
    filter_class = MeasurementFilter
    queryset = Measurement.observations_manager.all()

    def get_serializer_class(self):
        if self.request.is_ajax() or self.request.QUERY_PARAMS.get('compact'):
            return CompactMeasurementSerializer
        else:

# Path: observations/filters.py
# class MeasurementFilter(django_filters.FilterSet):
#     from_date = django_filters.DateTimeFilter(
#         name='reference_timestamp', lookup_type='gte',
#         initial=date.today() - timedelta(days=365),
#         widget=DateTimeWidget(options={
#                 'format': 'yyyy/mm/dd',
#                 'autoclose': 'true',
#                 'showMeridian': 'true',
#                 'weekStart': 1,
#                 'endDate': date.today(),
#                 'todayBtn': 'true',
#                 'todayHighlight': 'true',
#                 'minView': 2,
#                 'startView': 3,
#                 'pickerPosition': 'bottom-left',
#             })
#     )
#     to_date = django_filters.DateTimeFilter(
#         name='reference_timestamp', lookup_type='lte',
#         initial=date.today(),
#         widget=DateTimeWidget(options={
#                 'format': 'yyyy/mm/dd',
#                 'autoclose': 'true',
#                 'showMeridian': 'true',
#                 'weekStart': 1,
#                 'endDate': date.today() + timedelta(days=1),
#                 'todayBtn': 'true',
#                 'todayHighlight': 'true',
#                 'minView': 2,
#                 'startView': 3,
#                 'pickerPosition': 'bottom-left',
#             })
#     )
#     parameter = django_filters.ModelMultipleChoiceFilter(
#         label='Parameters',
#         name='parameters__parameter', lookup_type='in',
#         queryset=Parameter.objects.all(),
#         widget=ChosenSelectMultiple,
#     )
# 
#     class Meta:
#         model = Measurement
#         fields = ['from_date', 'to_date']
# 
#     def __init__(self, *args, **kwargs):
#         super(MeasurementFilter, self).__init__(*args, **kwargs)
#         self.filters['parameter'].field.help_text = ""
# 
# Path: observations/models.py
# class Measurement(models.Model):
#     """A measurement at a point in space/time."""
#     created_timestamp = models.DateTimeField(auto_now_add=True)
#     reference_timestamp = models.DateTimeField(
#         verbose_name="Observation date/time",
#         null=True, blank=True,
#         help_text="When was the sample/measurement taken?"
#     )
#     location = models.PointField()
#     location_reference = models.CharField(
#         verbose_name="Location name",
#         max_length=200, null=True, blank=True,
#         help_text="A friendly/reference name for this site")
#     observations = hstore.DictionaryField(null=True, blank=True)
#     parameters = models.ManyToManyField(Test, through='TestValue')
# 
#     observer = models.EmailField(
#         verbose_name="Email address",
#         null=True, blank=True,
#         help_text="Your email address - don't worry, we won't share it with "
#         "anyone!")
#     source = models.ForeignKey(
#         'supplements.DataSource', null=True, blank=True,
#         help_text="If this data came from an historic source, what is it?"
#     )
# 
#     objects = models.GeoManager()
#     observations_manager = hstore.HStoreManager()
# 
#     class Meta:
#         ordering = ('-reference_timestamp',)
# 
#     def __unicode__(self):
#         return u"Observation at {0}".format(self.created_timestamp)
# 
#     def _observed_as_string(self):
#         """Returns a list of parameter names that were obeserved."""
#         return ", ".join([
#             test.parameter.name for test in self.parameters.all()])
# 
#     def get_timestamp(self):
#         """Return the most useful timestamp."""
#         return self.reference_timestamp or self.created_timestamp
# 
#     def get_location(self):
#         """Return a nice location name."""
#         return self.location_reference or "{0:0.2f}, {1:0.2f}".format(
#             self.location.x, self.location.y)
# 
# Path: observations/api/serializers.py
# class CompactMeasurementSerializer(geo_serializers.GeoFeatureModelSerializer):
#     class Meta:
#         model = Measurement
#         geo_field = 'location'
#         fields = ('id', 'location')
# 
# class MeasurementSerializer(geo_serializers.GeoFeatureModelSerializer):
#     observations = DictionaryField()
# 
#     class Meta:
#         model = Measurement
#         geo_field = 'location'
#         fields = (
#             'id', 'created_timestamp', 'reference_timestamp', 'location',
#             'location_reference', 'observations', 'source',
#         )
# 
# Path: utils/mapit.py
# def lookup_postcode(postcode):
# def geocode_postcode(postcode):


# Path: observations/api/views.py
import requests
import json
from rest_framework import generics
from django.conf import settings
from django.http import HttpResponse
from observations.filters import MeasurementFilter
from observations.models import Measurement
from observations.api.serializers import (
    CompactMeasurementSerializer, MeasurementSerializer,
)
from utils import mapit






class MeasurementList(generics.ListAPIView):
    serializer_class = MeasurementSerializer
    filter_class = MeasurementFilter
    queryset = Measurement.observations_manager.all()

    def get_serializer_class(self):
        if self.request.is_ajax() or self.request.QUERY_PARAMS.get('compact'):
            return CompactMeasurementSerializer
        else:

            return MeasurementSerializer