Skip to content

Commit 06a9318

Browse files
committed
Add SiteResource and GroupResource; Show players for a team
1 parent 497e439 commit 06a9318

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Diff for: api.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class Meta:
5555
authentication = Authentication()
5656
authorization = Authorization()
5757

58+
def dehydrate(self, bundle):
59+
bundle.data['display_name'] = str(bundle.obj)
60+
return bundle
61+
5862

5963
class ClubResource(ModelResource):
6064
district = fields.ForeignKey(DistrictResource, 'district', full=True)
@@ -68,7 +72,7 @@ class Meta:
6872
authorization = Authorization()
6973
authentication = Authentication()
7074
filtering = {
71-
'union': ALL_WITH_RELATIONS
75+
'district': ALL_WITH_RELATIONS
7276
}
7377

7478
def obj_create(self, bundle, request=None, **kwargs):
@@ -92,6 +96,9 @@ class Meta:
9296
allowed_methods = ['get', 'post', 'put']
9397
authorization = Authorization()
9498
authentication = Authentication()
99+
filtering = {
100+
'club': ALL_WITH_RELATIONS
101+
}
95102

96103
def obj_create(self, bundle, request=None, **kwargs):
97104
# The user to create a team becomes its first manager (for lack of other people)
@@ -100,6 +107,12 @@ def obj_create(self, bundle, request=None, **kwargs):
100107

101108
def dehydrate(self, bundle):
102109
bundle.data['display_name'] = str(bundle.obj)
110+
111+
bundle.data['players'] = []
112+
resource = PersonResource()
113+
for membership in TeamPlayerRelation.objects.filter(player=bundle.obj, manager_confirmed=True):
114+
playerBundle = resource.build_bundle(obj=membership.player, request=bundle.request)
115+
bundle.data['players'].append(resource.full_dehydrate(playerBundle))
103116
return bundle
104117

105118

@@ -212,6 +225,26 @@ class Meta:
212225
authentication = Authentication()
213226
always_return_data = True
214227

228+
229+
class SiteResource(ModelResource):
230+
class Meta:
231+
queryset = Site.objects.all()
232+
authorization = Authorization()
233+
authentication = Authentication()
234+
always_return_data = True
235+
236+
def dehydrate(self, bundle):
237+
bundle.data['display_name'] = str(bundle.obj)
238+
return bundle
239+
240+
241+
class GroupResource(ModelResource):
242+
class Meta:
243+
queryset = Group.objects.all()
244+
authorization = Authorization()
245+
authentication = Authentication()
246+
247+
215248
"""
216249
Non-resource api endpoints
217250
"""

Diff for: urls.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
v1_api.register(LeagueResource())
1313
v1_api.register(DistrictResource())
1414
v1_api.register(ClubMemberRelationResource())
15+
v1_api.register(SiteResource())
16+
v1_api.register(GameTypeResource())
17+
v1_api.register(GroupResource())
1518

1619
urlpatterns = patterns('handball.views',
1720
(r'^$', 'index')

0 commit comments

Comments
 (0)