# Path: db/campaigns/models.py
# class Parameter(vera.BaseParameter):
#     campaign = models.ForeignKey(Campaign, related_name='parameters')
#     description = models.TextField()
# 
#     # Inherited from vera's params.BaseParameter:
#     #   name = models.CharField()
#     #   slug = models.CharField()
#     #   is_numeric = models.BooleanField()
#     #   units = models.CharField()
# 
#     class Meta:
#         ordering = ['pk']
# 
# 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')


from rest_framework import serializers
from wq.db.rest.serializers import ModelSerializer
from wq.db.patterns import serializers as patterns
from vera.models import Site
from .models import Parameter, Report
from vera.results.serializers import ResultSerializer as VeraResultSerializer
from vera.series.serializers import ReportSerializer as VeraReportSerializer
    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 ResultSerializer(VeraResultSerializer):
    class Meta(VeraResultSerializer.Meta):
        type_filter = {
            'campaign_id': '{{campaign_id}}',
        }


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)

# Path: db/campaigns/models.py
# class Parameter(vera.BaseParameter):
#     campaign = models.ForeignKey(Campaign, related_name='parameters')
#     description = models.TextField()
# 
#     # Inherited from vera's params.BaseParameter:
#     #   name = models.CharField()
#     #   slug = models.CharField()
#     #   is_numeric = models.BooleanField()
#     #   units = models.CharField()
# 
#     class Meta:
#         ordering = ['pk']
# 
# 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
from rest_framework import serializers
from wq.db.rest.serializers import ModelSerializer
from wq.db.patterns import serializers as patterns
from vera.models import Site
from .models import Parameter, Report
from vera.results.serializers import ResultSerializer as VeraResultSerializer
from vera.series.serializers import ReportSerializer as VeraReportSerializer

    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 ResultSerializer(VeraResultSerializer):
    class Meta(VeraResultSerializer.Meta):
        type_filter = {
            'campaign_id': '{{campaign_id}}',
        }


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):