Skip to content

Commit 6146d01

Browse files
committed
Add display_name to team and person; Turn off authentication for testing purposes
1 parent 5cbcb69 commit 6146d01

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

api.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Meta:
2525
queryset = Union.objects.all()
2626
allowed_methods = ['get', 'post', 'put', 'patch']
2727
authorization = Authorization()
28-
authentication = ApiKeyAuthentication()
28+
authentication = Authentication()
2929
filtering = {
3030
'name': ('exact')
3131
}
@@ -40,19 +40,19 @@ class LeagueResource(ModelResource):
4040
class Meta:
4141
queryset = League.objects.all()
4242
allowed_methods = ['get', 'post', 'put']
43-
authentication = ApiKeyAuthentication()
43+
authentication = Authentication()
4444
authorization = Authorization()
4545

4646

4747
class ClubResource(ModelResource):
48-
union = fields.ForeignKey(UnionResource, 'union')
48+
union = fields.ForeignKey(UnionResource, 'union', full=True)
4949
# teams = fields.ToManyField('handball.api.TeamResource', 'teams')
5050

5151
class Meta:
5252
queryset = Club.objects.all()
5353
allowed_methods = ['get', 'post', 'put']
5454
authorization = Authorization()
55-
authentication = ApiKeyAuthentication()
55+
authentication = Authentication()
5656
filtering = {
5757
'union': ALL_WITH_RELATIONS
5858
}
@@ -72,13 +72,17 @@ class Meta:
7272
queryset = Team.objects.all()
7373
allowed_methods = ['get', 'post', 'put']
7474
authorization = Authorization()
75-
authentication = ApiKeyAuthentication()
75+
authentication = Authentication()
7676

7777
def obj_create(self, bundle, request=None, **kwargs):
7878
# The user to create a team becomes its first manager (for lack of other people)
7979
bundle.data['managers'] = ['/api/v1/person/' + str(request.user.get_profile().id) + '/']
8080
return super(TeamResource, self).obj_create(bundle, request)
8181

82+
def dehydrate(self, bundle):
83+
bundle.data['display_name'] = str(bundle.obj)
84+
return bundle
85+
8286

8387
class UserResource(ModelResource):
8488
person = fields.OneToOneField('handball.api.PersonResource', 'person', full=True)
@@ -103,21 +107,25 @@ class Meta:
103107
'last_name': ['exact']
104108
}
105109

110+
def dehydrate(self, bundle):
111+
bundle.data['display_name'] = str(bundle.obj)
112+
return bundle
113+
106114

107115
class GameTypeResource(ModelResource):
108116
class Meta:
109117
queryset = GameType.objects.all()
110118
include_resource_uri = False
111119
authorization = Authorization()
112-
authentication = ApiKeyAuthentication()
120+
authentication = Authentication()
113121

114122

115123
class SiteResource(ModelResource):
116124
class Meta:
117125
queryset = Site.objects.all()
118126
include_resource_uri = False
119127
authorization = Authorization()
120-
authentication = ApiKeyAuthentication()
128+
authentication = Authentication()
121129

122130

123131
class GameResource(ModelResource):
@@ -137,7 +145,7 @@ class GameResource(ModelResource):
137145
class Meta:
138146
queryset = Game.objects.all()
139147
authorization = Authorization()
140-
authentication = ApiKeyAuthentication()
148+
authentication = Authentication()
141149

142150

143151
class EventTypeResource(ModelResource):
@@ -147,7 +155,7 @@ class Meta:
147155
queryset = EventType.objects.all()
148156
include_resource_uri = False
149157
authorization = Authorization()
150-
authentication = ApiKeyAuthentication()
158+
authentication = Authentication()
151159

152160

153161
class EventResource(ModelResource):

models.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class Person(models.Model):
1111
user = models.OneToOneField(User, blank=True)
12+
club = models.ForeignKey('Club', related_name='members', blank=True)
1213

1314
# Fields used for user activation after signup
1415
activation_key = models.CharField(max_length=40, blank=True)
@@ -39,7 +40,7 @@ class Team(models.Model):
3940
coaches = models.ManyToManyField('Person', blank=True, related_name='teams_coaching')
4041
league = models.ForeignKey('League', related_name='league')
4142
club = models.ForeignKey('Club', related_name='teams')
42-
managers = models.ManyToManyField('Person', blank=True)
43+
managers = models.ManyToManyField('Person', blank=True, related_name='teams_managed')
4344

4445
def __unicode__(self):
4546
return self.club.name + ' ' + self.name
@@ -49,7 +50,7 @@ class Club(models.Model):
4950
name = models.CharField(max_length=50)
5051

5152
union = models.ForeignKey('Union', related_name='clubs')
52-
managers = models.ManyToManyField('Person', blank=True)
53+
managers = models.ManyToManyField('Person', blank=True, related_name='clubs_managed')
5354

5455
def __unicode__(self):
5556
return self.name
@@ -66,7 +67,7 @@ def __unicode__(self):
6667
class Union(models.Model):
6768
name = models.CharField(max_length=50)
6869

69-
managers = models.ManyToManyField('Person', blank=True)
70+
managers = models.ManyToManyField('Person', blank=True, related_name='unions_managed')
7071

7172
def __unicode__(self):
7273
return self.name

0 commit comments

Comments
 (0)