# Path: db/campaigns/models.py
# class Campaign(NaturalKeyModel):
#     slug = models.SlugField()
#     name = models.CharField(max_length=255)
#     icon = models.ImageField(upload_to='campaigns')
#     description = models.TextField()
#     creator = models.ForeignKey("auth.User", null=True, blank=True)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         unique_together = ['slug']
# 
# class Event(vera.BaseEvent):
#     date = models.DateField()
#     campaign = models.ForeignKey(Campaign)
# 
#     # Inherited from vera's series.BaseEvent:
#     #   site = models.ForeignKey('vera.Site')
# 
#     def __str__(self):
#         return "%s Observation on %s" % (
#             self.campaign, self.date
#         )
# 
#     class Meta:
#         unique_together = ('campaign', 'site', 'date')
#         ordering = ('-date', 'campaign', 'site')
# 
# class Report(vera.BaseReport):
#     photo = models.ImageField(
#         null=True, blank=True, upload_to='reports'
#     )
# 
#     # Inherited from vera's series.BaseReport:
#     #   event = models.ForeignKey(Event)
#     #   entered = models.DateTimeField()
#     #   user = models.ForeignKey('auth.User')
#     #   status = models.ForeignKey('vera.ReportStatus')
# 
# Path: db/campaigns/serializers.py
# class CampaignSerializer(patterns.AttachedModelSerializer):
#     parameters = ParameterInlineSerializer(many=True, required=False)
#     icon = serializers.FileField(required=False)
# 
#     def to_internal_value(self, data):
#         data = data.copy()
#         if 'request' in self.context:
#             user = self.context['request'].user
#             if user.is_authenticated():
#                 data['creator_id'] = user.pk
#         return super(CampaignSerializer, self).to_internal_value(data)
# 
#     def to_representation(self, obj):
#         result = super(CampaignSerializer, self).to_representation(obj)
#         result.pop('creator', None)
#         return result
# 
# class ReportSerializer(VeraReportSerializer):
#     results = ResultSerializer(many=True)
# 
#     def to_representation(self, obj):
#         # FIXME: See https://github.com/wq/wq.db/issues/61
#         result = super(ReportSerializer, self).to_representation(obj)
#         if result.get('results', None):
#             return result
# 
#         campaign_id = (
#             'request' in self.context and
#             self.context['request'].GET.get('campaign_id', None)
#         )
#         if not campaign_id:
#             return result
# 
#         result['results'] = [
#             {
#                 '@index': i,
#                 'type': self.router.serialize(parameter),
#                 'type_label': str(parameter),
#                 'type_id': parameter.slug,
#             }
#             for i, parameter in enumerate(Parameter.objects.filter(
#                 campaign__slug=campaign_id
#             ))
#         ]
#         return result
# 
#     def to_internal_value(self, data):
#         # In vera, Site is usually managed as a separate table, but we want to create
#         # new sites on the fly for this demo.
#         if data.get('latitude', None) and data.get('longitude', None):
# 
#             lat = float(data['latitude'])
#             lng = float(data['longitude'])
#             site, is_new = Site.objects.get_or_create(
#                 name="%s, %s" % (round(lat, 3), round(lng, 3)),
#                 latitude=lat,
#                 longitude=lng,
#             )
# 
#             data = data.copy()
#             data['event[site][slug]'] = site.slug
# 
#         return super(ReportSerializer, self).to_internal_value(data)
# 
# class EventSerializer(ModelSerializer):
#     latitude = serializers.ReadOnlyField(source='site.latitude')
#     longitude = serializers.ReadOnlyField(source='site.longitude')
#     valid_reports = ModelSerializer.for_model(
#         Report, include_fields="__all__"
#     )(many=True)
#     photo = serializers.SerializerMethodField()
#     results = EventResultSerializer(many=True, source='eventresult_set')
# 
#     def get_photo(self, instance):
#         report = instance.valid_reports.exclude(photo='').first()
#         if report:
#             return report.photo.name
# 
# Path: db/campaigns/maps.py



from wq.db import rest
from .models import Campaign, Event, Report
from .serializers import (
    CampaignSerializer,
    ReportSerializer,
    EventSerializer,
)
from .maps import basemaps, index_map, event_map
from django.conf import settings
        if request.user.is_authenticated():
            return qs.filter(user=request.user)
        else:
            return qs.none()
    return qs


rest.router.register_model(
    Campaign,
    lookup='slug',
    serializer=CampaignSerializer,
    fields="__all__",
)

rest.router.register_serializer(Report, ReportSerializer)
rest.router.register_filter(Report, report_filter)
rest.router.update_config(
    Report,
    reversed=True,
    partial=True,
    map=[{
        'mode': 'edit',
        'layers': [],
    }],
    locate=True,
)

rest.router.register_serializer(Event, EventSerializer)
rest.router.register_filter(Event, no_json_filter)
rest.router.update_config(

# Path: db/campaigns/models.py
# class Campaign(NaturalKeyModel):
#     slug = models.SlugField()
#     name = models.CharField(max_length=255)
#     icon = models.ImageField(upload_to='campaigns')
#     description = models.TextField()
#     creator = models.ForeignKey("auth.User", null=True, blank=True)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         unique_together = ['slug']
# 
# class Event(vera.BaseEvent):
#     date = models.DateField()
#     campaign = models.ForeignKey(Campaign)
# 
#     # Inherited from vera's series.BaseEvent:
#     #   site = models.ForeignKey('vera.Site')
# 
#     def __str__(self):
#         return "%s Observation on %s" % (
#             self.campaign, self.date
#         )
# 
#     class Meta:
#         unique_together = ('campaign', 'site', 'date')
#         ordering = ('-date', 'campaign', 'site')
# 
# class Report(vera.BaseReport):
#     photo = models.ImageField(
#         null=True, blank=True, upload_to='reports'
#     )
# 
#     # Inherited from vera's series.BaseReport:
#     #   event = models.ForeignKey(Event)
#     #   entered = models.DateTimeField()
#     #   user = models.ForeignKey('auth.User')
#     #   status = models.ForeignKey('vera.ReportStatus')
# 
# Path: db/campaigns/serializers.py
# class CampaignSerializer(patterns.AttachedModelSerializer):
#     parameters = ParameterInlineSerializer(many=True, required=False)
#     icon = serializers.FileField(required=False)
# 
#     def to_internal_value(self, data):
#         data = data.copy()
#         if 'request' in self.context:
#             user = self.context['request'].user
#             if user.is_authenticated():
#                 data['creator_id'] = user.pk
#         return super(CampaignSerializer, self).to_internal_value(data)
# 
#     def to_representation(self, obj):
#         result = super(CampaignSerializer, self).to_representation(obj)
#         result.pop('creator', None)
#         return result
# 
# class ReportSerializer(VeraReportSerializer):
#     results = ResultSerializer(many=True)
# 
#     def to_representation(self, obj):
#         # FIXME: See https://github.com/wq/wq.db/issues/61
#         result = super(ReportSerializer, self).to_representation(obj)
#         if result.get('results', None):
#             return result
# 
#         campaign_id = (
#             'request' in self.context and
#             self.context['request'].GET.get('campaign_id', None)
#         )
#         if not campaign_id:
#             return result
# 
#         result['results'] = [
#             {
#                 '@index': i,
#                 'type': self.router.serialize(parameter),
#                 'type_label': str(parameter),
#                 'type_id': parameter.slug,
#             }
#             for i, parameter in enumerate(Parameter.objects.filter(
#                 campaign__slug=campaign_id
#             ))
#         ]
#         return result
# 
#     def to_internal_value(self, data):
#         # In vera, Site is usually managed as a separate table, but we want to create
#         # new sites on the fly for this demo.
#         if data.get('latitude', None) and data.get('longitude', None):
# 
#             lat = float(data['latitude'])
#             lng = float(data['longitude'])
#             site, is_new = Site.objects.get_or_create(
#                 name="%s, %s" % (round(lat, 3), round(lng, 3)),
#                 latitude=lat,
#                 longitude=lng,
#             )
# 
#             data = data.copy()
#             data['event[site][slug]'] = site.slug
# 
#         return super(ReportSerializer, self).to_internal_value(data)
# 
# class EventSerializer(ModelSerializer):
#     latitude = serializers.ReadOnlyField(source='site.latitude')
#     longitude = serializers.ReadOnlyField(source='site.longitude')
#     valid_reports = ModelSerializer.for_model(
#         Report, include_fields="__all__"
#     )(many=True)
#     photo = serializers.SerializerMethodField()
#     results = EventResultSerializer(many=True, source='eventresult_set')
# 
#     def get_photo(self, instance):
#         report = instance.valid_reports.exclude(photo='').first()
#         if report:
#             return report.photo.name
# 
# Path: db/campaigns/maps.py



# Path: db/campaigns/rest.py
from wq.db import rest
from .models import Campaign, Event, Report
from .serializers import (
    CampaignSerializer,
    ReportSerializer,
    EventSerializer,
)
from .maps import basemaps, index_map, event_map
from django.conf import settings

        if request.user.is_authenticated():
            return qs.filter(user=request.user)
        else:
            return qs.none()
    return qs


rest.router.register_model(
    Campaign,
    lookup='slug',
    serializer=CampaignSerializer,
    fields="__all__",
)

rest.router.register_serializer(Report, ReportSerializer)
rest.router.register_filter(Report, report_filter)
rest.router.update_config(
    Report,
    reversed=True,
    partial=True,
    map=[{
        'mode': 'edit',
        'layers': [],
    }],
    locate=True,
)

rest.router.register_serializer(Event, EventSerializer)
rest.router.register_filter(Event, no_json_filter)
rest.router.update_config(

    Event,