Example #1
0
 def test_to_native(self):
     request = self.get_request({})
     resource = AppSerializer(self.app)
     resource.context = {'request': request}
     self.field.context['request'] = request
     native = self.field.to_native(self.collection.apps()[0])
     for key, value in native.iteritems():
         if key == 'resource_uri':
             eq_(value, self.app.get_api_url(pk=self.app.pk))
         else:
             eq_(value, resource.data[key])
Example #2
0
 def test_to_native(self):
     request = self.get_request({})
     resource = AppSerializer(self.app)
     resource.context = {'request': request}
     self.field.context['request'] = request
     native = self.field.to_native(self.membership)
     for key, value in native.iteritems():
         if key == 'resource_uri':
             eq_(value, self.app.get_api_url(pk=self.app.pk))
         else:
             eq_(value, resource.data[key])
Example #3
0
def dump_app(id, **kw):
    from mkt.webapps.api import AppSerializer
    # Because @robhudson told me to.
    # Note: not using storage because all these operations should be local.
    target_dir = os.path.join(settings.DUMPED_APPS_PATH, 'apps',
                              str(id / 1000))
    target_file = os.path.join(target_dir, str(id) + '.json')

    try:
        obj = Webapp.objects.get(pk=id)
    except Webapp.DoesNotExist:
        task_log.info(u'Webapp does not exist: {0}'.format(id))
        return

    req = RequestFactory().get('/')
    req.user = AnonymousUser()
    req.REGION = RESTOFWORLD

    if not os.path.exists(target_dir):
        os.makedirs(target_dir)

    task_log.info('Dumping app {0} to {1}'.format(id, target_file))
    res = AppSerializer(obj, context={'request': req}).data
    json.dump(res, open(target_file, 'w'), cls=JSONEncoder)
    return target_file
Example #4
0
 def serialize(self, app, profile=None, region=None, request=None):
     if request is None:
         request = self.request
     request.amo_user = self.profile
     request.REGION = region
     a = AppSerializer(instance=app, context={'request': request})
     return a.data
Example #5
0
 def serialize(self, app, profile=None):
     a = AppSerializer(instance=app,
                       context={
                           'request': self.request,
                           'profile': profile
                       })
     return a.data
Example #6
0
 def serialize(self, app, profile=None, region=None, request=None):
     a = AppSerializer(instance=app,
                       context={
                           'request': request or self.request,
                           'profile': profile,
                           'region': region
                       })
     return a.data
Example #7
0
class AppAbuseSerializer(BaseAbuseSerializer):
    app = SplitField(
        SlugOrPrimaryKeyRelatedField(source='addon',
                                     slug_field='app_slug',
                                     queryset=Webapp.objects.all()),
        AppSerializer(source='addon'))

    class Meta:
        model = AbuseReport
        fields = ('text', 'ip_address', 'reporter', 'app')
Example #8
0
class FeedAppSerializer(URLSerializerMixin, serializers.ModelSerializer):
    app = SplitField(relations.PrimaryKeyRelatedField(required=True),
                     AppSerializer())
    description = TranslationSerializerField(required=False)
    preview = SplitField(relations.PrimaryKeyRelatedField(required=False),
                         PreviewSerializer())
    pullquote_attribution = TranslationSerializerField(required=False)
    pullquote_rating = serializers.IntegerField(required=False)
    pullquote_text = TranslationSerializerField(required=False)

    class Meta:
        fields = ('app', 'description', 'id', 'preview',
                  'pullquote_attribution', 'pullquote_rating',
                  'pullquote_text', 'url')
        model = FeedApp
        url_basename = 'feedapp'
Example #9
0
class FeedAppSerializer(URLSerializerMixin, serializers.ModelSerializer):
    """Thin wrappers around apps w/ metadata related to its feature in feed."""
    app = SplitField(relations.PrimaryKeyRelatedField(required=True),
                     AppSerializer())
    description = TranslationSerializerField(required=False)
    image = CollectionImageField(source='*',
                                 view_name='feed-app-image-detail',
                                 format='png')
    preview = SplitField(relations.PrimaryKeyRelatedField(required=False),
                         PreviewSerializer())
    pullquote_attribution = TranslationSerializerField(required=False)
    pullquote_rating = serializers.IntegerField(required=False)
    pullquote_text = TranslationSerializerField(required=False)

    class Meta:
        fields = ('app', 'background_color', 'description', 'feedapp_type',
                  'id', 'image', 'preview', 'pullquote_attribution',
                  'pullquote_rating', 'pullquote_text', 'slug', 'url')
        model = FeedApp
        url_basename = 'feedapps'
Example #10
0
class AppAbuseSerializer(BaseAbuseSerializer):
    app = AppSerializer(source='addon')
    class Meta:
        model = AbuseReport
        fields = ('text', 'ip_address', 'reporter', 'app')
Example #11
0
 def serialize(self, app, profile=None):
     self.request.amo_user = profile
     a = AppSerializer(instance=app, context={'request': self.request})
     return a.data
Example #12
0
 def app(self):
     return AppSerializer(self.webapp, context={'request': self.request})
Example #13
0
 def to_native(self, value):
     return AppSerializer(value.app, context=self.context).data