Skip to content

Instantly share code, notes, and snippets.

@dbtsai
Created July 2, 2012 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbtsai/3031004 to your computer and use it in GitHub Desktop.
Save dbtsai/3031004 to your computer and use it in GitHub Desktop.
class UserResource(DuJourModelResource):
profile_image_thumbnail = fields.OneToOneField('website.api.v1.media_resources.ImageResource', 'profile_image_thumbnail',full=True, null=True)
profile_image_standard = fields.OneToOneField('website.api.v1.media_resources.ImageResource', 'profile_image_standard', full=True, null=True)
created_time = fields.DateTimeField(attribute='created_time', readonly=True, default=now)
updated_time = fields.DateTimeField(attribute='updated_time', readonly=True, default=now)
age = fields.IntegerField(attribute='age')
class Meta:
serializer = TzSerializer()
always_return_data = True
authorization= Authorization()
#cache = SimpleCache()
#cache_control = [public,{ "max_age": 60*10}]
detail_allowed_methods = ['get', 'post', 'patch']
detail_uri_name = 'uuid'
fields = ['username','about_me','fashion_statement','gender','first_name','last_name','middle_name','email','website','location']
filtering = { "community":ALL }
queryset = UserProfile.objects.filter(is_active=True)
list_allowed_methods = ['get','post']
include_resource_uri = True
resource_name = 'user'
def dehydrate(self, bundle):
#print bundle.request.META['REQUEST_METHOD']
# if not (bundle.data['profile_image_standard'] is None):# and (bundle.request.META['REQUEST_METHOD'] == 'GET'):
# import pdb; pdb.set_trace()
# profile_image_standard = bundle.data['profile_image_standard']
# print profile_image_standard.data['versions']
# del bundle.data['profile_image_standard']
bundle.data['profile_image_standard'] = bundle.data['profile_image_standard'].data['versions']
# else:
# del bundle.data['profile_image_standard']
# if not (bundle.data['profile_image_thumbnail'] is None):# and (bundle.request.META['REQUEST_METHOD'] == 'GET'):
# profile_image_thumbnail = bundle.data['profile_image_thumbnail']
# del bundle.data['profile_image_thumbnail']
# bundle.data['profile_image_thumbnail'] = profile_image_thumbnail.data['versions']
# else:
# del bundle.data['profile_image_thumbnail']
#bundle.data['profile_image_standard'] = bundle.obj.profile_image_standard
#import pdb; pdb.set_trace()
bundle.data['total_subscribers'] = bundle.obj.total_subscribers()
bundle.data['total_images'] = bundle.obj.total_images()
bundle.data['total_wordboxes'] = bundle.obj.total_wordboxes()
bundle.data['community'] = '/v1/community/?member=' + bundle.data['resource_uri']
return bundle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment