2012-05-11 02:08:46 +00:00
|
|
|
from tastypie.resources import ModelResource
|
|
|
|
|
from tastypie import fields
|
2012-07-06 20:01:33 +00:00
|
|
|
from tastypie.authentication import BasicAuthentication
|
|
|
|
|
from tastypie.authorization import DjangoAuthorization
|
|
|
|
|
|
|
|
|
|
from django.contrib.auth.models import User
|
2012-05-11 02:08:46 +00:00
|
|
|
|
|
|
|
|
from pinry.pins.models import Pin
|
|
|
|
|
|
|
|
|
|
|
2012-05-12 00:27:02 +00:00
|
|
|
class PinResource(ModelResource): # pylint: disable-msg=R0904
|
2012-05-11 02:08:46 +00:00
|
|
|
thumbnail = fields.CharField(readonly=True)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
queryset = Pin.objects.all()
|
|
|
|
|
resource_name = 'pin'
|
|
|
|
|
include_resource_uri = False
|
|
|
|
|
|
|
|
|
|
def dehydrate_thumbnail(self, bundle):
|
2012-05-12 00:27:02 +00:00
|
|
|
pin = Pin.objects.only('image').get(pk=bundle.data['id'])
|
|
|
|
|
return pin.image.url_200x1000
|
2012-07-06 20:01:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserResource(ModelResource):
|
|
|
|
|
class Meta:
|
|
|
|
|
queryset = User.objects.all()
|
|
|
|
|
resource_name = 'auth/user'
|
|
|
|
|
excludes = ['email', 'password', 'is_superuser']
|
|
|
|
|
# Add it here.
|
|
|
|
|
authentication = BasicAuthentication()
|
|
|
|
|
authorization = DjangoAuthorization()
|