Ejemplo n.º 1
0
 def to_representation(self, obj):
     if obj.app is None:
         e = ExtensionSerializer(context=self.context)
         data = e.to_representation(obj.extension)
         data['latecustomization_id'] = obj.pk
         data['latecustomization_type'] = 'extension'
     else:
         a = SimpleAppSerializer(context=self.context)
         data = a.to_representation(obj.app)
         data['latecustomization_id'] = obj.pk
         data['latecustomization_type'] = 'webapp'
     return data
Ejemplo n.º 2
0
 def test_to_native(self):
     self.app2 = amo.tests.app_factory()
     self.collection.add_app(self.app2)
     apps = [self.app, self.app2]
     request = self.get_request({})
     resource = SimpleAppSerializer(apps)
     resource.context = {'request': request}
     self.field.context['request'] = request
     data = self.field.to_native(self.collection.apps())
     eq_(len(data), 2)
     eq_(data[0]['id'], int(self.app.pk))
     eq_(data[0]['resource_uri'], self.app.get_api_url(pk=self.app.pk))
     eq_(data[1]['id'], int(self.app2.id))
     eq_(data[1]['resource_uri'], self.app2.get_api_url(pk=self.app2.pk))
Ejemplo n.º 3
0
 def test_to_native(self):
     self.app2 = amo.tests.app_factory()
     self.collection.add_app(self.app2)
     apps = [self.app, self.app2]
     request = self.get_request({})
     resource = SimpleAppSerializer(apps)
     resource.context = {"request": request}
     self.field.context["request"] = request
     data = self.field.to_native(self.collection.apps())
     eq_(len(data), 2)
     eq_(data[0]["id"], int(self.app.pk))
     eq_(data[0]["resource_uri"], self.app.get_api_url(pk=self.app.pk))
     eq_(data[1]["id"], int(self.app2.id))
     eq_(data[1]["resource_uri"], self.app2.get_api_url(pk=self.app2.pk))
Ejemplo n.º 4
0
class AppAbuseSerializer(BaseAbuseSerializer):
    app = SplitField(
        SlugOrPrimaryKeyRelatedField(source='addon', slug_field='app_slug',
                                     queryset=Webapp.objects.all()),
        SimpleAppSerializer(source='addon'))

    class Meta(BaseAbuseSerializer.Meta):
        fields = BaseAbuseSerializer.Meta.fields + ('app',)
Ejemplo n.º 5
0
class AppAbuseSerializer(BaseAbuseSerializer):
    app = SplitField(
        SlugOrPrimaryKeyRelatedField(source='addon',
                                     slug_field='app_slug',
                                     queryset=Webapp.objects.all()),
        SimpleAppSerializer(source='addon'))

    class Meta:
        model = AbuseReport
        fields = ('text', 'ip_address', 'reporter', 'app')
Ejemplo n.º 6
0
 def simple_app(self):
     return SimpleAppSerializer(self.webapp,
                                context={'request': self.request})