forked from apluslms/a-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
30 lines (24 loc) · 963 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from tastypie.resources import ModelResource
from api.permissions import SuperuserAuthorization
from userprofile.models import UserProfile
class UserProfileResource(ModelResource):
def dehydrate(self, bundle):
"""
This method adds fields from the corresponding User
object to the response.
"""
user = bundle.obj.user
extra_fields = {"username": user.username,
"first_name": user.first_name,
"last_name": user.last_name,
"email": user.email,
}
bundle.data.update(extra_fields)
return bundle
class Meta:
queryset = UserProfile.objects.all()
resource_name = 'userprofile'
# In this version of the API only superusers are allowed to access
# userprofile objects
allowed_methods = ['get']
authorization = SuperuserAuthorization()