Skip to content

Commit

Permalink
SeatSeason method are now statics. m2m_changed uses those methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
SRJ9 committed Nov 19, 2016
1 parent f0ceca4 commit 131f3d9
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions driver27/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ class Meta:
verbose_name_plural = _('Seats')




@python_2_unicode_compatible
class Circuit(models.Model):
name = models.CharField(max_length=30, verbose_name=_('circuit'), unique=True)
Expand Down Expand Up @@ -339,7 +337,8 @@ class SeatSeason(models.Model):
seat = models.ForeignKey('Seat', related_name='seasons_seat')
season = models.ForeignKey('Season', related_name='seats_season')

def get_seat_season_errors(self, seat, season):
@staticmethod
def get_seat_season_errors(seat, season):
seat_competition = seat.contender.competition
season_competition = season.competition
errors = []
Expand All @@ -350,7 +349,8 @@ def get_seat_season_errors(self, seat, season):
)
return errors

def get_seat_team_season_error(self, team, season):
@staticmethod
def get_seat_team_season_error(team, season):
errors = []
if season.pk:
season_teams = [season_team.pk for season_team in season.teams.all()]
Expand All @@ -361,7 +361,6 @@ def get_seat_team_season_error(self, team, season):
return errors

def clean(self, *args, **kwargs):
raise Exception('ko')
seat = self.seat
season = self.season
errors = []
Expand All @@ -379,21 +378,11 @@ class Meta:
def seat_seasons(sender, instance, action, pk_set, **kwargs): #noqa
# """ Signal in DriverCompetitionTeam.seasons to avoid seasons which not is in competition"""
if action == 'pre_add':
contender_competition = instance.contender.competition
contender_seasons = [season.pk for season in contender_competition.seasons.all()]
team_seasons = [season.pk for season in instance.team.seasons.all()]
errors = []
for pk in list(pk_set):
pk_season = Season.objects.get(pk=pk)
if int(pk) not in contender_seasons:
errors.append(
_('%(season)s is not a/an %(competition)s season')
% {'season': pk_season, 'competition': contender_competition}
)
if int(pk) not in team_seasons:
errors.append(
_('%(team)s is not a team of %(season)s') % {'team': instance.team, 'season': pk_season}
)
season = Season.objects.get(pk=pk)
errors.extend(SeatSeason.get_seat_season_errors(instance, season))
errors.extend(SeatSeason.get_seat_team_season_error(instance.team, season))
if errors:
raise ValidationError(errors)

Expand Down

0 comments on commit 131f3d9

Please sign in to comment.